Bug 54023 - [C++0x][initializer list] integer type to floating type narrowing type is not producing diagnostics
Summary: [C++0x][initializer list] integer type to floating type narrowing type is not...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-18 21:28 UTC by ebeworld
Modified: 2012-07-18 21:40 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ebeworld 2012-07-18 21:28:45 UTC
According to 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, ...

and not allowed at top level. Therefore followings should be generate diagnostics

int i=3;
double d=i;
float f=i;
long double ld=i;

char c=3;
double d=c;

etc.. should give narrowing error.
Comment 1 ebeworld 2012-07-18 21:40:20 UTC
forgot the curly braces.It should have been double d={i} and the compiler gives 
warning: narrowing conversion of 'i' from 'int' to 'double' inside { } [-Wnarrowing]