<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2547</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="2547"></A><H4>2547.
  
Defaulted comparison operator function for non-classes
</H4>
<B>Section: </B>9.6.2&#160; [<A href="https://wg21.link/dcl.fct.def.default">dcl.fct.def.default</A>]
 &#160;&#160;&#160;

 <B>Status: </B>CD7
 &#160;&#160;&#160;

 <B>Submitter: </B>Jim X
 &#160;&#160;&#160;

 <B>Date: </B>2022-03-07<BR>


<P>[Accepted as a DR at the March, 2024 meeting.]</P>

<P>(See
<A HREF="https://github.com/cplusplus/draft/issues/5337">editorial issue 5337</A>.)</P>

<P>Subclause 9.6.2 [<A href="https://wg21.link/dcl.fct.def.default#1">dcl.fct.def.default</A>] paragraph 1 specifies:</P>

<BLOCKQUOTE>

A function definition whose <I>function-body</I> is of the form <TT>=
default ;</TT> is called an <I>explicitly-defaulted definition</I>.  A
function that is explicitly defaulted shall

<UL>

<LI>be a special member function or a comparison operator function
(12.4.3 [<A href="https://wg21.link/over.binary">over.binary</A>]), and
</LI>

<LI>
not have default arguments.
</LI>

</UL>

</BLOCKQUOTE>

<P>There seem to be no further restrictions on which comparison
operator functions are allowed to be defaulted.  For example,</P>

<PRE>
  enum E { };
  bool operator==(E, E) = default;  // <SPAN CLASS="cmnt">well-formed?</SPAN>
</PRE>

<P>Subclause 11.10.1 [<A href="https://wg21.link/class.compare.default#1">class.compare.default</A>] paragraph 1 applies only to comparison
operator functions "for some class":</P>

<BLOCKQUOTE>

A defaulted comparison operator function (12.4.3 [<A href="https://wg21.link/over.binary">over.binary</A>])
for some class <TT>C</TT> shall be a non-template function that is

<UL>

<LI>a non-static const non-volatile member of C having one parameter of type
<TT>const C&amp;</TT> and either no <I>ref-qualifier</I> or
the <I>ref-qualifier</I> &amp;, or
</LI>

<LI>a friend of <TT>C</TT> having either two parameters of
type <TT>const C&amp;</TT> or two parameters of type <TT>C</TT>.
</LI>

</UL>

</BLOCKQUOTE>

<P><B>Proposed resolution [SUPERSEDED]:</B></P>

<OL>

<LI>Change in 9.6.2 [<A href="https://wg21.link/dcl.fct.def.default#1">dcl.fct.def.default</A>] paragraph 1 as follows:

<BLOCKQUOTE>

A function definition whose <I>function-body</I> is of the form <TT>=
default ;</TT> is called an <I>explicitly-defaulted definition</I>.  A
function that is explicitly defaulted shall

<UL>
<LI>be a special member
function <INS>(11.4.4 [<A href="https://wg21.link/special">special</A>])</INS> or a comparison
operator function (12.4.3 [<A href="https://wg21.link/over.binary">over.binary</A>]<INS>,
11.10.1 [<A href="https://wg21.link/class.compare.default">class.compare.default</A>]</INS>), and
</LI>

<LI>
not have default arguments <INS>(9.3.4.7 [<A href="https://wg21.link/dcl.fct.default">dcl.fct.default</A>])</INS>.
</LI>
</UL>

</BLOCKQUOTE>
</LI>

<LI>Change in 11.10.1 [<A href="https://wg21.link/class.compare.default#1">class.compare.default</A>] paragraph 1 as follows:

<BLOCKQUOTE>

A defaulted comparison operator function (12.4.3 [<A href="https://wg21.link/over.binary">over.binary</A>])
<DEL>for some class <TT>C</TT></DEL> shall be a non-template function that is

<UL>

<LI>a non-static const non-volatile member of <INS>some
class</INS> <TT>C</TT> having one parameter of type
<TT>const C&amp;</TT> and either no <I>ref-qualifier</I> or
the <I>ref-qualifier</I> &amp;, or
</LI>

<LI>a friend of <INS>some class</INS> <TT>C</TT> having either two
parameters of type <TT>const C&amp;</TT> or two parameters of
type <TT>C</TT>.
</LI>

</UL>

<P>
<INS>Such a comparison operator function is termed a comparison
operator function for class <TT>C</TT>.</INS> A comparison operator
function for class <TT>C</TT> that is defaulted on its first
declaration ...</P>

</BLOCKQUOTE>

</LI>

</OL>

<P><B>CWG 2023-12-01</B></P>

<P>A defaulted comparison function for an incomplete class later
declared a friend for that class should be made ill-formed.</P>

<P><B>Proposed resolution (approved by CWG 2023-12-15):</B></P>

<OL>

<LI>Change in 9.6.2 [<A href="https://wg21.link/dcl.fct.def.default#1">dcl.fct.def.default</A>] paragraph 1 as follows:

<BLOCKQUOTE>

A function definition whose <I>function-body</I> is of the form <TT>=
default ;</TT> is called an <I>explicitly-defaulted definition</I>.  A
function that is explicitly defaulted shall

<UL>
<LI>be a special member
function <INS>(11.4.4 [<A href="https://wg21.link/special">special</A>])</INS> or a comparison
operator function (12.4.3 [<A href="https://wg21.link/over.binary">over.binary</A>]<INS>,
11.10.1 [<A href="https://wg21.link/class.compare.default">class.compare.default</A>]</INS>), and
</LI>

<LI>
not have default arguments <INS>(9.3.4.7 [<A href="https://wg21.link/dcl.fct.default">dcl.fct.default</A>])</INS>.
</LI>
</UL>

</BLOCKQUOTE>
</LI>

<LI>
<P>Change in 11.10.1 [<A href="https://wg21.link/class.compare.default#1">class.compare.default</A>] paragraph 1 as follows:</P>

<BLOCKQUOTE>

A defaulted comparison operator function (12.4.3 [<A href="https://wg21.link/over.binary">over.binary</A>])
<DEL>for some class C</DEL> shall be a non-template function that <DEL>is</DEL>
<UL>
<LI>
<INS>is</INS> a non-static member or friend of <INS>some class</INS> C<INS>,</INS>
</LI>
<LI>
<INS>is defined as defaulted in <TT>C</TT> or in a context
where <TT>C</TT> is complete,</INS> and</LI>
<LI>either has two parameters of type const C&amp; or two parameters
of type C, where the implicit object parameter (if any) is considered
to be the first parameter.
</LI>
</UL>
<INS>Such a comparison operator function is termed a defaulted comparison
operator function for class <TT>C</TT>.</INS> Name lookups in the
implicit definition (9.6.2 [<A href="https://wg21.link/dcl.fct.def.default">dcl.fct.def.default</A>]) of a comparison
operator function are performed from a context equivalent to its
function-body.  A definition of a comparison operator as defaulted
that appears in a class shall be the first declaration of that
function. <INS>[ Example:</INS>

<PRE class="ins">
  struct S;
  bool operator==(S, S) = default;  // <SPAN CLASS="cmnt">error: </SPAN>S<SPAN CLASS="cmnt"> is not complete</SPAN>
  struct S {
    friend bool operator==(S, const S&amp;) = default; // <SPAN CLASS="cmnt">error: parameters of different types</SPAN>
  };
  enum E { };
  bool operator==(E, E) = default;  // <SPAN CLASS="cmnt">error: not a member or friend of a class</SPAN>
</PRE>

<INS>-- end example ]</INS>

</BLOCKQUOTE>

</LI>
</OL>

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