This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2024-11-11
[Moved to DR at the September, 2013 meeting.]
When a similar question was raised in issue 413, the resolution was to remove the use of the term. The resolution of issue 1359 has now reintroduced the concept of an “empty” union, so there is once again the need to define it.
(See also issues 1562 and 1622.)
Proposed resolution (February, 2013) [superseded]:
Change 11.5 [class.union] paragraph 2 as follows:
...At most one non-static data member of a union may have a brace-or-equal-initializer. A union is an empty union if it has no non-static data members. [Note: If any...
Additional note (March, 2013):
The question was raised as to whether an example like
union A { union {}; union {}; constexpr A() {} }; A a = A();
is well-formed, which hinges on the question of whether A is an “empty union,” per 9.2.6 [dcl.constexpr] paragraph 4 bullet 5:
if the class is a non-empty union, or for each non-empty anonymous union member of a non-union class, exactly one non-static data member shall be initialized;
Must one of the empty anonymous union members be initialized for A's constructor to be constexpr?
The issue is being returned to "review" status for discussion of this point.
See also issues 1562, 1587, 1621, and 1623.
Proposed resolution (August, 2013):
Change 9.2.6 [dcl.constexpr] paragraph 4 as follows:
...In addition, either its function-body shall be = delete, or it shall satisfy the following constraints:
...
if the class is a non-empty union, or for each non-empty anonymous union member of a non-union class, exactly one non-static data member shall be initialized;if the class is a union having variant members (11.5 [class.union]), exactly one of them shall be initialized;
if the class is a union-like class, but is not a union, for each of its anonymous union members having variant members, exactly one of them shall be initialized;
every constructor involved...
Change 11.5 [class.union] paragraph 2 as follows:
A union can have member functions (including constructors and destructors), but not virtual (11.7.3 [class.virtual]) functions. A union shall not have base classes. A union shall not be used as a base class. If a union contains a non-static data member of reference type the program is ill-formed.At most one non-static data member of a union may have a brace-or-equal-initializer.[Note: If any non-static data member...
Change 11.5 [class.union] paragraph 8 as follows:
A union-like class is a union or a class that has an anonymous union as a direct member. A union-like class X has a set of variant members.
If X is a union its variant members are the non-static data members; otherwise, its variant members are the non-static data members of all anonymous unions that are members of X.If X is a union, a non-static data member of X that is not an anonymous union is a variant member of X. In addition, a non-static data member of an anonymous union that is a member of X is also a variant member of X. At most one variant member of a union may have a brace-or-equal-initializer. [Example:union U { int x = 0; union { }; union { int z; int y = 1; // error: initialization for second variant member of U }; };
—end example]
Change 11.9.3 [class.base.init] paragraph 8 as follows:
In a non-delegating constructor, if a given non-static data member or base class is not designated by a mem-initializer-id (including the case where there is no mem-initializer-list because the constructor has no ctor-initializer) and the entity is not a virtual base class of an abstract class (11.7.4 [class.abstract]), then
if the entity is a non-static data member that has a brace-or-equal-initializer and either
the constructor's class is a union (11.5 [class.union]), and no other variant member of that union is designated by a mem-initializer-id or
the constructor's class is not a union, and, if the entity is a member of an anonymous union, no other member of that union is designated by a mem-initializer-id,
the entity is initialized as specified in 9.4 [dcl.init];
otherwise, if the entity...
(This resolution also resolves issue 1562.)