Skip to content

Commit d235bb4

Browse files
committed
P2953R5 Adding restrictions to defaulted assignment operator functions
1 parent 14ed707 commit d235bb4

2 files changed

Lines changed: 65 additions & 27 deletions

File tree

source/compatibility.tex

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,46 @@
11
%!TEX root = std.tex
22
\infannex{diff}{Compatibility}
33

4+
\rSec1[diff.cpp26]{\Cpp{} and ISO \CppXXVI{}}
5+
6+
\rSec2[diff.cpp26.general]{General}
7+
8+
\pnum
9+
\indextext{summary!compatibility with ISO \CppXXVI{}}%
10+
Subclause \ref{diff.cpp26} lists the differences between \Cpp{} and
11+
ISO \CppXXVI{},
12+
by the chapters of this document.
13+
14+
\rSec2[diff.cpp26.dcl]{\ref{dcl}: declarations}
15+
16+
\diffref{dcl.fct.def.default}
17+
\change
18+
It is no longer valid
19+
for explicitly defaulted assignment operators to have a
20+
\grammarterm{cv-qualifier-seq} or \tcode{\&\&} \grammarterm{ref-qualifier}, or
21+
for an explicitly defaulted move assignment operator
22+
to have a parameter of type ``reference to \tcode{T}''
23+
where \tcode{T} is cv-qualified.
24+
\rationale
25+
Removal of rarely-used and confusing feature.
26+
\effect
27+
A valid \CppXXVI{} program
28+
which uses these features on an explicitly defaulted assignment operator
29+
is ill-formed.
30+
\begin{example}
31+
\begin{codeblock}
32+
struct S {
33+
S& operator=(const S&) && = default; // ill-formed; previously well-formed
34+
};
35+
struct T {
36+
T& operator=(const T&) const = default; // ill-formed; previously well-formed but deleted
37+
};
38+
struct U {
39+
U& operator=(const U&&) = default; // ill-formed; previously well-formed but deleted
40+
};
41+
\end{codeblock}
42+
\end{example}
43+
444
\rSec1[diff.cpp23]{\Cpp{} and ISO \CppXXIII{}}
545

646
\rSec2[diff.cpp23.general]{General}

source/declarations.tex

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7005,41 +7005,39 @@
70057005
\end{itemize}
70067006

70077007
\pnum
7008-
An explicitly defaulted special member function $\tcode{F}_1$
7009-
is allowed to differ from
7010-
the corresponding special member function $\tcode{F}_2$
7011-
that would have been implicitly declared, as follows:
7008+
The program is ill-formed
7009+
if an explicitly defaulted special member function $\tcode{F}_1$
7010+
of class \tcode{C}
7011+
differs from the corresponding special member function $\tcode{F}_2$
7012+
that would have been implicitly declared
7013+
other than as follows:
70127014
\begin{itemize}
70137015
\item
7014-
$\tcode{F}_1$ and $\tcode{F}_2$ may have differing \grammarterm{ref-qualifier}{s};
7016+
if $\tcode{F}_1$ is an assignment operator,
7017+
it may have the \tcode{\&} \grammarterm{ref-qualifier};
70157018
\item
7016-
if $\tcode{F}_2$ has an implicit object parameter of
7017-
type ``reference to \tcode{C}'',
7018-
$\tcode{F}_1$ may be an explicit object member function whose
7019-
explicit object parameter is of (possibly different) type ``reference to \tcode{C}'',
7019+
if $\tcode{F}_2$ is an assignment operator
7020+
(which has an implicit object parameter
7021+
of type ``lvalue reference to \tcode{C}''),
7022+
$\tcode{F}_1$ may have an explicit object parameter
7023+
of type ``lvalue reference to \tcode{C}'',
70207024
in which case the type of $\tcode{F}_1$ would differ from the type of $\tcode{F}_2$
70217025
in that the type of $\tcode{F}_1$ has an additional parameter;
70227026
\item
7023-
$\tcode{F}_1$ and $\tcode{F}_2$ may have differing exception specifications; and
7027+
$\tcode{F}_1$ and $\tcode{F}_2$ may have differing exception specifications;
70247028
\item
7025-
if $\tcode{F}_2$ has a non-object parameter of type \tcode{const C\&},
7026-
the corresponding non-object parameter of $\tcode{F}_1$ may be of
7027-
type \tcode{C\&}.
7028-
\end{itemize}
7029-
If the type of $\tcode{F}_1$ differs from the type of $\tcode{F}_2$ in a way
7030-
other than as allowed by the preceding rules, then:
7031-
\begin{itemize}
7032-
\item
7033-
if $\tcode{F}_1$ is an assignment operator, and
7034-
the return type of $\tcode{F}_1$ differs from
7035-
the return type of $\tcode{F}_2$ or
7036-
$\tcode{F}_1${'s} non-object parameter type is not a reference,
7037-
the program is ill-formed;
7038-
\item
7039-
otherwise, if $\tcode{F}_1$ is explicitly defaulted on its first declaration,
7040-
it is defined as deleted;
7029+
if $\tcode{F}_2$ has a non-object parameter
7030+
of type ``lvalue reference to const \tcode{C}'',
7031+
the corresponding non-object parameter of $\tcode{F}_1$ may be
7032+
of type ``lvalue reference to \tcode{C}''; and
70417033
\item
7042-
otherwise, the program is ill-formed.
7034+
if $\tcode{F}_2$ has a non-object parameter
7035+
of type ``lvalue reference to \tcode{C}'',
7036+
the corresponding non-object parameter of $\tcode{F}_1$ may be
7037+
of type ``lvalue reference to const \tcode{C}'';
7038+
in this case only, $\tcode{F}_1$ is defined as deleted
7039+
if it is explicitly defaulted on its first declaration and
7040+
the program is ill-formed otherwise.
70437041
\end{itemize}
70447042

70457043
\pnum

0 commit comments

Comments
 (0)