[Bug c++/49793] Narrowing conversion from int/short/char to double with -std=c++0x

jason at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Jul 22 21:31:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49793

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> 2011-07-22 21:30:40 UTC ---
The compiler is, unfortunately, following the standard.  8.5.4/7: 

A narrowing conversion is an implicit conversion
...
* from an integer type or unscoped enumeration type to a floating-point type,
except where the source is a constant expression and the actual value after
conversion will fit into the target type and will produce the original value
when converted back to the original type, or ....

With the consts, some of the local variables are usable in a constant
expression, so we can verify that their constant values are suitable.  But for
non-constant expressions we can't and have to give an error.

I think we should probably add a -Wno-narrowing flag and downgrade narrowing
complaints to pedwarn.



More information about the Gcc-bugs mailing list