Skip to content

Commit c8c8a17

Browse files
committed
Merge 2016-02 CWG Motion 10
2 parents 55025ba + 3a9bf2e commit c8c8a17

File tree

2 files changed

+75
-42
lines changed

2 files changed

+75
-42
lines changed

source/basic.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
\indextext{region!declarative}%
3333
\indextext{entity}%
3434
An \defn{entity} is a value, object, reference, function, enumerator, type,
35-
class member, bit-field, template, template specialization, namespace, parameter
36-
pack, or \tcode{this}.
35+
class member, bit-field, template, template specialization, namespace, or
36+
parameter pack.
3737

3838
\pnum
3939
A \defn{name} is a use of an \grammarterm{identifier}~(\ref{lex.name}),

source/expressions.tex

Lines changed: 73 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@
625625
identifier\br
626626
\terminal{\&} identifier\br
627627
\terminal{this}
628+
\terminal{* this}
628629
\end{bnf}
629630

630631
\begin{bnf}
@@ -939,18 +940,23 @@
939940
by \tcode{\&}. If a \grammarterm{lambda-capture} includes a
940941
\grammarterm{capture-default} that is \tcode{=}, each
941942
\grammarterm{simple-capture} of that \grammarterm{lambda-capture} shall
942-
be of the form ``\tcode{\&} \grammarterm{identifier}''. Ignoring appearances in
943+
be of the form ``\tcode{\&} \grammarterm{identifier}'' or ``\tcode{* this}''.
944+
\enternote The form \tcode{[\&,this]} is redundant but accepted
945+
for compatibility with ISO \Cpp14. \exitnote
946+
Ignoring appearances in
943947
\grammarterm{initializer}{s} of \grammarterm{init-capture}{s}, an identifier or
944948
\tcode{this} shall not appear more than once in a
945949
\grammarterm{lambda-capture}. \enterexample
946950

947951
\begin{codeblock}
948952
struct S2 { void f(int i); };
949953
void S2::f(int i) {
950-
[&, i]{ }; // OK
951-
[&, &i]{ }; // error: \tcode{i} preceded by \tcode{\&} when \tcode{\&} is the default
952-
[=, this]{ }; // error: \tcode{this} when \tcode{=} is the default
953-
[i, i]{ }; // error: \tcode{i} repeated
954+
[&, i]{ }; // OK
955+
[&, &i]{ }; // error: \tcode{i} preceded by \tcode{\&} when \tcode{\&} is the default
956+
[=, *this]{ }; // OK
957+
[=, this]{ }; // error: \tcode{this} when \tcode{=} is the default
958+
[i, i]{ }; // error: \tcode{i} repeated
959+
[this, *this]{ }; // error: \tcode{this} appears twice
954960
}
955961
\end{codeblock}
956962
\exitexample
@@ -970,7 +976,9 @@
970976
usual rules for unqualified name lookup~(\ref{basic.lookup.unqual}); each such lookup
971977
shall find an entity. An entity that is designated by a
972978
\grammarterm{simple-capture}
973-
is said to be \defn{explicitly captured}, and shall be \tcode{this} or
979+
is said to be \defn{explicitly captured}, and shall be \tcode{*this}
980+
(when the \grammarterm{simple-capture}
981+
is ``\tcode{this}'' or ``\tcode{* this}'') or
974982
a variable with automatic storage duration declared in
975983
the reaching scope of the local lambda expression.
976984

@@ -1005,15 +1013,17 @@
10051013

10061014
\pnum
10071015
A \grammarterm{lambda-expression} with an associated
1008-
\grammarterm{capture-default} that does not explicitly capture \tcode{this} or
1016+
\grammarterm{capture-default} that does not explicitly capture \tcode{*this} or
10091017
a variable with automatic storage duration (this excludes any \grammarterm{id-expression}
10101018
that has been found to refer to an \grammarterm{init-capture}{'s} associated
10111019
\indextext{implicit capture!definition of}%
10121020
non-static data member), is said to \defnx{implicitly capture}{capture!implicit}
10131021
the entity (i.e.,
1014-
\tcode{this} or a variable) if the \grammarterm{compound-statement}:
1022+
\tcode{*this} or a variable) if the \grammarterm{compound-statement}:
10151023
\begin{itemize}
1016-
\item odr-uses~(\ref{basic.def.odr}) the entity, or
1024+
\item odr-uses~(\ref{basic.def.odr}) the entity (in the case of a variable),
1025+
\item odr-uses~(\ref{basic.def.odr}) \tcode{this}
1026+
(in the case of the object designated by \tcode{*this}), or
10171027
\item names the entity in a potentially-evaluated
10181028
expression~(\ref{basic.def.odr}) where the enclosing full-expression depends on
10191029
a generic lambda parameter declared within the reaching scope of the
@@ -1046,7 +1056,7 @@
10461056
\pnum
10471057
An entity is \defn{captured} if it is captured explicitly or implicitly. An entity
10481058
captured by a \grammarterm{lambda-expression} is odr-used~(\ref{basic.def.odr}) in the scope
1049-
containing the \grammarterm{lambda-expression}. If \tcode{this} is captured by a local
1059+
containing the \grammarterm{lambda-expression}. If \tcode{*this} is captured by a local
10501060
lambda expression, its nearest enclosing function shall be a non-static member function.
10511061
If a \grammarterm{lambda-expression} or an instantiation of the function call
10521062
operator template of a generic lambda odr-uses~(\ref{basic.def.odr}) \tcode{this} or a
@@ -1085,6 +1095,22 @@
10851095
}
10861096
};
10871097
}
1098+
1099+
struct s2 {
1100+
double ohseven = .007;
1101+
auto f() {
1102+
return [this] {
1103+
return [*this] {
1104+
return ohseven; // OK
1105+
}
1106+
}();
1107+
}
1108+
auto g() {
1109+
return [] {
1110+
return [*this] { }; // error: \tcode{*this} not captured by outer \grammarterm{lambda-expression}
1111+
}();
1112+
}
1113+
};
10881114
\end{codeblock}
10891115
\exitexample
10901116

@@ -1105,10 +1131,18 @@
11051131
\exitexample
11061132

11071133
\pnum
1108-
An entity is \defnx{captured by copy}{captured!by~copy} if it is implicitly captured and the
1109-
\grammarterm{capture-default} is \tcode{=} or if it is explicitly captured with a
1110-
capture that is not of the form \tcode{\&} \grammarterm{identifier} or
1134+
An entity is \defnx{captured by copy}{captured!by~copy} if
1135+
\begin{itemize}
1136+
\item
1137+
it is implicitly captured,
1138+
the \grammarterm{capture-default} is \tcode{=}, and
1139+
the captured entity is not \tcode{*this}, or
1140+
\item
1141+
it is explicitly captured with a capture that is not of the form
1142+
\tcode{this},
1143+
\tcode{\&} \grammarterm{identifier}, or
11111144
\tcode{\&} \grammarterm{identifier} \grammarterm{initializer}.
1145+
\end{itemize}
11121146
For each entity captured by copy, an
11131147
unnamed non-static data member is declared in the closure type. The declaration order of
11141148
these members is unspecified. The type of such a data member is
@@ -1117,6 +1151,32 @@
11171151
the type of the corresponding captured entity otherwise.
11181152
A member of an anonymous union shall not be captured by copy.
11191153

1154+
\pnum
1155+
Every \grammarterm{id-expression} within the \grammarterm{compound-statement} of a
1156+
\grammarterm{lambda-expression} that is an odr-use~(\ref{basic.def.odr}) of an
1157+
entity captured by copy is transformed into an access to the corresponding unnamed data
1158+
member of the closure type.
1159+
\enternote An \grammarterm{id-expression} that is not an odr-use refers to
1160+
the original entity, never to a member of the closure type. Furthermore, such
1161+
an \grammarterm{id-expression} does not cause the implicit capture of the
1162+
entity. \exitnote
1163+
If \tcode{*this} is captured by copy, each odr-use of \tcode{this} is
1164+
transformed into a pointer to the corresponding unnamed data member of the closure type,
1165+
cast~(\ref{expr.cast}) to the type of \tcode{this}. \enternote The cast ensures that the
1166+
transformed expression is a prvalue. \exitnote \enterexample
1167+
\begin{codeblock}
1168+
void f(const int*);
1169+
void g() {
1170+
const int N = 10;
1171+
[=] {
1172+
int arr[N]; // OK: not an odr-use, refers to automatic variable
1173+
f(&N); // OK: causes \tcode{N} to be captured; \tcode{\&N} points to the
1174+
// corresponding member of the closure type
1175+
};
1176+
}
1177+
\end{codeblock}
1178+
\exitexample
1179+
11201180
\pnum
11211181
An entity is \defnx{captured by reference}{captured!by~reference} if it is implicitly or explicitly
11221182
captured but not captured by copy. It is unspecified whether additional unnamed
@@ -1164,33 +1224,6 @@
11641224
\end{codeblock}
11651225
\exitexample
11661226

1167-
1168-
\pnum
1169-
Every \grammarterm{id-expression} within the \grammarterm{compound-statement} of a
1170-
\grammarterm{lambda-expression} that is an odr-use~(\ref{basic.def.odr}) of an
1171-
entity captured by copy is transformed into an access to the corresponding unnamed data
1172-
member of the closure type.
1173-
\enternote An \grammarterm{id-expression} that is not an odr-use refers to
1174-
the original entity, never to a member of the closure type. Furthermore, such
1175-
an \grammarterm{id-expression} does not cause the implicit capture of the
1176-
entity. \exitnote
1177-
If \tcode{this} is captured, each odr-use of \tcode{this} is
1178-
transformed into an access to the corresponding unnamed data member of the closure type,
1179-
cast~(\ref{expr.cast}) to the type of \tcode{this}. \enternote The cast ensures that the
1180-
transformed expression is a prvalue. \exitnote \enterexample
1181-
\begin{codeblock}
1182-
void f(const int*);
1183-
void g() {
1184-
const int N = 10;
1185-
[=] {
1186-
int arr[N]; // OK: not an odr-use, refers to automatic variable
1187-
f(&N); // OK: causes \tcode{N} to be captured; \tcode{\&N} points to the
1188-
// corresponding member of the closure type
1189-
};
1190-
}
1191-
\end{codeblock}
1192-
\exitexample
1193-
11941227
\pnum
11951228
Every occurrence of \tcode{decltype((x))} where \tcode{x} is a possibly
11961229
parenthesized \grammarterm{id-expression} that names an entity of automatic storage

0 commit comments

Comments
 (0)