This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 118c. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-10-11


3079. Allow empty-declarations in anonymous unions

Section: 11.5.2  [class.union.anon]     Status: open     Submitter: keinflue     Date: 2025-08-27

(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).

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. ...