Created on 2025-08-27.00:00:00 last changed 2 weeks ago
Suggested resolution:
Change in 11.5.2 [class.union.anon] paragraph 1 as follows:
... Each member-declaration in the member-specification of an anonymous union shalleitherdefine one or more public non-static data members, be an empty-declaration, or be a static_assert-declaration. Nested types, anonymous unions, and functions shall not be declared within an anonymous union. ...
(From submission #755.)
Subclause 11.5.2 [class.union.anon] paragraph 1 specifies:
... Each member-declaration in the member-specification of an anonymous union shall either define one or more public non-static data members or be a static_assert-declaration. Nested types, anonymous unions, and functions shall not be declared within an anonymous union. ...
This rule yields:
struct A { union {int x;;} u; }; // OK struct B { union {int y;;}; }; // error
Both class definitions ought to be allowed. There is implementation divergence: MSVC, gcc, and EDG accept both class definition; clang accepts both in default mode and rejects both in pedantic mode (rejecting empty declarations in all class definitions).
History | |||
---|---|---|---|
Date | User | Action | Args |
2025-09-25 21:12:44 | admin | set | messages: + msg8126 |
2025-08-27 00:00:00 | admin | create |