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

2023-02-07


888. Union member initializers

Section: 11.9.3  [class.base.init]     Status: CD2     Submitter: Alisdair Meredith     Date: 6 May, 2009

[Voted into WP at October, 2009 meeting.]

11.9.3 [class.base.init] paragraph 5 forbids initializing multiple members of a union via mem-initializers:

If a ctor-initializer specifies more than one mem-initializer for the same member, for the same base class or for multiple members of the same union (including members of anonymous unions), the ctor-initializer is ill-formed.

However, there is no corresponding restriction against specifying brace-or-equal-initializers for multiple union members, nor for a non-overlapping pair of brace-or-equal-initializer and mem-initializer. This is presumably an oversight.

Proposed resolution (July, 2009):

  1. Change 11.5 [class.union] paragraph 1 as follows:

  2. ...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 shall have a brace-or-equal-initializer. [Note:...
  3. Change 11.9.3 [class.base.init] paragraph 5 as follows:

  4. ...If a ctor-initializer specifies more than one mem-initializer for the same member, or for the same base class or for multiple members of the same union (including members of anonymous unions), the ctor-initializer is ill-formed.
  5. Change 11.9.3 [class.base.init] paragraph 8 as follows:

  6. ...An attempt to initialize more than one non-static data member of a union renders the program ill-formed. After the call to a constructor for class X has completed...