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.]
The following example is ill-formed:
union U { int a = 0; float f; U() {} // ok, a initialized to 0 U(float f) : f(f) {} // error, constructor initializes both a and f };
because of 11.9.3 [class.base.init] paragraph 8:
An attempt to initialize more than one non-static data member of a union renders the program ill-formed.
In non-union classes, a mem-initializer takes precedence over a non-static data member initializer, per paragraph 9:
If a given non-static data member has both a brace-or-equal-initializer and a mem-initializer, the initialization specified by the mem-initializer is performed, and the non-static data member's brace-or-equal-initializer is ignored.
It would be reasonable to treat union mem-initializers in an analogous fashion.
(See also issue 1460.)
Proposed resolution (March, 2013) [superseded]:
Change 11.9.3 [class.base.init] paragraph 8 as follows:
[Note: this wording was reviewed during the 2013-03-25 teleconference.]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, if the entity is a member of a union, no other non-static data member of that union is designated by a mem-initializer-id, the entity is initialized as specified in 9.4 [dcl.init];
...
See also issues 1460, 1587, 1621, and 1623.
Proposed resolution (August, 2013):
This issue is resolved by the resolution of issue 1460.