|
6588 | 6588 | \end{example}
|
6589 | 6589 |
|
6590 | 6590 | \pnum
|
| 6591 | +An \defnadj{implicitly movable}{entity} is |
| 6592 | +a variable of automatic storage duration |
| 6593 | +that is either a non-volatile object or |
| 6594 | +an rvalue reference to a non-volatile object type. |
6591 | 6595 | In the following copy-initialization contexts, a move operation might be used instead of a copy operation:
|
6592 | 6596 | \begin{itemize}
|
6593 |
| -\item If the \grammarterm{expression} in a \tcode{return} or \tcode{co_return} statement\iref{stmt.return} |
| 6597 | +\item If the \grammarterm{expression} in a \tcode{return}\iref{stmt.return} or |
| 6598 | +\tcode{co_return}\iref{stmt.return.coroutine} statement |
6594 | 6599 | is a (possibly parenthesized) \grammarterm{id-expression}
|
6595 |
| -that names an object with automatic storage duration declared in the body |
| 6600 | +that names an implicitly movable entity declared in the body |
6596 | 6601 | or \grammarterm{parameter-declaration-clause} of the innermost enclosing
|
6597 | 6602 | function or \grammarterm{lambda-expression}, or
|
6598 | 6603 |
|
6599 | 6604 | \item if the operand of a \grammarterm{throw-expression}\iref{expr.throw}
|
6600 |
| -is the name of a non-volatile automatic object |
6601 |
| -(other than a function or catch-clause parameter) |
6602 |
| -whose scope does not extend beyond the end of the innermost enclosing |
6603 |
| -\grammarterm{try-block} (if there is one), |
| 6605 | +is a (possibly parenthesized) \grammarterm{id-expression} |
| 6606 | +that names an implicitly movable entity |
| 6607 | +whose scope does not extend beyond the \grammarterm{compound-statement} |
| 6608 | +of the innermost \grammarterm{try-block} or \grammarterm{function-try-block} |
| 6609 | +(if any) |
| 6610 | +whose \grammarterm{compound-statement} or \grammarterm{ctor-initializer} |
| 6611 | +encloses the \grammarterm{throw-expression}, |
6604 | 6612 | \end{itemize}
|
6605 | 6613 | overload resolution to select the constructor
|
6606 | 6614 | for the copy or the \tcode{return_value} overload to call
|
6607 |
| -is first performed as if the object were designated by an |
6608 |
| -rvalue. |
| 6615 | +is first performed as if the expression or operand were an rvalue. |
6609 | 6616 | If the first overload resolution fails or was not performed,
|
6610 |
| -or if the type of the first parameter of the selected |
6611 |
| -constructor or the \tcode{return_value} overload |
6612 |
| -is not an rvalue reference to the object's type (possibly cv-qualified), |
6613 |
| -overload resolution is performed again, considering the object as an lvalue. |
| 6617 | +overload resolution is performed again, |
| 6618 | +considering the expression or operand as an lvalue. |
6614 | 6619 | \begin{note}
|
6615 | 6620 | This two-stage overload resolution must be performed regardless
|
6616 | 6621 | of whether copy elision will occur. It determines the constructor
|
6617 | 6622 | or the \tcode{return_value} overload to be called if
|
6618 | 6623 | elision is not performed, and the selected constructor
|
6619 |
| -or the \tcode{return_value} overload must be accessible even if |
| 6624 | +or \tcode{return_value} overload must be accessible even if |
6620 | 6625 | the call is elided.
|
6621 | 6626 | \end{note}
|
6622 | 6627 |
|
|
6653 | 6658 | \end{codeblock}
|
6654 | 6659 | \end{example}
|
6655 | 6660 |
|
| 6661 | +\pnum |
| 6662 | +\begin{example} |
| 6663 | +\begin{codeblock} |
| 6664 | +template<class T> void g(const T&); |
| 6665 | + |
| 6666 | +template<class T> void f() { |
| 6667 | + T x; |
| 6668 | + try { |
| 6669 | + T y; |
| 6670 | + try { g(x); } |
| 6671 | + catch (...) { |
| 6672 | + if (/*...*/) |
| 6673 | + throw x; // does not move |
| 6674 | + throw y; // moves |
| 6675 | + } |
| 6676 | + g(y); |
| 6677 | + } catch(...) { |
| 6678 | + g(x); |
| 6679 | + g(y); // error: \tcode{y} is not in scope |
| 6680 | + } |
| 6681 | +} |
| 6682 | +\end{codeblock} |
| 6683 | +\end{example} |
| 6684 | + |
6656 | 6685 | \rSec1[class.compare]{Comparisons}%
|
6657 | 6686 |
|
6658 | 6687 | \rSec2[class.compare.default]{Defaulted comparison operator functions}%
|
|
0 commit comments