Created on 2023-07-06.00:00:00 last changed 16 months ago
Currently, the specification permits this example:
namespace { extern union { int x, y; }; union { int x, y; }; };
However, those non-defining declarations seem to be mostly useless, because any definition attempt would violate the one-definition rule (6.3 [basic.def.odr]).
Possible resolution (updated 2023-10-21):
This resolution also addresses issue 1702.
Split 11.5.2 [class.union.anon] paragraph 1 and change as follows:
A union of the formA simple-declaration or member-declaration of the formattribute-specifier-seqopt decl-specifier-seq ;where one of the decl-specifiers is a class-specifier of the formunion attribute-specifier-seqopt { member-specification };is calleddeclares an anonymous union; it defines an unnamed type T and an unnamed object ofthattype cv T called an anonymous union member if it is a non-static data member or an anonymous union variable otherwise, where cv is determined from the cv-qualifiers of the declaration. The optional attribute-specifier-seq in the simple-declaration or member-declaration appertains to the data member or variable, respectively. The storage-class-specifier extern (9.2.2 [dcl.stc]) shall not be among the decl-specifiers declaring an anonymous union. The declaration of an anonymous union shall not be the name-declaration of a linkage-specification (9.11 [dcl.link]).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. The names of the members of an anonymous union are bound in the scope inhabited by the union declaration.
Change in 11.5.2 [class.union.anon] paragraph 2 as follows:
Anonymous unions declared in the scope ofAn anonymous union whose declaration inhabits a namespace scope with external linkage shall be declared static.Anonymous unions declared at block scope shall be declared with any storage class allowed for a block variable, or with no storage class. A storage class is not allowed in a declaration of an anonymous union in a class scope.An anonymous union whose declaration inhabits a class scope shall not be declared with a storage-class-specifier.
History | |||
---|---|---|---|
Date | User | Action | Args |
2023-07-06 00:00:00 | admin | create |