Created on 2026-01-29.00:00:00 last changed 2 days ago
Proposed resolution (approved by CWG 2026-03-06):
Change in 7.5.6.3 [expr.prim.lambda.capture] paragraph 15 as follows:
When the lambda-expression is evaluated, theThe entities that are captured by copy are used to direct-initialize each corresponding non-static data member of the resulting closure object, and the non-static data members corresponding to the init-captures are initialized as indicated by the corresponding initializer (which may be copy- or direct-initialization). (For array members, the array elements are direct-initialized in increasing subscript order.) These initializations are performed when the lambda-expression is evaluated and in the (unspecified) order in which the non-static data members are declared. The initializations shall be well-formed even if the lambda-expression is not evaluated.
(From submission #841.)
Consider:
struct C
{
C(int) = delete;
C(){};
};
decltype([b = C(3)](){ return 4; }()) x; //MSVC accepts; gcc and clang reject
Arguably, 7.5.6.3 [expr.prim.lambda.capture] paragraph 15 specifies that the initialization of the non-static data members only happens when the lambda-expression is evaluated, but there is no statement when the semantic contraints of such an initialization are checked.
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2026-03-06 21:39:32 | admin | set | status: review -> tentatively ready |
| 2026-02-22 14:01:42 | admin | set | status: open -> review |
| 2026-02-18 21:25:17 | admin | set | messages: + msg8478 |
| 2026-01-29 00:00:00 | admin | create | |