Bug 221550 - g++ and g++4 output bogus warnings on valid C code bracketed with extern "C" when using -Wshadow
Summary: g++ and g++4 output bogus warnings on valid C code bracketed with extern "C" ...
Alias: None
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: gcc3
Version: 4.4
Hardware: All
OS: Linux
Target Milestone: ---
: ---
Assignee: Jakub Jelinek
QA Contact:
Depends On:
TreeView+ depends on / blocked
Reported: 2007-01-05 01:23 UTC by Wagner T. Correa
Modified: 2007-11-17 01:14 UTC (History)
0 users

Clone Of:
Last Closed: 2007-01-05 07:53:59 UTC

Attachments (Terms of Use)

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):

How reproducible:

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


g++4 -Wshadow -c foo.cpp

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

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.

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