Bug 221550

Summary: g++ and g++4 output bogus warnings on valid C code bracketed with extern "C" when using -Wshadow
Product: Red Hat Enterprise Linux 4 Reporter: Wagner T. Correa <wtcorrea>
Component: gcc3Assignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 4.4   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2007-01-05 07:53:59 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Wagner T. Correa 2007-01-05 01:23:54 UTC
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'

Comment 1 Jakub Jelinek 2007-01-05 07:53:59 UTC
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.

Comment 2 Wagner T. Correa 2007-01-05 14:32:51 UTC
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.

Comment 3 Jakub Jelinek 2007-01-05 14:40:04 UTC
Please reread what I said above and/or the ISO C++98 standard, extern "C" is
not marking something as C code.