Bug 221550 - g++ and g++4 output bogus warnings on valid C code bracketed with extern "C" when using -Wshadow
g++ and g++4 output bogus warnings on valid C code bracketed with extern "C" ...
Status: CLOSED NOTABUG
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: gcc3 (Show other bugs)
4.4
All Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2007-01-04 20:23 EST by Wagner T. Correa
Modified: 2007-11-16 20:14 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2007-01-05 02:53:59 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)

  None (edit)
Description Wagner T. Correa 2007-01-04 20:23:54 EST
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 02:53:59 EST
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 09:32:51 EST
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 09:40:04 EST
Please reread what I said above and/or the ISO C++98 standard, extern "C" is
not marking something as C code.

Note You need to log in before you can comment on or make changes to this bug.