This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2024-11-11
[Accepted as a DR at the February, 2019 meeting.]
The current rule for determining when a local entity is odr-usable because of a capture-default is too broad. For example:
void f() { int n; void g(int k = n); // ill-formed [](int k = n) {}; // ill-formed [=](int k = n) {}; // valid! [=](int k = [=]{ return n; }()) {}; // valid! }
Proposed resolution (January, 2019):
Change 6.3 [basic.def.odr] bullet 9.2.2 and add to the example as follows:
A local entity (6.3 [basic.def.odr]) is odr-usable in a declarative region (_N4868_.6.4.1 [basic.scope.declarative]) if:
...
...
the intervening declarative region is the function parameter scope of a lambda-expression that has a simple-capture naming the entity or has a capture-default, and the block scope of the lambda-expression is also an intervening declarative region.
If a local entity is odr-used in a declarative region in which it is not odr-usable, the program is ill-formed. [Example:
void f(int n) { [] { n = 1; }; // error, n is not odr-usable due to intervening lambda-expression struct A { void f() { n = 2; } // error, n is not odr-usable due to intervening function definition scope }; void g(int = n); // error, n is not odr-usable due to intervening function parameter scope [=](int k = n) {}; // error, n is not odr-usable due to being outside the block scope of the lambda-expression [&] { [n]{ return n; }; }; // OK }