CWG Issue 1815 (original) (raw)

This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 118e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-11-05


1815. Lifetime extension in aggregate initialization

Section: 9.5.2 [dcl.init.aggr]Status: CD4Submitter: Dinka RannsDate: 2013-11-22

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

With the recent addition of _brace-or-equal-initializer_s to aggregates and the presumed resolution forissue 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 giveB a deleted default constructor since it would extend the lifetime of a temporary.

See also issue 1696.

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.

Proposed resolution (June, 2014):

This issue is resolved by the resolution ofissue 1696.