+2020-05-07 Marek Polacek <polacek@redhat.com>
+
+ PR c++/94590 - Detect long double -> double narrowing.
+ * typeck2.c (check_narrowing): Detect long double -> double
+ narrowing even when double and long double have the same
+ precision. Make it handle conversions to float too.
+
2020-05-07 Marek Polacek <polacek@redhat.com>
PR c++/94255
|| !int_fits_type_p (init, type)))
ok = false;
}
+ /* [dcl.init.list]#7.2: "from long double to double or float, or from
+ double to float". */
else if (TREE_CODE (ftype) == REAL_TYPE
&& TREE_CODE (type) == REAL_TYPE)
{
- if (TYPE_PRECISION (type) < TYPE_PRECISION (ftype))
+ if ((same_type_p (ftype, long_double_type_node)
+ && (same_type_p (type, double_type_node)
+ || same_type_p (type, float_type_node)))
+ || (same_type_p (ftype, double_type_node)
+ && same_type_p (type, float_type_node))
+ || (TYPE_PRECISION (type) < TYPE_PRECISION (ftype)))
{
if (TREE_CODE (init) == REAL_CST)
{
+2020-05-07 Marek Polacek <polacek@redhat.com>
+
+ PR c++/94590 - Detect long double -> double narrowing.
+ * g++.dg/cpp0x/Wnarrowing18.C: New test.
+
2020-05-07 Marek Polacek <polacek@redhat.com>
PR c++/94255
--- /dev/null
+// PR c++/94590 - Detect long double -> double narrowing.
+// { dg-do compile { target c++11 } }
+// { dg-additional-options "-mlong-double-64" { target x86_64-*-* i?86-*-* } }
+
+int
+main ()
+{
+ using T = long double;
+ extern long double ld;
+ extern T ld2;
+ extern const T ld3;
+ double d{ld}; // { dg-error "narrowing conversion" }
+ double d2{ld2}; // { dg-error "narrowing conversion" }
+ double d3{ld3}; // { dg-error "narrowing conversion" }
+}