Skip to content

Commit c88aa3c

Browse files
authored
Merge 2019-07 CWG Motion 9
P1630R1 Spaceship needs a tune-up Fixes #2988.
2 parents 6e5a3e9 + 5d1bb1c commit c88aa3c

File tree

3 files changed

+104
-52
lines changed

3 files changed

+104
-52
lines changed

source/classes.tex

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6708,6 +6708,12 @@
67086708
\item a friend of \tcode{C} having two parameters of type \tcode{const C\&}.
67096709
\end{itemize}
67106710

6711+
\pnum
6712+
A defaulted comparison operator function for class \tcode{C}
6713+
is defined as deleted if
6714+
any non-static data member of \tcode{C} is of reference type or
6715+
\tcode{C} is a union-like class\iref{class.union.anon}.
6716+
67116717
\pnum
67126718
If the class definition
67136719
does not explicitly declare an \tcode{==} operator function,
@@ -6744,15 +6750,22 @@
67446750
given a glvalue \tcode{x} of type \tcode{const C}, either:
67456751
\begin{itemize}
67466752
\item
6747-
\tcode{C} is a non-class type and \tcode{x <=> x} is a valid expression
6748-
of type \tcode{std::strong_ordering} or \tcode{std::strong_equality}, or
6753+
\tcode{C} is a non-class type and
6754+
\tcode{x <=> x} is a valid expression
6755+
of type \tcode{std::strong_ordering} or \tcode{std::strong_equality}, or
6756+
67496757
\item
6750-
\tcode{C} is a class type with an \tcode{==} operator
6751-
defined as defaulted in the definition of \tcode{C},
6752-
\tcode{x == x} is well-formed when contextually converted to \tcode{bool},
6753-
all of \tcode{C}'s base class subobjects and non-static data members
6754-
have strong structural equality, and
6755-
\tcode{C} has no \tcode{mutable} or \tcode{volatile} subobjects.
6758+
\tcode{C} is a class type
6759+
where all of the following hold:
6760+
\begin{itemize}
6761+
\item All of \tcode{C}'s base class subobjects and non-static data members
6762+
have strong structural equality.
6763+
\item \tcode{C} has no mutable or volatile non-static data members.
6764+
\item At the end of the definition of \tcode{C},
6765+
overload resolution performed for the expression \tcode{x == x} succeeds and
6766+
finds either a friend or public member \tcode{==} operator
6767+
that is defined as defaulted in the definition of \tcode{C}.
6768+
\end{itemize}
67566769
\end{itemize}
67576770

67586771
\pnum
@@ -6807,15 +6820,12 @@
68076820
with parameters \tcode{x} and \tcode{y} is defined as deleted if
68086821
\begin{itemize}
68096822
\item
6810-
overload resolution\iref{over.match}, as applied to \tcode{x == y}
6811-
(also considering synthesized candidates
6812-
with reversed order of parameters\iref{over.match.oper}),
6813-
results in an ambiguity or a function
6814-
that is deleted or inaccessible from the operator function, or
6823+
overload resolution\iref{over.match}, as applied to \tcode{x == y},
6824+
does not result in a usable function, or
68156825
\item
6816-
\tcode{x == y} cannot be contextually converted to \tcode{bool}.
6826+
\tcode{x == y} is not a prvalue of type \tcode{bool}.
68176827
\end{itemize}
6818-
Otherwise, the operator function yields \tcode{(x == y) ?\ false :\ true}.
6828+
Otherwise, the operator function yields \tcode{!(x == y)}.
68196829

68206830
\pnum
68216831
\begin{example}
@@ -6824,7 +6834,7 @@
68246834
int i;
68256835
friend bool operator==(const D& x, const D& y) = default;
68266836
// OK, returns \tcode{x.i == y.i}
6827-
bool operator!=(const D& z) const = default; // OK, returns \tcode{(*this == z) ?\ false :\ true}
6837+
bool operator!=(const D& z) const = default; // OK, returns \tcode{!(*this == z)}
68286838
};
68296839
\end{codeblock}
68306840
\end{example}
@@ -6990,10 +7000,8 @@
69907000
\begin{itemize}
69917001
\item
69927002
overload resolution\iref{over.match},
6993-
as applied to \tcode{x <=> y}
6994-
results in an ambiguity
6995-
or a function that is deleted or inaccessible from the operator function,
6996-
or
7003+
as applied to \tcode{x <=> y},
7004+
does not result in a usable function, or
69977005

69987006
\item
69997007
the operator \tcode{@}

source/compatibility.tex

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,37 @@
20042004
};
20052005
\end{codeblock}
20062006

2007+
\rSec2[diff.cpp17.over]{\ref{over}: overloading}
2008+
2009+
\diffref{over.match.oper}
2010+
\change
2011+
Equality and inequality expressions can now find
2012+
reversed and rewritten candidates.
2013+
\rationale
2014+
Improve consistency of equality with three-way comparison
2015+
and make it easier to write the full complement of equality operations.
2016+
\effect
2017+
Equality and inequality expressions between two objects of different types,
2018+
where one is convertible to the other,
2019+
could invoke a different operator.
2020+
Equality and inequality expressions between two objects of the same type
2021+
could become ambiguous.
2022+
\begin{codeblock}
2023+
struct A {
2024+
operator int() const;
2025+
};
2026+
2027+
bool operator==(A, int); // \#1
2028+
// \#2 is built-in candidate: \tcode{bool operator==(int, int);}
2029+
// \#3 is built-in candidate: \tcode{bool operator!=(int, int);}
2030+
2031+
int check(A x, A y) {
2032+
return (x == y) + // ill-formed; previously well-formed
2033+
(10 == x) + // calls \#1, previously selected \#2
2034+
(10 != x); // calls \#1, previously selected \#3
2035+
}
2036+
\end{codeblock}
2037+
20072038
\rSec2[diff.cpp17.temp]{\ref{temp}: templates}
20082039

20092040
\diffref{temp.names}

source/overloading.tex

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,44 +1077,44 @@
10771077
that is not a function template specialization.
10781078
\end{itemize}
10791079

1080+
\item
1081+
The rewritten candidate set is determined as follows:
1082+
\begin{itemize}
10801083
\item
10811084
For the relational\iref{expr.rel} operators,
10821085
the rewritten candidates include
1083-
all member, non-member, and built-in candidates
1084-
for the operator \tcode{<=>}
1085-
for which the rewritten expression
1086-
\tcode{(x <=> y) @ 0} is well-formed using that \tcode{operator<=>}.
1086+
all non-rewritten candidates
1087+
for the expression \tcode{x <=> y}.
1088+
\item
10871089
For the
10881090
relational\iref{expr.rel} and
10891091
three-way comparison\iref{expr.spaceship}
10901092
operators,
10911093
the rewritten candidates also include
10921094
a synthesized candidate,
10931095
with the order of the two parameters reversed,
1094-
for each member, non-member, and built-in candidate
1095-
for the operator \tcode{<=>}
1096-
for which the rewritten expression
1097-
\tcode{0 @ (y <=> x)} is well-formed using that \tcode{operator<=>}.
1096+
for each non-rewritten candidate
1097+
for the expression
1098+
\tcode{y <=> x}.
1099+
\item
10981100
For the \tcode{!=} operator\iref{expr.eq},
10991101
the rewritten candidates
1100-
include all member, non-member, and built-in candidates
1101-
for the operator \tcode{==}
1102-
for which the rewritten expression \tcode{(x == y)} is well-formed
1103-
when contextually converted to \tcode{bool} using that operator \tcode{==}.
1102+
include all non-rewritten candidates
1103+
for the expression \tcode{x == y}.
1104+
\item
11041105
For the equality operators,
11051106
the rewritten candidates also include a synthesized candidate,
11061107
with the order of the two parameters reversed,
1107-
for each member, non-member, and built-in candidate for the operator \tcode{==}
1108-
for which the rewritten expression \tcode{(y == x)} is well-formed
1109-
when contextually converted to \tcode{bool} using that operator \tcode{==}.
1108+
for each non-rewritten candidate
1109+
for the expression \tcode{y == x}.
1110+
\item
1111+
For all other operators, the rewritten candidate set is empty.
1112+
\end{itemize}
11101113
\begin{note}
11111114
A candidate synthesized from a member candidate has its implicit
11121115
object parameter as the second parameter, thus implicit conversions
11131116
are considered for the first, but not for the second, parameter.
11141117
\end{note}
1115-
In each case, rewritten candidates are not considered
1116-
in the context of the rewritten expression.
1117-
For all other operators, the rewritten candidate set is empty.
11181118
\end{itemize}
11191119

11201120
\pnum
@@ -1165,26 +1165,39 @@
11651165
\end{example}
11661166

11671167
\pnum
1168-
If a rewritten candidate is selected by overload resolution
1169-
for a relational or three-way comparison operator \tcode{@},
1168+
If a rewritten \tcode{operator<=>} candidate
1169+
is selected by overload resolution
1170+
for an operator \tcode{@},
11701171
\tcode{x @ y}
1171-
is interpreted as the rewritten expression:
1172+
is interpreted as
11721173
\tcode{0 @ (y <=> x)}
11731174
if the selected candidate is a synthesized candidate
11741175
with reversed order of parameters,
11751176
or \tcode{(x <=> y) @ 0} otherwise,
11761177
using the selected rewritten \tcode{operator<=>} candidate.
1177-
If a rewritten candidate is selected by overload resolution
1178-
for a \tcode{!=} operator,
1179-
\tcode{x != y} is interpreted as \tcode{(y == x) ?\ false :\ true}
1180-
if the selected candidate is a synthesized candidate
1181-
with reversed order of parameters, or
1182-
\tcode{(x == y) ?\ false :\ true} otherwise,
1183-
using the selected rewritten \tcode{operator==} candidate.
1184-
If a rewritten candidate is selected by overload resolution
1185-
for an \tcode{==} operator,
1186-
\tcode{x == y} is interpreted as \tcode{(y == x) ?\ true :\ false}
1187-
using the selected rewritten \tcode{operator==} candidate.
1178+
Rewritten candidates for the operator \tcode{@}
1179+
are not considered in the context of the resulting expression.
1180+
1181+
\pnum
1182+
If a rewritten \tcode{operator==} candidate
1183+
is selected by overload resolution
1184+
for an operator \tcode{@},
1185+
its return type shall be \cv{} \tcode{bool}, and
1186+
\tcode{x @ y} is interpreted as:
1187+
\begin{itemize}
1188+
\item
1189+
if \tcode{@} is \tcode{!=}
1190+
and the selected candidate is a synthesized candidate
1191+
with reversed order of parameters,
1192+
\tcode{!(y == x)},
1193+
\item
1194+
otherwise, if \tcode{@} is \tcode{!=},
1195+
\tcode{!(x == y)},
1196+
\item
1197+
otherwise (when \tcode{@} is \tcode{==}),
1198+
\tcode{y == x},
1199+
\end{itemize}
1200+
in each case using the selected rewritten \tcode{operator==} candidate.
11881201

11891202
\pnum
11901203
If a built-in candidate is selected by overload resolution, the

0 commit comments

Comments
 (0)