Skip to content

Commit 2ad3129

Browse files
burblebeetkoeppe
authored andcommitted
CWG2586 Explicit object parameter for assignment and comparison
1 parent 2ba4c2f commit 2ad3129

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

source/classes.tex

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,7 +1678,7 @@
16781678
\indextext{operator!move assignment|see{assignment operator, move}}%
16791679
A user-declared \term{copy} assignment operator \tcode{X::operator=} is a
16801680
non-static non-template member function of class \tcode{X} with exactly one
1681-
parameter of type \tcode{X}, \tcode{X\&}, \tcode{const X\&},
1681+
non-object parameter of type \tcode{X}, \tcode{X\&}, \tcode{const X\&},
16821682
\tcode{volatile X\&}, or \tcode{const volatile X\&}.
16831683
\begin{footnote}
16841684
Because
@@ -1763,7 +1763,7 @@
17631763
\pnum
17641764
A user-declared move assignment operator \tcode{X::operator=} is
17651765
a non-static non-template member function of class \tcode{X} with exactly
1766-
one parameter of type \tcode{X\&\&}, \tcode{const X\&\&}, \tcode{volatile X\&\&}, or
1766+
one non-object parameter of type \tcode{X\&\&}, \tcode{const X\&\&}, \tcode{volatile X\&\&}, or
17671767
\tcode{const volatile X\&\&}.
17681768
\begin{note}
17691769
An overloaded assignment operator must be
@@ -6457,15 +6457,14 @@
64576457
that is
64586458
\begin{itemize}
64596459
\item
6460-
a non-static const non-volatile member of \tcode{C} having
6461-
one parameter of type \tcode{const C\&} and either
6462-
no \grammarterm{ref-qualifier} or
6463-
the \grammarterm{ref-qualifier} \tcode{\&}, or
6460+
a non-static member or friend of \tcode{C} and
64646461

64656462
\item
6466-
a friend of \tcode{C} having either
6463+
either has
64676464
two parameters of type \tcode{const C\&} or
6468-
two parameters of type \tcode{C}.
6465+
two parameters of type \tcode{C},
6466+
where the implicit object parameter (if any) is considered to be
6467+
the first parameter.
64696468
\end{itemize}
64706469
A comparison operator function for class \tcode{C} that
64716470
is defaulted on its first declaration and

source/declarations.tex

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6211,28 +6211,38 @@
62116211
\end{itemize}
62126212

62136213
\pnum
6214-
The type \tcode{T}$_1$ of an explicitly defaulted special member function \tcode{F}
6215-
is allowed to differ from the type \tcode{T}$_2$ it would have had
6216-
if it were implicitly declared, as follows:
6214+
An explicitly defaulted special member function $\tcode{F}_1$
6215+
with type $\tcode{T}_1$
6216+
is allowed to differ from
6217+
the corresponding special member function $\tcode{F}_2$
6218+
with type $\tcode{T}_2$
6219+
that would have been implicitly declared, as follows:
62176220
\begin{itemize}
62186221
\item
6219-
\tcode{T}$_1$ and \tcode{T}$_2$ may have differing \grammarterm{ref-qualifier}{s};
6222+
$\tcode{T}_1$ and $\tcode{T}_2$ may have differing \grammarterm{ref-qualifier}{s};
62206223
\item
6221-
\tcode{T}$_1$ and \tcode{T}$_2$ may have differing exception specifications; and
6224+
if $\tcode{F}_2$ has an implicit object parameter of
6225+
type ``reference to \tcode{C}'',
6226+
$\tcode{F}_1$ may be an explicit object member function whose
6227+
explicit object parameter is of type ``reference to \tcode{C}'';
62226228
\item
6223-
if \tcode{T}$_2$ has a parameter of type \tcode{const C\&},
6224-
the corresponding parameter of \tcode{T}$_1$ may be of type \tcode{C\&}.
6229+
$\tcode{T}_1$ and $\tcode{T}_2$ may have differing exception specifications; and
6230+
\item
6231+
if $\tcode{F}_2$ has a non-object parameter of type \tcode{const C\&},
6232+
the corresponding non-object parameter of $\tcode{F}_1$ may be of
6233+
type \tcode{C\&}.
62256234
\end{itemize}
6226-
If \tcode{T}$_1$ differs from \tcode{T}$_2$ in any other way, then:
6235+
If $\tcode{T}_1$ differs from $\tcode{T}_2$ in a way
6236+
other than as allowed by the preceding rules, then:
62276237
\begin{itemize}
62286238
\item
6229-
if \tcode{F} is an assignment operator, and
6230-
the return type of \tcode{T}$_1$ differs from
6231-
the return type of \tcode{T}$_2$ or
6232-
\tcode{T}$_1${'s} parameter type is not a reference,
6239+
if $\tcode{F}_1$ is an assignment operator, and
6240+
the return type of $\tcode{T}_1$ differs from
6241+
the return type of $\tcode{T}_2$ or
6242+
$\tcode{F}_1${'s} non-object parameter type is not a reference,
62336243
the program is ill-formed;
62346244
\item
6235-
otherwise, if \tcode{F} is explicitly defaulted on its first declaration,
6245+
otherwise, if $\tcode{F}_1$ is explicitly defaulted on its first declaration,
62366246
it is defined as deleted;
62376247
\item
62386248
otherwise, the program is ill-formed.

0 commit comments

Comments
 (0)