Title
Explicitly captured variable is not odr-usable in lambda contract
Status
open
Section
6.3 [basic.def.odr]
Submitter
Abhinav Agarwal

Created on 2026-06-20.00:00:00 last changed 1 week ago

Messages

Date: 2026-07-13.21:02:13

Suggested resolution:

Change in 6.3 [basic.def.odr] bullet 10.2.4 as follows:

  • ...
  • the intervening scope is the lambda scope of a lambda-expression that has a simple-capture naming the entity or has a capture-default, and at least one of the following is also an intervening scope:
    • the block scope of the lambda-expression is also an intervening scope. , or
    • a contract-assertion scope (6.4.10 [basic.scope.contract]) introduced by a function contract assertion (9.4.1 [dcl.contract.func]) of the function call operator or operator template of the corresponding closure type.
Date: 2026-06-20.00:00:00

(From submission #927.)

Consider:

  void test() {
   int i = 1;
   auto f3 = [i] pre(i > 0) {};  // OK, i is captured explicitly.
  }

The normative rules do not result in "OK".

History
Date User Action Args
2026-07-13 21:02:13adminsetmessages: + msg8629
2026-06-20 00:00:00admincreate