Title
Dependent odr-use in generic lambdas
Status
dr
Section
6.3 [basic.def.odr]
Submitter
Shafik Yaghmour

Created on 2022-12-13.00:00:00 last changed 3 weeks ago

Messages

Date: 2024-03-20.03:01:37

Proposed resolution (approved by CWG 2024-03-20):

Insert a new paragraph before 6.3 [basic.def.odr] paragraph 11:

[ Example:

  void g() {
    constexpr int x = 1;
    auto lambda = [] <typename T, int = ((T)x, 0)> {};  // OK
    lambda.operator()<int, 1>();         // OK, does not consider x at all
    lambda.operator()<int>();            // OK, does not odr-use x
    lambda.operator()<const int&>();     // error: odr-uses x from a context where x is not odr-usable
  }

  void h() {
    constexpr int x = 1;
    auto lambda = [] <typename T> { (T)x; };  // OK
    lambda.operator()<int>();            // OK, does not odr-use x
    lambda.operator()<void>();           // OK, does not odr-use x
    lambda.operator()<const int&>();     // error: odr-uses x from a context where x is not odr-usable
  }

-- end example ]

Every program shall contain at least one definition of every function or variable ...

Date: 2024-03-15.00:00:00

[Accepted as a DR at the March, 2024 meeting.]

Default template arguments of generic lambdas can refer to local variables. It is unclear whether the potential odr-use is checked when parsing the template definition or when instantiating the template.

There is wide implementation divergence.

History
Date User Action Args
2024-04-05 21:43:46adminsetstatus: ready -> dr
2024-03-20 03:04:54adminsetstatus: tentatively ready -> ready
2024-03-03 21:57:08adminsetmessages: + msg7627
2024-03-03 21:57:08adminsetstatus: open -> tentatively ready
2022-12-13 00:00:00admincreate