<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">

<style type="text/css">

body { color: #000000; background-color: #FFFFFF; }
del { text-decoration: line-through; color: #CB0040; }
ins { text-decoration: underline; color: #00A100; }

p.example { margin-left: 2em; }
pre.example { margin-left: 2em; }
div.example { margin-left: 2em; }

code.extract { background-color: #F5F6A2; }
pre.extract { margin-left: 2em; background-color: #F5F6A2;
  border: 1px solid #E1E28E; }

p.function { }
.attribute { margin-left: 2em; }
.attribute dt { float: left; font-style: italic;
  padding-right: 1ex; }
.attribute dd { margin-left: 0em; }

blockquote.std { color: #000000; background-color: #F1F1F1;
  border: 1px solid #D1D1D1;
  padding-left: 0.5em; padding-right: 0.5em; }
blockquote.stddel { text-decoration: line-through;
  color: #000000; background-color: #FFEBFF;
  border: 1px solid #ECD7EC;
  padding-left: 0.5empadding-right: 0.5em; ; }

blockquote.stdins { text-decoration: underline;
  color: #000000; background-color: #C8FFC8;
  border: 1px solid #B3EBB3; padding: 0.5em; }

table { border: 1px solid black; border-spacing: 0px;
  margin-left: auto; margin-right: auto; }
th { text-align: left; vertical-align: top;
  padding-left: 0.8em; border: none; }
td { text-align: left; vertical-align: top;
  padding-left: 0.8em; border: none; }

</style>

<title>Wording Changes for Generalized Lambda-capture</title>
</head>
<body>
<div style="text-align: right">
<p>ISO/IEC JTC1 SC22 WG21
<br>N3648
<br>Daveed Vandevoorde
<br>Ville Voutilainen
<br>2013-04-17
<br></p>
</div>

<h1>Wording Changes for Generalized Lambda-capture</h1>
<p>
In 5.1.2 [expr.prim.lambda] paragraph 1, replace the grammar for <i>capture</i> by:
<pre><i>
        capture:
		simple-capture
		init-capture

	simple-capture:
		identifier
		</i><tt>&</tt><i> identifier
		this

	init-capture:
		identifier initializer
		</i><tt>&</tt><i> identifier initializer
</i></pre>
</p>

<p>
Amend 5.1.2 [expr.prim.lambda] paragraph 8 as follows:
</p>
<p>
If a <i>lambda-capture</i> includes a <i>capture-default</i> that is <tt>&</tt>,
<del>the</del><ins>no</ins> identifier<del>s</del> in <del>the</del> <ins>a <i>simple-capture</i> of that </ins><i>lambda-capture</i> shall<del>not </del>
be preceded by <tt>&</tt>. If a <i>lambda-capture</i> includes a
<i>capture-default</i> that is <tt>=</tt>, <del>the</del><ins>each
<i>simple-capture</i> of that </ins> <i>lambda-capture</i> shall <del>not contain <tt>this</tt> and each <i>identifier</i> it contains shall be preceded by
<tt>&</tt></del><ins>be of the form "<tt>&</tt> <i>identifier</i>"</ins>.
<ins>Ignoring appearances in <i>initializer</i>s of <i>init-capture</i>s,
a</ins><del>A</del>n <i>identifier</i> or <tt>this</tt> shall not appear more
than once in a <i>lambda-capture</i>.
[ Example: ... ]

</p>
<p>
Amend 5.1.2 [expr.prim.lambda] paragraph 9 as follows:
</p>
<p>
A <i>lambda-expression</i> whose smallest enclosing scope is a block scope
(3.3.3) is a local lambda expression; any other <i>lambda-expression</i> shall
not have a <del><i>capture-list</i></del><ins><i>capture-default</i> or
<i>simple-capture</i></ins> in its <i>lambda-introducer</i>.
The <i>reaching scope</i> of ...
</p>

<p>
Amend 5.1.2 [expr.prim.lambda] paragraph 10 as follows:
</p>
<p>
The <i>identifier</i><del>s</del> in a <del><i>capture-list</i> are</del>
<ins><i>simple-capture</i> is</ins> looked up using the usual
rules for unqualified name lookup (3.4.1); each such lookup shall find a
variable with automatic storage duration declared in the reaching scope of the
local lambda expression. An entity (i.e. a variable or <tt>this</tt>) is said
to be <i>explicitly captured</i> if it <del>appears in the
<i>lambda-expression</i>’s <i>capture-list</i></del><ins>is found by this
process</ins>.
</p>

<p>
Append a new paragraph after 5.1.2 [expr.prim.lambda] paragraph 10:
</p>
<p>
For every <i>init-capture</i> a non-static data member named by the
<i>identifier</i> of the <i>init-capture</i> is declared in the closure type.
This member is not a bit-field and not <tt>mutable</tt>.
The type of that member corresponds to the type of a hypothetical variable
declaration of
the form "<tt>auto </tt><i>init-capture</i> <tt>;</tt>", except that the
variable name (i.e., the <i>identifier</i> of the <i>init-capture</i>) is
replaced by a unique identifier.  [ <i>Note:</i> This enables an 
<i>init-capture</i> like "<tt>x = std::move(x)</tt>"; the second "<tt>x</tt>"
must bind to a declaration in the surrounding context. <i>--end note</i> ]
No entity is captured by an <i>init-capture</i>.  Within the 
<i>lambda-expression</i>'s <i>lambda-declarator</i> and
<i>compound-statement</i>,
the <i>identifier</i> in the <i>init-capture</i> hides any declaration
of the same name in scopes enclosing the <i>lambda-expression</i>.
<!--
 an <i>id-expression</i> that does not refer to a
declaration within that <i>lambda-declarator</i> and <i>compound-statement</i>
refers to an <i>init-capture</i>'s non-static data member of the same name
if there is one.  --!>
[ <i>Example:</i>
<pre>    int x = 4;
    auto y = [&r = x, x = x+1]()-&gt;int {
                r += 2;
                return x+2;
             }();  // Updates ::x to 6, and initializes y to 7.
</pre><i>--end example]</i>
</p>

<p>
Amend 5.1.2 [expr.prim.lambda] paragraph 11 as follows:
</p>
<p>
If a <i>lambda-expression</i> has an associated <i>capture-default</i>
<ins>,</ins> and
its <i>compound-statement</i> odr-uses (3.2) <tt>this</tt> or a variable
with automatic storage duration<ins> (this excludes any <i>id-expression</i>
that has been found to refer to an <i>init-capture</i>'s associated
non-static data member),</ins>
and the odr-used entity is not explicitly captured, then the odr-used entity
is said to be implicitly captured; such entities shall be declared within
the reaching scope of the lambda expression. [<i>Note:</i> ... ]
</i>

<p>
Amend 5.1.2 [expr.prim.lambda] paragraph 21 as follows:
</p>
<p>
When the <i>lambda-expression</i> is evaluated, the entities that are
captured by copy are used to direct-initialize each corresponding
non-static data member of the resulting closure object<ins>, and the
non-static data members corresponding to the <i>init-captures</i> are
initialized as indicated by the corresponding <i>initializer</i>
(which may be copy- or direct-initialization)</ins>. (For array members,
the array elements are direct-initialized in increasing subscript order.)
These initializations are performed in the (unspecified) order in which
the non-static data members are declared. [<i>Note:</i> This ensures that
the destructions will occur in the reverse order of the constructions.
<i>-- end note</i> ]


<p>
Amend 5.1.2 [expr.prim.lambda] paragraph 23 as follows:
</p>
<p>
A <i><ins>simple-</ins>capture</i> followed by an ellipsis is a pack expansion
(14.5.3).
<ins>An <i>init-capture</i> followed by an ellipsis is ill-formed.</ins>
[ <i>Example:</i> ... ]
</p>

</body>
