Skip to content

Commit fc62568

Browse files
authored
Merge 2019-07 CWG Motion 23
P1825R0 Merged wording for P0527R1 and P1155R3 Fixes #3002.
2 parents 1bac4eb + b3b7d37 commit fc62568

File tree

2 files changed

+71
-13
lines changed

2 files changed

+71
-13
lines changed

source/classes.tex

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6588,35 +6588,40 @@
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}
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
65946599
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
65966601
or \grammarterm{parameter-declaration-clause} of the innermost enclosing
65976602
function or \grammarterm{lambda-expression}, or
65986603

65996604
\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},
66046612
\end{itemize}
66056613
overload resolution to select the constructor
66066614
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.
66096616
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.
66146619
\begin{note}
66156620
This two-stage overload resolution must be performed regardless
66166621
of whether copy elision will occur. It determines the constructor
66176622
or the \tcode{return_value} overload to be called if
66186623
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
66206625
the call is elided.
66216626
\end{note}
66226627

@@ -6653,6 +6658,30 @@
66536658
\end{codeblock}
66546659
\end{example}
66556660

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+
66566685
\rSec1[class.compare]{Comparisons}%
66576686

66586687
\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)