Description of problem: g++ and g++4 output bogus warnings on valid C code bracketed with extern "C" when using -Wshadow. Version-Release number of selected component (if applicable): gcc-c++-3.4.6-3 gcc4-c++-4.1.0-18.EL4 How reproducible: Always. Steps to Reproduce: 1. Save this to foo.cpp: extern "C" { struct Foo {}; void Foo(void) {} } 2. Compile it with: g++ -Wshadow -c foo.cpp or g++4 -Wshadow -c foo.cpp 3. Actual results: I get the warning message: foo.cpp: In function ‘void Foo()’: foo.cpp:3: warning: ‘void Foo()’ hides constructor for ‘struct Foo’ Expected results: No warnings. Additional info: I ran into this problem when compiling a C++ file that included /usr/include/orbit-2.0/orbit/dynamic/dynamic-defs.h from ORBit2-devel-2.12.0-3. The message then was: /usr/include/orbit-2.0/orbit/dynamic/dynamic-defs.h:715: warning: `CORBA_TypeCode_struct* DynamicAny_DynAny_type(DynamicAny_DynAny_type*, CORBA_Environment*)' hides constructor for `struct DynamicAny_DynAny_type'
There is nothing wrong on the warning. extern "C" doesn't mean compile this chunk of source with a C compiler, extern "C" is solely about external linkage. And in C++, struct/class names are injected into the same namespace as function names.
I still think it's strange to give warnings about perfectly correct C code marked as C code. Plus, if I write this: extern "C" { struct Foo {}; void Foo(void) {} } int main() { Foo a; return 0; } I get an error and a warning on line 8: foo.cpp: In function `void Foo()': foo.cpp:3: warning: `void Foo()' hides constructor for `struct Foo' foo.cpp: In function `int main()': foo.cpp:8: error: expected `;' before "a" foo.cpp:8: warning: statement is a reference, not call, to function `Foo' I get the warning on line 8 even without the -Wshadow option. So, to me the warning on line 3 seems redundant for code affected by it, and unnecessary and strange for code not affected by it.
Please reread what I said above and/or the ISO C++98 standard, extern "C" is not marking something as C code.