Title
Explicit capture of value
Status
cd5
Section
7.5.5.3 [expr.prim.lambda.capture]
Submitter
Daveed Vandevoorde

Created on 2017-09-20.00:00:00 last changed 7 months ago

Messages

Date: 2018-11-15.00:00:00

Proposed resolution (November, 2018):

Change 7.5.5.3 [expr.prim.lambda.capture] paragraph 9 as follows:

A lambda-expression appearing in a default argument shall not implicitly or explicitly capture any entity, except for an init-capture for which any full-expression in its initializer satisfies the constraints of an expression appearing in a default argument (9.3.4.7 [dcl.fct.default]). [Example:

  void f2() {
    int i = 1;
    void g1(int = ([i]{ return i; })());       // ill-formed
    void g2(int = ([i]{ return 0; })());       // ill-formed
    void g3(int = ([=]{ return i; })());       // ill-formed
    void g4(int = ([=]{ return 0; })());       // OK
    void g5(int = ([]{ return sizeof i; })()); // OK
    void g6(int = ([x=1] { return x; }))();    // OK
    void g7(int = ([x=i] { return x; }))();    // ill-formed
  }

end example]

Date: 2018-04-15.00:00:00

Notes from the April, 2018 teleconference:

CWG felt that the rule for capturing should be something like the prohibition for local classes odr-using a variable with automatic storage duration in 11.6 [class.local] paragraph 1.

Date: 2019-02-15.00:00:00

[Accepted as a DR at the February, 2019 meeting.]

The status of an example like the following is unclear:

  int foo(int a = ([loc=1] { return loc; })()) { return a; }

because of 7.5.5.3 [expr.prim.lambda.capture] paragraph 9:

A lambda-expression appearing in a default argument shall not implicitly or explicitly capture any entity.

However, there doesn't appear to be a good reason for prohibiting such a capture.

History
Date User Action Args
2020-12-15 00:00:00adminsetmessages: + msg6378
2020-12-15 00:00:00adminsetstatus: drafting -> cd5
2018-04-11 00:00:00adminsetmessages: + msg6192
2017-09-20 00:00:00admincreate