Skip to content

Commit df6ff5c

Browse files
authored
Merge 2019-07 CWG Motion 6
P1186R3 When do you actually use <=>? Fixes #2985.
2 parents 2a8ac4c + dc45e8c commit df6ff5c

File tree

4 files changed

+91
-9
lines changed

4 files changed

+91
-9
lines changed

source/basic.tex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,13 @@
651651
// \tcode{D()}'s implicit definition violates the ODR
652652
\end{codeblock}
653653
\end{example}
654+
655+
\item if \tcode{D} is a class with
656+
a defaulted three-way comparison operator function\iref{class.spaceship},
657+
it is as if the operator was
658+
implicitly defined in every translation unit where it is odr-used, and the
659+
implicit definition in every translation unit shall call the same
660+
comparison operators for each subobject of \tcode{D}.
654661
\end{itemize}
655662
If \tcode{D} is a template and is defined in more than one
656663
translation unit, then the preceding requirements

source/classes.tex

Lines changed: 77 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6831,24 +6831,92 @@
68316831
\rSec2[class.spaceship]{Three-way comparison}
68326832
\indextext{operator!three-way comparison!defaulted}%
68336833

6834+
\pnum
6835+
The \defnadj{synthesized}{three-way comparison}
6836+
for comparison category type \tcode{R}\iref{cmp.categories}
6837+
of glvalues \tcode{a} and \tcode{b} of the same type
6838+
is defined as follows:
6839+
6840+
\begin{itemize}
6841+
\item
6842+
If overload resolution for \tcode{a <=> b}
6843+
finds a usable function\iref{over.match},
6844+
\tcode{static_cast<R>(a <=> b)}.
6845+
6846+
\item
6847+
Otherwise, if overload resolution for \tcode{a <=> b}
6848+
finds at least one viable candidate,
6849+
the synthesized three-way comparison is not defined.
6850+
6851+
\item
6852+
Otherwise, if \tcode{R} is \tcode{strong_ordering}, then
6853+
\begin{codeblock}
6854+
a == b ? strong_ordering::equal :
6855+
a < b ? strong_ordering::less :
6856+
strong_ordering::greater
6857+
\end{codeblock}
6858+
6859+
\item
6860+
Otherwise, if \tcode{R} is \tcode{weak_ordering}, then
6861+
\begin{codeblock}
6862+
a == b ? weak_ordering::equal :
6863+
a < b ? weak_ordering::less :
6864+
weak_ordering::greater
6865+
\end{codeblock}
6866+
6867+
\item
6868+
Otherwise, if \tcode{R} is \tcode{partial_ordering}, then
6869+
\begin{codeblock}
6870+
a == b ? partial_ordering::equivalent :
6871+
a < b ? partial_ordering::less :
6872+
b < a ? partial_ordering::greater :
6873+
partial_ordering::unordered
6874+
\end{codeblock}
6875+
6876+
\item
6877+
Otherwise, if \tcode{R} is \tcode{strong_equality}, then
6878+
\begin{codeblock}
6879+
a == b ? strong_equality::equal : strong_equality::nonequal
6880+
\end{codeblock}
6881+
6882+
\item
6883+
Otherwise, if \tcode{R} is \tcode{weak_equality}, then
6884+
\begin{codeblock}
6885+
a == b ? weak_equality::equivalent : weak_equality::nonequivalent
6886+
\end{codeblock}
6887+
6888+
\item
6889+
Otherwise, the synthesized three-way comparison is not defined.
6890+
\end{itemize}
6891+
\begin{note}
6892+
A synthesized three-way comparison may be ill-formed
6893+
if overload resolution finds usable functions
6894+
that do not otherwise meet the requirements implied by the defined expression.
6895+
\end{note}
6896+
68346897
\pnum
68356898
Given an expanded list of subobjects for an object \tcode{x} of type \tcode{C},
68366899
the type of the expression $\tcode{x}_i$ \tcode{<=>} $\tcode{x}_i$
68376900
is denoted by $\tcode{R}_i$.
6901+
If overload resolution as applied to $\tcode{x}_i$ \tcode{<=>} $\tcode{x}_i$
6902+
does not find a usable function,
6903+
then $\tcode{R}_i$ is \tcode{void}.
68386904
If the declared return type
68396905
of a defaulted three-way comparison operator function
68406906
is \tcode{auto},
68416907
then the return type is deduced as
68426908
the common comparison type (see below) of
68436909
$\tcode{R}_0$, $\tcode{R}_1$, $\dotsc$, $\tcode{R}_{n-1}$.
6844-
\begin{note}
6845-
Otherwise,
6846-
the program will be ill-formed
6847-
if the expression $\tcode{x}_i$ \tcode{<=>} $\tcode{x}_i$
6848-
is not implicitly convertible to the declared return type for any $i$.
6849-
\end{note}
68506910
If the return type is deduced as \tcode{void},
68516911
the operator function is defined as deleted.
6912+
If the declared return type of
6913+
a defaulted three-way comparison operator function
6914+
is \tcode{R}
6915+
and the synthesized three-way comparison
6916+
for comparison category type \tcode{R}
6917+
between any objects $\tcode{x}_i$ and $\tcode{x}_i$
6918+
is not defined or would be ill-formed,
6919+
the operator function is defined as deleted.
68526920

68536921
\pnum
68546922
The return value \tcode{V} of type \tcode{R}
@@ -6858,8 +6926,9 @@
68586926
$\tcode{x}_i$ and $\tcode{y}_i$
68596927
in the expanded lists of subobjects for \tcode{x} and \tcode{y}
68606928
(in increasing index order)
6861-
until the first index $i$
6862-
where $\tcode{x}_i$ \tcode{<=>} $\tcode{y}_i$
6929+
until the first index $i$ where
6930+
the synthesized three-way comparison for comparison category type \tcode{R}
6931+
between $\tcode{x}_i$ and $\tcode{y}_i$
68636932
yields a result value $\tcode{v}_i$ where $\tcode{v}_i \mathrel{\tcode{!=}} 0$,
68646933
contextually converted to \tcode{bool}, yields \tcode{true};
68656934
\tcode{V} is $\tcode{v}_i$ converted to \tcode{R}.

source/overloading.tex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,12 @@
474474
in which it is used,
475475
the program is ill-formed.
476476

477+
\pnum
478+
Overload resolution results in a \defnadj{usable}{function}
479+
if overload resolution succeeds and
480+
the selected function is not deleted and
481+
is accessible from the context in which overload resolution was performed.
482+
477483
\rSec2[over.match.funcs]{Candidate functions and argument lists}%
478484
\indextext{overloading!candidate functions|(}%
479485
\indextext{overloading!argument lists|(}

source/preprocessor.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,7 @@
16971697
\defnxname{cpp_hex_float} & \tcode{201603L} \\ \rowsep
16981698
\defnxname{cpp_if_constexpr} & \tcode{201606L} \\ \rowsep
16991699
\defnxname{cpp_impl_destroying_delete} & \tcode{201806L} \\ \rowsep
1700-
\defnxname{cpp_impl_three_way_comparison} & \tcode{201711L} \\ \rowsep
1700+
\defnxname{cpp_impl_three_way_comparison} & \tcode{201907L} \\ \rowsep
17011701
\defnxname{cpp_inheriting_constructors} & \tcode{201511L} \\ \rowsep
17021702
\defnxname{cpp_init_captures} & \tcode{201304L} \\ \rowsep
17031703
\defnxname{cpp_initializer_lists} & \tcode{200806L} \\ \rowsep

0 commit comments

Comments
 (0)