CWG Issue 1622 (original) (raw)
This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 117a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2025-04-13
1622. Empty aggregate initializer for union
Section: 9.5.2 [dcl.init.aggr]Status: C++17Submitter: Daveed VandevoordeDate: 2013-02-14
[Adopted at the February/March, 2017 meeting.]
According to 9.5.2 [dcl.init.aggr] paragraph 15,
When a union is initialized with a brace-enclosed initializer, the braces shall only contain an initializer-clause for the first non-static data member of the union.
This would appear to preclude using {} as the initializer for a union, which would otherwise have reasonable semantics. Is there a reason for this restriction?
Also, paragraph 7 reads,
If there are fewer _initializer-clause_s in the list than there are members in the aggregate, then each member not explicitly initialized shall be initialized from an empty initializer list (9.5.5 [dcl.init.list]).
There should presumably be special treatment for unions, so that only a single member is initialized in such cases.
(See also issue 1460.)
Proposed resolution (November, 2016) [SUPERSEDED]:
Change 9.5.2 [dcl.init.aggr] paragraph 8 as follows:
If there are fewer _initializer-clause_s in the list than there are elements in the aggregate, then eachEach non-variantelement of the aggregate that isnot explicitly initializedshall beisinitialized from its default member initializer (11.4 [class.mem]) or, if there is no default member initializer,copy-initializedfrom an empty initializer list (9.5.5 [dcl.init.list]). If the aggregate is a union and the initializer list is empty, then
- if any union member has a default member initilizer, that member is initialized from its default member initializer;
- otherwise, the first member of the union (if any) is copy-initialized from an empty initializer list.
[Example:...
Proposed resolution (February, 2017):
The resolution of issue 2272 also resolves this issue.