Title
Cv-qualification of nested lambda capture
Status
cd6
Section
7.5.6.3 [expr.prim.lambda.capture]
Submitter
James Widman

Created on 2011-03-02.00:00:00 last changed 28 months ago

Messages

Date: 2021-08-15.00:00:00

Proposed resolution (August, 2021):

Change 7.5.6.3 [expr.prim.lambda.capture] paragraph 14 as follows:

If a lambda-expression m2 captures an entity and that entity is captured by an immediately enclosing lambda-expression m1, then m2's capture is transformed as follows:

  • if If m1 captures the entity by copy, m2 captures the corresponding non-static data member of m1's closure type; if m1 is not mutable, the non-static data member is considered to be const-qualified.

  • if If m1 captures the entity by reference, m2 captures the same entity captured by m1.

Date: 2021-10-15.00:00:00

[Accepted as a DR at the October, 2021 meeting.]

Consider the following example:

    void f(int i) {
      auto l1 = [i] {
        auto l2 = [&i] {
          ++i;    // Well-formed?
        };
      };
    }

Because the l1 lambda is not marked as mutable, its operator() is const; however, it is not clear from the wording of 7.5.6 [expr.prim.lambda] paragraph 16 whether the captured member of the enclosing lambda is considered const or not.

History
Date User Action Args
2022-08-19 07:54:33adminsetstatus: drwp -> cd6
2022-02-15 00:00:00adminsetstatus: dr -> drwp
2021-11-15 00:00:00adminsetmessages: + msg6567
2021-11-15 00:00:00adminsetstatus: drafting -> dr
2011-03-02 00:00:00admincreate