Skip to content

Commit 5cd87e2

Browse files
burblebeetkoeppe
authored andcommitted
CWG2547 Defaulted comparison operator function for non-classes
1 parent eef4c2b commit 5cd87e2

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

‎source/classes.tex‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6400,12 +6400,15 @@
64006400

64016401
\pnum
64026402
A defaulted comparison operator function\iref{over.binary}
6403-
for some class \tcode{C}
64046403
shall be a non-template function
6405-
that is
6404+
that
64066405
\begin{itemize}
64076406
\item
6408-
a non-static member or friend of \tcode{C} and
6407+
is a non-static member or friend of some class \tcode{C},
6408+
6409+
\item
6410+
is defined as defaulted in \tcode{C} or in
6411+
a context where \tcode{C} is complete, and
64096412

64106413
\item
64116414
either has
@@ -6414,13 +6417,27 @@
64146417
where the implicit object parameter (if any) is considered to be
64156418
the first parameter.
64166419
\end{itemize}
6420+
Such a comparison operator function is termed
6421+
\indextext{operator!defaulted comparison operator function}%
6422+
a defaulted comparison operator function for class \tcode{C}.
64176423
Name lookups in the implicit definition\iref{dcl.fct.def.default}
64186424
of a comparison operator function
64196425
are performed from a context equivalent to
64206426
its \grammarterm{function-body}.
64216427
A definition of a comparison operator as
64226428
defaulted that appears in a class shall be the first declaration
64236429
of that function.
6430+
\begin{example}
6431+
\begin{codeblock}
6432+
struct S;
6433+
bool operator==(S, S) = default; // error: \tcode{S} is not complete
6434+
struct S {
6435+
friend bool operator==(S, const S&) = default; // error: parameters of different types
6436+
};
6437+
enum E { };
6438+
bool operator==(E, E) = default; // error: not a member or friend of a class
6439+
\end{codeblock}
6440+
\end{example}
64246441

64256442
\pnum
64266443
A defaulted \tcode{<=>} or \tcode{==} operator function for class \tcode{C}

‎source/declarations.tex‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6403,9 +6403,9 @@
64036403
is called an \defnx{explicitly-defaulted}{definition!function!explicitly-defaulted} definition.
64046404
A function that is explicitly defaulted shall
64056405
\begin{itemize}
6406-
\item be a special member function or
6407-
a comparison operator function\iref{over.binary}, and
6408-
\item not have default arguments.
6406+
\item be a special member function\iref{special} or
6407+
a comparison operator function\iref{over.binary, class.compare.default}, and
6408+
\item not have default arguments\iref{dcl.fct.default}.
64096409
\end{itemize}
64106410

64116411
\pnum

0 commit comments

Comments
 (0)