Created on 2017-09-20.00:00:00 last changed 47 months ago
Proposed resolution (November, 2018):
Change 7.5.6.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]
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.
[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.6.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:00 | admin | set | messages: + msg6378 |
2020-12-15 00:00:00 | admin | set | status: drafting -> cd5 |
2018-04-11 00:00:00 | admin | set | messages: + msg6192 |
2017-09-20 00:00:00 | admin | create |