<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2432</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
  INS { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  .INS { text-decoration:none; background-color:#D0FFD0 }
  DEL { text-decoration:line-through; background-color:#FFA0A0 }
  .DEL { text-decoration:line-through; background-color: #FFD0D0 }
  @media (prefers-color-scheme: dark) {
    HTML { background-color:#202020; color:#f0f0f0; }
    A { color:#5bc0ff; }
    A:visited { color:#c6a8ff; }
    A:hover, a:focus { color:#afd7ff; }
    INS { background-color:#033a16; color:#aff5b4; }
    .INS { background-color: #033a16; }
    DEL { background-color:#67060c; color:#ffdcd7; }
    .DEL { background-color:#67060c; }
  }
  SPAN.cmnt { font-family:Times; font-style:italic }
</STYLE>
</HEAD>
<BODY>
<P><EM>This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21
  Core Issues List revision 118b.
  See http://www.open-std.org/jtc1/sc22/wg21/ for the official
  list.</EM></P>
<P>2025-09-28</P>
<HR>
<A NAME="2432"></A><H4>2432.
  
Return types for defaulted <TT>&lt;=&gt;</TT>
</H4>
<B>Section: </B>11.10.3&#160; [<A href="https://wg21.link/class.spaceship">class.spaceship</A>]
 &#160;&#160;&#160;

 <B>Status: </B>C++20
 &#160;&#160;&#160;

 <B>Submitter: </B>Richard Smith
 &#160;&#160;&#160;

 <B>Date: </B>2019-08-14<BR>


<P>[Adopted as a DR at the November, 2019 meeting.]</P>

<P>It is unclear what the constraints are on the type R.  We
define the "synthesized three-way comparison for comparison
category type R", but it's defined in such a way that it
works for an arbitrary type R, and the uses of it do not
impose a constraint that R is a comparison category
type. Should it be permissible to default
an <TT>operator&lt;=&gt;</TT> with some other return type,
so long as the construction described in
11.10.3 [<A href="https://wg21.link/class.spaceship">class.spaceship</A>] works (specifically, so long as
all subobjects have <TT>operator&lt;=&gt;</TT>s that can be
converted to the specified return type)?</P>

<P><B>Proposed resolution (September, 2019)</B></P>

<P>Change 11.10.3 [<A href="https://wg21.link/class.spaceship">class.spaceship</A>] paragraphs 1-3, changing the
running text of paragraph 2 to into a bulleted list, as follows:</P>

<BLOCKQUOTE>

<P>The <I>synthesized three-way comparison</I>
<DEL>for comparison category</DEL> <INS>of</INS>
type <TT>R</TT> (17.12.2 [<A href="https://wg21.link/cmp.categories">cmp.categories</A>]) of
glvalues <TT>a</TT> and <TT>b</TT>...</P>

<P>
<INS>Let <TT>R</TT> be the declared return type of a
defaulted three-way comparison operator function.</INS>
Given an expanded list of subobjects for an
object <TT>x</TT> of
type <TT>C</TT>, <INS>let <TT>R</TT><I><SUB>i</SUB></I> be</INS>
the type of the expression <TT>x</TT><I><SUB>i</SUB></I>
<TT>&lt;=&gt; x</TT><I><SUB>i</SUB></I><DEL> is denoted
by <TT>R</TT><I><SUB>i</SUB></I>. If</DEL>
<INS>, or <TT>void</TT> if</INS> overload resolution <DEL>as</DEL>
applied to <DEL><TT>x</TT><I><SUB>i</SUB></I>
<TT>&lt;=&gt; x</TT><I><SUB>i</SUB></I></DEL>
<INS>that expression</INS> does not find a usable
function<DEL>, then <TT>R</TT><I><SUB>i</SUB></I>
is <TT>void</TT></DEL>.</P>

<UL>
<LI><P>If <DEL>the declared return type of a
defaulted three-way comparison operator function</DEL>
<INS><TT>R</TT></INS> is <TT>auto</TT>, then the return type
is deduced as the common comparison type (see below)
of <TT>R</TT><I><SUB>0</SUB></I>,
<TT>R</TT><I><SUB>1</SUB></I>,
..., <TT>R</TT><I><SUB>n-1</SUB></I>. If the return type is
deduced as <TT>void</TT>, the operator function is defined
as deleted.</P></LI>

<LI><P>
<DEL>If the declared return type of a defaulted
three-way comparison operator function is <TT>R</TT> and</DEL>
<INS>Otherwise, if</INS> the synthesized three-way
comparison <DEL>for comparison category</DEL>
<INS>of</INS> type <TT>R</TT> between any
objects <TT>x</TT><I><SUB>i</SUB></I>
and <TT>x</TT><I><SUB>i</SUB></I> is not defined or would be
ill-formed, the operator function is defined as deleted.</P></LI>

</UL>

<P>...until the first index <I>i</I> where the synthesized
three-way comparison <DEL>for comparison category</DEL>
<INS>of</INS> type <TT>R</TT>
between <TT>x</TT><I><SUB>i</SUB></I>
and <TT>y</TT><I><SUB>i</SUB></I> yields...</P>

</BLOCKQUOTE>

<BR><BR>
</BODY>
</HTML>
