http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50011
Summary: [C++0x] warning: narrowing conversion of 'i' from
'short unsigned int' to 'int' inside { } [-Wnarrowing]
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: [email protected]
ReportedBy: [email protected]
CC: [email protected]
Since fixing PR49577, gcc gives a warning for the following code:
void foo(short unsigned i)
{
int a[] = {i};
}
$ g++ -std=gnu++0x tst.C
tst.C: In function 'int foo(short unsigned int)':
tst.C:3:14: warning: narrowing conversion of 'i' from 'short unsigned int' to
'int' inside { } [-Wnarrowing]
8.5.4/6 says:
A narrowing conversion is an implicit conversion
...
— from an integer type or unscoped enumeration type to an integer type that
cannot represent all the values of the original type
...
In this case, 'int' can represent all the values of 'short unsigned int', so
unless I am missing something, this should be valid.