https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72708
Bug ID: 72708
Summary: error on anonymous union in an unnamed namespace
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
In [basic.link], all versions of C++ state that:
A name having namespace scope (3.3.6) has internal linkage if it is the name
of
...
-- a data member of an anonymous union.
In addition, in [class.union.anon], C++ specifies that:
Anonymous unions declared in a named namespace or in the global namespace
shall be declared static.
This implies that when an anonymous union is declared without the static
keyword in an unnamed namespace it has internal linkage.
However, G++ rejects the following valid program needlessly insisting that the
anonymous union declaration in the unnamed namespace use the static keyword:
$ cat xyz.c && /build/gcc-71912/gcc/xgcc -B /build/gcc-71912/gcc -S -Wall
-Wextra -Wpedantic -xc++ xyz.c
namespace {
union { int x; };
}
xyz.c:2:18: error: namespace-scope anonymous aggregates must be static
union { int x; };
^