[Bug c++/72751] New: anonymous union within an anonymous union accepted
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Jul 29 21:17:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72751
Bug ID: 72751
Summary: anonymous union within an anonymous union accepted
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: ---
Quoting from C++14, [class.union.anon], p1:
Each member-declaration in the member-specification of an anonymous union shall
either define a non-static data member or be a static_assert-declaration.
[Note: Nested types, anonymous unions, and functions cannot be declared within
an anonymous union. -- end note]
That makes the following program ill-formed. In C mode (where the program is
also ill-formed) GCC issues a warning for the nested union and an error for the
use of a. However in C++ mode, G++ fails to issue a diagnostic for it, even in
pedantic mode. Clang issues:
warning: anonymous types declared in an anonymous union are an extension
[-Wnested-anon-types]
and EDG eccp 4.11:
error: types cannot be declared in anonymous unions
$ cat t.C && gcc -S -Wall -Wextra -Wpedantic t.C
void f ()
{
union { union { int a, b; }; };
a = 0;
}
More information about the Gcc-bugs
mailing list