Title
capture-default makes too many references odr-usable
Status
cd5
Section
6.3 [basic.def.odr]
Submitter
Richard Smith

Created on 2018-06-14.00:00:00 last changed 48 months ago

Messages

Date: 2019-01-15.00:00:00

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
  }
Date: 2019-02-15.00:00:00

[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!
  }
History
Date User Action Args
2020-12-15 00:00:00adminsetmessages: + msg6353
2018-06-14 00:00:00admincreate