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

2024-12-19


1695. Lifetime extension via init-capture

Section: 6.7.7  [class.temporary]     Status: NAD     Submitter: Richard Smith     Date: 2013-05-31

If an init-capture binds a const reference to a temporary, is the lifetime of the temporary extended to match that of the lambda? For example,

   struct S { ~S(); };
   const S f();
   auto &&lambda = [&x(f())] () -> auto& { return x; };
   auto &y = lambda(); // ok?

Notes from the September, 2013 meeting:

CWG agreed that there is no lifetime extension in this example.

Rationale (June, 2014):

After further consideration, CWG agreed that this example should extend the lifetime of the temporary (because the notional variable is a reference) and that the existing text is clear enough in this regard.