Skip to content

Commit ea4b17a

Browse files
jensmaurerzygoloid
authored andcommitted
[expr.prim.lambda.capture] Move discusssion of capture-by-reference of references
to after the introduction of 'capture by reference'. Fixes #1785.
1 parent 4ba4e9c commit ea4b17a

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

source/expressions.tex

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,14 +1310,6 @@
13101310
transformed into a pointer to the corresponding unnamed data member of the closure type,
13111311
cast\iref{expr.cast} to the type of \tcode{this}. \begin{note} The cast ensures that the
13121312
transformed expression is a prvalue. \end{note}
1313-
An \grammarterm{id-expression} within
1314-
the \grammarterm{compound-statement} of a \grammarterm{lambda-expression}
1315-
that is an odr-use of a reference captured by reference
1316-
refers to the entity to which the captured reference is bound and
1317-
not to the captured reference.
1318-
\begin{note} The validity of such captures is determined by
1319-
the lifetime of the object to which the reference refers,
1320-
not by the lifetime of the reference itself. \end{note}
13211313
\begin{example}
13221314
\begin{codeblock}
13231315
void f(const int*);
@@ -1329,12 +1321,6 @@
13291321
// the corresponding member of the closure type
13301322
};
13311323
}
1332-
auto h(int &r) {
1333-
return [&] {
1334-
++r; // Valid after \tcode{h} returns if the lifetime of the
1335-
// object to which \tcode{r} is bound has not ended
1336-
};
1337-
}
13381324
\end{codeblock}
13391325
\end{example}
13401326

@@ -1352,6 +1338,26 @@
13521338
\end{example}
13531339
A bit-field or a member of an anonymous union shall not be captured by reference.
13541340

1341+
\pnum
1342+
An \grammarterm{id-expression} within
1343+
the \grammarterm{compound-statement} of a \grammarterm{lambda-expression}
1344+
that is an odr-use of a reference captured by reference
1345+
refers to the entity to which the captured reference is bound and
1346+
not to the captured reference.
1347+
\begin{note} The validity of such captures is determined by
1348+
the lifetime of the object to which the reference refers,
1349+
not by the lifetime of the reference itself. \end{note}
1350+
\begin{example}
1351+
\begin{codeblock}
1352+
auto h(int &r) {
1353+
return [&] {
1354+
++r; // Valid after \tcode{h} returns if the lifetime of the
1355+
// object to which \tcode{r} is bound has not ended
1356+
};
1357+
}
1358+
\end{codeblock}
1359+
\end{example}
1360+
13551361
\pnum
13561362
If a \grammarterm{lambda-expression} \tcode{m2} captures an entity and that entity is
13571363
captured by an immediately enclosing \grammarterm{lambda-expression}

0 commit comments

Comments
 (0)