This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/51440] New: C++ compiler produces warning for an unnamed struct member: TYPE has a field FIELD whose type uses the anonymous namespace
- From: "blue.dragan+gcc at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 06 Dec 2011 19:37:39 +0000
- Subject: [Bug c++/51440] New: C++ compiler produces warning for an unnamed struct member: TYPE has a field FIELD whose type uses the anonymous namespace
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51440
Bug #: 51440
Summary: C++ compiler produces warning for an unnamed struct
member: TYPE has a field FIELD whose type uses the
anonymous namespace
Classification: Unclassified
Product: gcc
Version: 4.6.1
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: blue.dragan+gcc@gmail.com
Repro steps:
File test.h:
========================================
typedef volatile struct {
} Unnamed;
typedef struct __Named {
Unnamed u;
} Named;
========================================
File test.cpp:
========================================
#include "test.h"
========================================
Outcome:
========================================
$ g++ -c -o test.o test.cpp
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]
========================================
Details about the repro scenario:
1) Only C++ compiler (C compiler does not generate the warning).
2) Only if the structures are in header files. When the contents of test.h are
moved to test.cpp, the warning disappears.
3) Only if the unnamed structure is volatile. When volatile keyword is removed,
the warning disappears.
4) GCC 4.6.1 hits this problem, but GCC 4.2.4 and 4.4.3 don't have this
problem. Haven't tested any other version of GCC.
5) I'm using GCC for armv7a-unknown-linux-gnueabi target, haven't tried it with
any other target, although the problem "seems" target-independent.
6) The warning is especially annoying, because there appears to be no way to
disable it.
I don't see anything wrong with defining the structures like this. This is a
common way for defining hardware registers which helps to prevent users from
mistakenly dropping the volatile keyword.