unexpected warning about unused variables from anonymous union with a template member

Steve Ward planet36@gmail.com
Sun Dec 6 07:39:00 GMT 2009


See the attached program.

Command:
g++ -Wunused anonymous_union.cpp

Output:
anonymous_union.cpp: In function 'void print_byte_array_2(T) [with T =
unsigned int]':
anonymous_union.cpp:95:   instantiated from here
anonymous_union.cpp:38: warning: unused variable 'y'
anonymous_union.cpp:38: warning: unused variable 'byte_array'

Expected output:
none


The four functions do the same thing.  Two use template parameters,
and the other two use non-template parameters.  Two use anonymous
unions, and the other two use named unions.

Warnings about unused variables are printed for the second function
(with a template parameter and anonymous union) but not for the other
three.

g++ --version
g++ (Ubuntu 4.4.1-4ubuntu8) 4.4.1


Steve
-------------- next part --------------
A non-text attachment was scrubbed...
Name: anonymous_union.cpp
Type: text/x-c++src
Size: 1815 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20091206/0faccfb3/attachment.bin>


More information about the Gcc-help mailing list