This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/51440] C++ compiler produces warning for an unnamed struct member: TYPE has a field FIELD whose type uses the anonymous namespace
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 07 Dec 2011 01:32:03 +0000
- Subject: [Bug c++/51440] C++ compiler produces warning for an unnamed struct member: TYPE has a field FIELD whose type uses the anonymous namespace
- Auto-submitted: auto-generated
- References: <bug-51440-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51440
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-12-07 01:32:03 UTC ---
(In reply to comment #0)
> In file included from test.cpp:1:0:
> test.h:4:16: warning: '__Named' has a field '__Named::u' whose type uses the
> anonymous namespace [enabled by default]
> ========================================
The error is a bit misleading, it should say that the type has internal linkage
(which it would have if it was declared in an anonymous namespace, but that's
not the case here.)
> Details about the repro scenario:
>
> 1) Only C++ compiler (C compiler does not generate the warning).
C supports the idea of "compatible types" which C++ doesn't
> 2) Only if the structures are in header files. When the contents of test.h are
> moved to test.cpp, the warning disappears.
In C++ a type with internal linkage defined in a header will be a different
type in every file that includes the header, which is usually a mistake so you
get a warning.
The same type defined in a source file cannot be referred to by more than one
file anyway, so there's no need to warn.
> 3) Only if the unnamed structure is volatile. When volatile keyword is removed,
> the warning disappears.
'const' has the same effect
Without const or volatile, the unnamed class has the name "Unnamed" for linkage
purpopses, and so has external linkage. I'm not sure if the cv-qualifiers mean
the unnamed class doesn't have the typedef name 'Unnamed' for linkage purposes,
or if it's a bug