[Bug c++/50011] New: [C++0x] warning: narrowing conversion of 'i' from 'short unsigned int' to 'int' inside { } [-Wnarrowing]
zsojka at seznam dot cz
gcc-bugzilla@gcc.gnu.org
Sun Aug 7 11:10:00 GMT 2011
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: unassigned@gcc.gnu.org
ReportedBy: zsojka@seznam.cz
CC: jason@gcc.gnu.org
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.
More information about the Gcc-bugs
mailing list