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


2380. capture-default makes too many references odr-usable

Section: 6.3  [basic.def.odr]     Status: CD5     Submitter: Richard Smith     Date: 2018-06-14

[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:

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
  }