Skip to content

Commit 68aa22b

Browse files
jensmaurerzygoloid
authored andcommitted
P1825R0 Merged wording for P0527R1 and P1155R3
- P0527R1 Implicitly move from rvalue references in return statements - P1155R3 More implicit moves
1 parent 1bac4eb commit 68aa22b

File tree

2 files changed

+67
-12
lines changed

2 files changed

+67
-12
lines changed

source/classes.tex

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6588,35 +6588,39 @@
65886588
\end{example}
65896589

65906590
\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.
65916595
In the following copy-initialization contexts, a move operation might be used instead of a copy operation:
65926596
\begin{itemize}
65936597
\item If the \grammarterm{expression} in a \tcode{return} or \tcode{co_return} statement\iref{stmt.return}
65946598
is a (possibly parenthesized) \grammarterm{id-expression}
6595-
that names an object with automatic storage duration declared in the body
6599+
that names an implicitly movable entity declared in the body
65966600
or \grammarterm{parameter-declaration-clause} of the innermost enclosing
65976601
function or \grammarterm{lambda-expression}, or
65986602

65996603
\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),
6604+
is a (possibly parenthesized) \grammarterm{id-expression}
6605+
that names an implicitly movable entity
6606+
whose scope does not extend beyond the \grammarterm{compound-statement}
6607+
of the innermost \grammarterm{try-block} or \grammarterm{function-try-block}
6608+
(if any)
6609+
whose \grammarterm{compound-statement} or \grammarterm{ctor-initializer}
6610+
encloses the \grammarterm{throw-expression},
66046611
\end{itemize}
66056612
overload resolution to select the constructor
66066613
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.
6614+
is first performed as if the expression or operand were an rvalue.
66096615
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.
6616+
overload resolution is performed again,
6617+
considering the expression or operand as an lvalue.
66146618
\begin{note}
66156619
This two-stage overload resolution must be performed regardless
66166620
of whether copy elision will occur. It determines the constructor
66176621
or the \tcode{return_value} overload to be called if
66186622
elision is not performed, and the selected constructor
6619-
or the \tcode{return_value} overload must be accessible even if
6623+
or \tcode{return_value} overload must be accessible even if
66206624
the call is elided.
66216625
\end{note}
66226626

@@ -6653,6 +6657,28 @@
66536657
\end{codeblock}
66546658
\end{example}
66556659

6660+
\pnum
6661+
\begin{example}
6662+
\begin{codeblock}
6663+
void f() {
6664+
T x;
6665+
try {
6666+
T y;
6667+
try { g(x); }
6668+
catch (...) {
6669+
if (/*...*/)
6670+
throw x; // does not move
6671+
throw y; // moves
6672+
}
6673+
g(y);
6674+
} catch(...) {
6675+
g(x);
6676+
// g(y); // error
6677+
}
6678+
}
6679+
\end{codeblock}
6680+
\end{example}
6681+
66566682
\rSec1[class.compare]{Comparisons}%
66576683

66586684
\rSec2[class.compare.default]{Defaulted comparison operator functions}%

source/compatibility.tex

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,6 +2035,35 @@
20352035
};
20362036
\end{codeblock}
20372037

2038+
\diffref{class.copy.elision}
2039+
\change
2040+
A function returning an implicitly movable entity\iref{class.copy.elision}
2041+
may invoke a constructor taking an rvalue reference to a type
2042+
different from that of the returned expression.
2043+
Function and catch-clause parameters can be thrown using move constructors.
2044+
\rationale
2045+
Side effect of making it easier to write
2046+
more efficient code that takes advantage of moves.
2047+
\effect
2048+
Valid \CppXVII{} code may fail to compile in this International Standard.
2049+
For example:
2050+
\begin{codeblock}
2051+
struct base {
2052+
base();
2053+
base(base const &);
2054+
private:
2055+
base(base &&);
2056+
};
2057+
2058+
struct derived : base {};
2059+
2060+
base f(base b) {
2061+
throw b; // error: \tcode{base(base \&\&)} is private
2062+
derived d;
2063+
return d; // error: \tcode{base(base \&\&)} is private
2064+
}
2065+
\end{codeblock}
2066+
20382067
\rSec2[diff.cpp17.over]{\ref{over}: overloading}
20392068

20402069
\diffref{over.match.oper}

0 commit comments

Comments
 (0)