Access of member corresponding to init-capture
7.5.5 [expr.prim.lambda]
United Kingdom

Created on 2013-09-23.00:00:00 last changed 81 months ago


Date: 2013-09-15.00:00:00

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.:

    • if the capture is by copy (see below), the non-static data member declared for the capture and the variable are treated as two different ways of referring to the same object, which has the lifetime of the non-static data member, and no additional copy and destruction is performed, and

    • if the capture is by reference, the variable's lifetime ends when the closure object's lifetime ends.

    [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.

Date: 2014-03-03.00:00:00
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.

Date User Action Args
2014-11-24 00:00:00adminsetstatus: accepted -> c++14
2014-03-03 00:00:00adminsetstatus: ready -> accepted
2013-10-14 00:00:00adminsetmessages: + msg4579
2013-09-23 00:00:00admincreate