This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/72751] New: anonymous union within an anonymous union accepted
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 29 Jul 2016 21:17:45 +0000
- Subject: [Bug c++/72751] New: anonymous union within an anonymous union accepted
- Auto-submitted: auto-generated
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;
}