|
1310 | 1310 | transformed into a pointer to the corresponding unnamed data member of the closure type,
|
1311 | 1311 | cast\iref{expr.cast} to the type of \tcode{this}. \begin{note} The cast ensures that the
|
1312 | 1312 | 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} |
1321 | 1313 | \begin{example}
|
1322 | 1314 | \begin{codeblock}
|
1323 | 1315 | void f(const int*);
|
|
1329 | 1321 | // the corresponding member of the closure type
|
1330 | 1322 | };
|
1331 | 1323 | }
|
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 |
| -} |
1338 | 1324 | \end{codeblock}
|
1339 | 1325 | \end{example}
|
1340 | 1326 |
|
|
1352 | 1338 | \end{example}
|
1353 | 1339 | A bit-field or a member of an anonymous union shall not be captured by reference.
|
1354 | 1340 |
|
| 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 | + |
1355 | 1361 | \pnum
|
1356 | 1362 | If a \grammarterm{lambda-expression} \tcode{m2} captures an entity and that entity is
|
1357 | 1363 | captured by an immediately enclosing \grammarterm{lambda-expression}
|
|
0 commit comments