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

Reply via email to