This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 110b. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2023-01-15


1760. Access of member corresponding to init-capture

Section: 7.5.5.3  [expr.prim.lambda.capture]     Status: C++14     Submitter: United Kingdom     Date: 2013-09-23

N3690 comment GB 3

[Applied to WP at the February, 2014 meeting.]

The access of the non-static data member corresponding to an init-capture is not specified. The question would be moot if the member were unnamed like the other non-static data members of the closure class.

Proposed resolution (September, 2013):

  1. Change 7.5.5 [expr.prim.lambda] paragraph 11 as follows:
  2. For every init-capture a non-static data member named by the identifier of the init-capture is declared in the closure type. This member is not a bit-field and not mutable. The type of that member corresponds to the type of a hypothetical An init-capture behaves as if it declares and explicitly captures a variable declaration of the form “auto init-capture ;” whose declarative region is the lambda-expression's compound-statement, except that the variable name (i.e., the identifier of the init-capture) is replaced by a unique identifier.:

    [Note: This enables an init-capture like “x = std::move(x)”; the second “x” must bind to a declaration in the surrounding context. —end note] No entity is captured by an init-capture. Within the lambda-expressions lambda-declarator and compound-statement, the identifier in the init-capture hides any declaration of the same name in scopes enclosing the lambda-expression. [Example:...

  3. Change 7.5.5 [expr.prim.lambda] paragraph 15 as follows:

  4. An entity is captured by copy if it is implicitly captured and the capture-default is = or if it is explicitly captured with a capture that does not include an & is not of the form & identifier or & identifier initializer. For each entity...
  5. Change 7.5.5 [expr.prim.lambda] paragraph 18 as follows:

  6. Every id-expression within the compound-statement of a lambda-expression that is an odr-use (6.3 [basic.def.odr]) of an entity captured by copy is transformed into an access to the corresponding unnamed data member of the closure type. [Note:...

This resolution also resolves issue 1681.