Title
Lifetime extension in aggregate initialization
Status
cd4
Section
9.4.2 [dcl.init.aggr]
Submitter
Dinka Ranns

Created on 2013-11-22.00:00:00 last changed 87 months ago

Messages

Date: 2014-11-15.00:00:00

[Moved to DR at the November, 2014 meeting.]

Date: 2014-06-15.00:00:00

Proposed resolution (June, 2014):

This issue is resolved by the resolution of issue 1696.

Date: 2014-02-15.00:00:00

Notes from the February, 2014 meeting:

CWG agreed with the suggested direction, which would treat #3 in the example like #2 and make the default constructor deleted, resulting in #1 being ill-formed.

Date: 2014-03-03.00:00:00

With the recent addition of brace-or-equal-initializers to aggregates and the presumed resolution for issue 1696, it is not clear how lifetime extension of temporaries should work in aggregate initialization. For example:

  struct A { };
  struct B { A&& a { A{} } };
  B b;         // #1
  B b{ A{} };  // #2
  B b{};       // #3

#1 is default initialization, so (presumably) the lifetime of the temporary persists only until B's default constructor exits. #2 is aggregate initialization, which binds B::a to the temporary in the initializer for b and thus extends its lifetime to that of b. #3 is aggregate initialization, but it is not clear whether the lifetime of the temporary in the non-static data member initializer for B::a should be lifetime-extended like #2 or not, like #1.

One possibility might be to extend the lifetime in #3 but to give B a deleted default constructor since it would extend the lifetime of a temporary.

See also issue 1696.

History
Date User Action Args
2017-02-06 00:00:00adminsetstatus: drwp -> cd4
2015-05-25 00:00:00adminsetstatus: dr -> drwp
2015-04-13 00:00:00adminsetmessages: + msg5383
2014-11-24 00:00:00adminsetstatus: tentatively ready -> dr
2014-07-07 00:00:00adminsetmessages: + msg5077
2014-07-07 00:00:00adminsetstatus: drafting -> tentatively ready
2014-03-03 00:00:00adminsetmessages: + msg4883
2014-03-03 00:00:00adminsetstatus: open -> drafting
2013-11-22 00:00:00admincreate