Movatterモバイル変換


[0]ホーム

URL:


Issue 1622 - WG21 CWG Issues
Title
Empty aggregate initializer for union
Status
c++17
Section
9.5.2 [dcl.init.aggr]
Submitter
Daveed Vandevoorde

Created on2013-02-14.00:00:00 last changed96 months ago

Messages

msg6163 (view)
Date: 2017-02-15.00:00:00

Proposed resolution (February, 2017):

The resolution ofissue 2272 also resolvesthis issue.

msg5717 (view)
Date: 2016-11-15.00:00:00

Proposed resolution (November, 2016) [SUPERSEDED]:

Change 9.5.2 [dcl.init.aggr] paragraph 8 as follows:

If there are fewerinitializer-clauses in the list than there areelements in the aggregate, then eachEach non-variantelementof 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 unionand the initializer list is empty, then

  • if any union member has a default member initilizer, thatmember is initialized from its default member initializer;

  • otherwise, the first member of the union (if any) iscopy-initialized from an empty initializer list.

[Example:...

msg4285 (view)
Date: 2017-02-15.00:00:00

[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 bracesshall only contain aninitializer-clause for the first non-staticdata member of the union.

This would appear to preclude using{} as the initializer for aunion, which would otherwise have reasonable semantics. Is there a reasonfor this restriction?

Also, paragraph 7 reads,

If there are fewerinitializer-clauses in the list than there aremembers in the aggregate, then each member not explicitly initialized shallbe initialized from an empty initializer list (9.5.5 [dcl.init.list]).

There should presumably be special treatment for unions, so that onlya single member is initialized in such cases.

(See alsoissue 1460.)

History
DateUserActionArgs
2018-02-27 00:00:00adminsetmessages: +msg6163
2018-02-27 00:00:00adminsetstatus: ready -> c++17
2017-02-06 00:00:00adminsetmessages: +msg5717
2017-02-06 00:00:00adminsetstatus: drafting -> ready
2013-05-03 00:00:00adminsetstatus: open -> drafting
2013-02-14 00:00:00admincreate

[8]ページ先頭

©2009-2026 Movatter.jp