This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/49793] Narrowing conversion from int/short/char to double with -std=c++0x
- From: "jason at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 22 Jul 2011 21:30:57 +0000
- Subject: [Bug c++/49793] Narrowing conversion from int/short/char to double with -std=c++0x
- Auto-submitted: auto-generated
- References: <bug-49793-4@http.gcc.gnu.org/bugzilla/>
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.