Title
Allow empty-declarations in anonymous unions
Status
open
Section
11.5.2 [class.union.anon]
Submitter
keinflue

Created on 2025-08-27.00:00:00 last changed 2 weeks ago

Messages

Date: 2025-09-25.21:12:44

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 shall either define 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. ...
Date: 2025-08-27.00:00:00

(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:44adminsetmessages: + msg8126
2025-08-27 00:00:00admincreate