Bug#741960: gcc-4.7: [C++] Bogus narrowing conversion warning when initializing bit-field in union
Package: gcc-4.7
Version: 4.7.2-5
Severity: normal
Dear Maintainer,
Compiling the following as C++ with -Wall:
unsigned int n;
union U { unsigned int x:8; } u = { n };
results in:
$ gcc-4.7 -Wall -c test.cpp
test.cpp:2:39: warning: narrowing conversion of 'n' from 'unsigned int' to 'unsigned char' inside { } is ill-formed in C++11 [-Wnarrowing]
The type of the field U::x is not unsigned char: it is unsigned int.
Since u.x and n have the same type, there is no narrowing conversion
as defined in [dcl.init.list].
(See also <http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#1461>)
This bug seems to affect only unions, not ordinary structs.
-- System Information:
Debian Release: 7.0
APT prefers stable
APT policy: (990, 'stable'), (500, 'oldstable-updates'), (500, 'stable'), (500, 'oldstable'), (50, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386
Kernel: Linux 3.2.0-4-amd64 (SMP w/12 CPU cores)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages gcc-4.7 depends on:
ii binutils 2.22-8
ii cpp-4.7 4.7.2-5
ii gcc-4.7-base 4.7.2-5
ii libc6 2.13-38
ii libgcc1 1:4.7.2-5
ii libgmp10 2:5.0.5+dfsg-2
ii libgomp1 4.7.2-5
ii libitm1 4.7.2-5
ii libmpc2 0.9-4
ii libmpfr4 3.1.0-5
ii libquadmath0 4.7.2-5
ii zlib1g 1:1.2.7.dfsg-13
Versions of packages gcc-4.7 recommends:
ii libc6-dev 2.13-38
Versions of packages gcc-4.7 suggests:
pn binutils-gold <none>
ii gcc-4.7-doc 4.7.2-2
pn gcc-4.7-locales <none>
ii gcc-4.7-multilib 4.7.2-5
ii libcloog-ppl0 0.15.11-4
pn libgcc1-dbg <none>
pn libgomp1-dbg <none>
pn libitm1-dbg <none>
pn libmudflap0-4.7-dev <none>
pn libmudflap0-dbg <none>
pn libppl-c2 <none>
pn libppl7 <none>
pn libquadmath0-dbg <none>
-- no debconf information
Reply to: