|
1473 | 1473 | If naming the entity from outside of an unevaluated operand within $S$
|
1474 | 1474 | would refer to an entity
|
1475 | 1475 | captured by copy in some intervening \grammarterm{lambda-expression},
|
1476 |
| -then let $E$ be the innermost such \grammarterm{lambda-expression}, and: |
| 1476 | +then let $E$ be the innermost such \grammarterm{lambda-expression}. |
1477 | 1477 | \begin{itemize}
|
1478 | 1478 | \item
|
1479 |
| -If $P$ is in $E$'s function parameter scope |
| 1479 | +If there is such a \grammarterm{lambda-expression} and |
| 1480 | +if $P$ is in $E$'s function parameter scope |
1480 | 1481 | but not its \grammarterm{parameter-declaration-clause}, then
|
1481 | 1482 | the type of the expression is
|
1482 | 1483 | the type of a class member access expression\iref{expr.ref}
|
|
1488 | 1489 | the type of such an identifier will typically be \keyword{const} qualified.
|
1489 | 1490 | \end{note}
|
1490 | 1491 | \item
|
1491 |
| -Otherwise (if $P$ either precedes $E$'s function parameter scope or |
| 1492 | +Otherwise (if there is no such \grammarterm{lambda-expression} or |
| 1493 | +if $P$ either precedes $E$'s function parameter scope or |
1492 | 1494 | is in $E$'s \grammarterm{parameter-declaration-clause}),
|
1493 |
| -the program is ill-formed. |
| 1495 | +the type of the expression is the type of the result. |
1494 | 1496 | \end{itemize}
|
1495 |
| -Otherwise, the type of the expression is the type of the result. |
1496 | 1497 | \begin{note}
|
1497 | 1498 | If the entity is a template parameter object for
|
1498 | 1499 | a template parameter of type \tcode{T}\iref{temp.param},
|
|
1521 | 1522 | return y2;
|
1522 | 1523 | };
|
1523 | 1524 |
|
1524 |
| - [=]<decltype(x) P>{}; // error: \tcode{x} refers to local entity but precedes the |
1525 |
| - // lambda's function parameter scope |
1526 |
| - [=](decltype((x)) y){}; // error: \tcode{x} refers to local entity but is in the lambda's |
1527 |
| - // \grammarterm{parameter-declaration-clause} |
| 1525 | + [=](decltype((x)) y){ |
| 1526 | + decltype((x)) z = x; // OK, \tcode{y} has type \tcode{float\&}, \tcode{z} has type \tcode{float const\&} |
| 1527 | + }; |
1528 | 1528 | [=]{
|
1529 |
| - []<decltype(x) P>{}; // OK, \tcode{x} is in the outer lambda's function parameter scope |
1530 | 1529 | [](decltype((x)) y){}; // OK, lambda takes a parameter of type \tcode{float const\&}
|
1531 |
| - [x=1](decltype((x)) z){}; // error: \tcode{x} refers to \grammarterm{init-capture} but is in the lambda's |
1532 |
| - // \grammarterm{parameter-declaration-clause} |
| 1530 | + [x=1](decltype((x)) z){ |
| 1531 | + decltype((x)) z = x; // OK, \tcode{y} has type \tcode{int\&}, \tcode{z} has type \tcode{int const\&} |
| 1532 | + }; |
1533 | 1533 | };
|
1534 | 1534 | }
|
1535 | 1535 | \end{codeblock}
|
|
2310 | 2310 | is said to be \defn{explicitly captured}.
|
2311 | 2311 |
|
2312 | 2312 | \pnum
|
2313 |
| -If an \grammarterm{identifier} in a \grammarterm{simple-capture} appears |
| 2313 | +If an \grammarterm{identifier} in a \grammarterm{capture} appears |
2314 | 2314 | as the \grammarterm{declarator-id} of a parameter of
|
2315 |
| -the \grammarterm{lambda-declarator}{'s} \grammarterm{parameter-declaration-clause}, |
| 2315 | +the \grammarterm{lambda-declarator}'s \grammarterm{parameter-declaration-clause} |
| 2316 | +or as the name of a template parameter of |
| 2317 | +the \grammarterm{lambda-expression}'s \grammarterm{template-parameter-list}, |
2316 | 2318 | the program is ill-formed.
|
2317 | 2319 | \begin{example}
|
2318 | 2320 | \begin{codeblock}
|
2319 | 2321 | void f() {
|
2320 | 2322 | int x = 0;
|
2321 |
| - auto g = [x](int x) { return 0; }; // error: parameter and \grammarterm{simple-capture} have the same name |
| 2323 | + auto g = [x](int x) { return 0; }; // error: parameter and \grammarterm{capture} have the same name |
| 2324 | + auto h = [y = 0]<typename y>(y) { return 0; }; // error: template parameter and \grammarterm{capture} |
| 2325 | + // have the same name |
2322 | 2326 | }
|
2323 | 2327 | \end{codeblock}
|
2324 | 2328 | \end{example}
|
2325 | 2329 |
|
2326 | 2330 | \pnum
|
2327 |
| -An \grammarterm{init-capture} inhabits the function parameter scope of |
2328 |
| -the \grammarterm{lambda-expression}'s \grammarterm{parameter-declaration-clause}. |
| 2331 | +An \grammarterm{init-capture} inhabits |
| 2332 | +the lambda scope of the \grammarterm{lambda-expression}. |
2329 | 2333 | An \grammarterm{init-capture} without ellipsis
|
2330 | 2334 | behaves as if it declares and explicitly captures a variable of
|
2331 | 2335 | the form ``\keyword{auto} \grammarterm{init-capture} \tcode{;}'', except that:
|
|
0 commit comments