- Title
- Non-static data member initializers and union ctor-initializer
- Status
- c++14
- Section
- 11.9.3 [class.base.init]
- Submitter
- Richard Smith
Created on 2012-10-01.00:00:00 last changed 143 months ago
Messages
Date: 2013-09-15.00:00:00
[Moved to DR at the September, 2013 meeting.]
Date: 2013-08-15.00:00:00
Proposed resolution (August, 2013): This issue is resolved by the resolution of issue 1460.
Date: 2013-03-15.00:00:00
Proposed resolution (March, 2013) [superseded]: 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, 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.5 [dcl.init]; ...
[Note: this wording was reviewed during the 2013-03-25
teleconference.]
Date: 2026-07-27.15:54:01
The following example is ill-formed: because of 11.9.3 [class.base.init] paragraph 8: In non-union classes, a mem-initializer takes precedence over
a non-static data member initializer, per paragraph 9: It would be reasonable to treat union mem-initializers in
an analogous fashion. (See also issue 1460.)
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
};
An attempt to initialize more than one non-static data member of a
union renders the program ill-formed.
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.
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2014-11-24 00:00:00 | admin | set | status: drwp -> c++14 |
| 2014-03-03 00:00:00 | admin | set | status: dr -> drwp |
| 2013-10-14 00:00:00 | admin | set | messages: + msg4693 |
| 2013-10-14 00:00:00 | admin | set | status: tentatively ready -> dr |
| 2013-09-03 00:00:00 | admin | set | messages: + msg4463 |
| 2013-09-03 00:00:00 | admin | set | status: drafting -> tentatively ready |
| 2013-05-03 00:00:00 | admin | set | messages: + msg4342 |
| 2012-10-01 00:00:00 | admin | create | |