This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 119a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2025-12-20
[Voted into the WP at the July, 2009 meeting as part of N2927.]
How does name binding work in nestedlambda-expressions? Forexample,
void f1() { float v; []() { return [v]() { return v; } } } void f2() { float v; [v]() { return [v]() { return v; } } }According to 7.5.6 [expr.prim.lambda] paragraph 3,
A name in thelambda-capture shall be in scope in the contextof the lambda expression, and shall bethis or shall refer toa local variable or reference with automatic storage duration.
One possible interpretation is that the lambda expression inf1 is ill-formed becausev is used in thecompound-statement of the outer lambda expression but does notappear in its effective capture set. However, the appearance ofv in the innerlambda-capture is not a“use” in the sense of 6.3 [basic.def.odr] paragraph2, because alambda-capture is not anexpression, andit's not clear whether the reference in the inner lambda expression'sreturn expression should be considered a use of the automaticvariable or of the member of the inner lambda expression's closureobject.
Similarly, the lambda expression inf2 could be deemedto be ill-formed because the reference tov in the innerlambda expression'slambda-capture would refer to the fieldof the outer lambda-expression's closure object, not to a localautomatic variable; however, it's not clear whether the innerlambda expression should be evaluatedin situ or as part ofthe generatedoperator() member of the outer lambdaexpression's closure object.
Proposed resolution (July, 2009)
See document PL22.16/09-0117 = WG21 N2927.