diff --git a/source/expressions.tex b/source/expressions.tex index d85bede7b3..bbda6a71a0 100644 --- a/source/expressions.tex +++ b/source/expressions.tex @@ -1592,6 +1592,35 @@ the type of such an identifier will typically be \keyword{const} qualified. \end{note} +\begin{example} +\begin{codeblock} +void f() { + float x, &r = x; + + [=]() -> decltype((x)) { // lambda returns \tcode{float const\&} because this lambda is not \tcode{mutable} and + // \tcode{x} is an lvalue + decltype(x) y1; // \tcode{y1} has type \tcode{float} + decltype((x)) y2 = y1; // \tcode{y2} has type \tcode{float const\&} + decltype(r) r1 = y1; // \tcode{r1} has type \tcode{float\&} + decltype((r)) r2 = y2; // \tcode{r2} has type \tcode{float const\&} + return y2; + }; + + [=](decltype((x)) y) { + decltype((x)) z = x; // OK, \tcode{y} has type \tcode{float\&}, \tcode{z} has type \tcode{float const\&} + }; + + [=] { + [](decltype((x)) y) {}; // OK, lambda takes a parameter of type \tcode{float const\&} + + [x=1](decltype((x)) y) { + decltype((x)) z = x; // OK, \tcode{y} has type \tcode{int\&}, \tcode{z} has type \tcode{int const\&} + }; + }; +} +\end{codeblock} +\end{example} + \pnum Otherwise, if the \grammarterm{unqualified-id} @@ -1750,36 +1779,6 @@ is sequenced before the initialization of the result object\iref{expr.call}, $E$ refers to the most recently initialized such temporary object. - -\begin{example} -\begin{codeblock} -void f() { - float x, &r = x; - - [=]() -> decltype((x)) { // lambda returns \tcode{float const\&} because this lambda is not \tcode{mutable} and - // \tcode{x} is an lvalue - decltype(x) y1; // \tcode{y1} has type \tcode{float} - decltype((x)) y2 = y1; // \tcode{y2} has type \tcode{float const\&} - decltype(r) r1 = y1; // \tcode{r1} has type \tcode{float\&} - decltype((r)) r2 = y2; // \tcode{r2} has type \tcode{float const\&} - return y2; - }; - - [=](decltype((x)) y) { - decltype((x)) z = x; // OK, \tcode{y} has type \tcode{float\&}, \tcode{z} has type \tcode{float const\&} - }; - - [=] { - [](decltype((x)) y) {}; // OK, lambda takes a parameter of type \tcode{float const\&} - - [x=1](decltype((x)) y) { - decltype((x)) z = x; // OK, \tcode{y} has type \tcode{int\&}, \tcode{z} has type \tcode{int const\&} - }; - }; -} -\end{codeblock} -\end{example} - \pnum An \defnadj{implicitly movable}{entity} is a variable with automatic storage duration