This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115f. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2024-12-06
[Accepted as a DR at the March, 2024 meeting.]
(See editorial issue 5337.)
Subclause 9.5.2 [dcl.fct.def.default] paragraph 1 specifies:
A function definition whose function-body is of the form = default ; is called an explicitly-defaulted definition. A function that is explicitly defaulted shall
- be a special member function or a comparison operator function (12.4.3 [over.binary]), and
- not have default arguments.
There seem to be no further restrictions on which comparison operator functions are allowed to be defaulted. For example,
enum E { };
bool operator==(E, E) = default; // well-formed?
Subclause 11.10.1 [class.compare.default] paragraph 1 applies only to comparison operator functions "for some class":
A defaulted comparison operator function (12.4.3 [over.binary]) for some class C shall be a non-template function that is
- a non-static const non-volatile member of C having one parameter of type const C& and either no ref-qualifier or the ref-qualifier &, or
- a friend of C having either two parameters of type const C& or two parameters of type C.
Proposed resolution [SUPERSEDED]:
A function definition whose function-body is of the form = default ; is called an explicitly-defaulted definition. A function that is explicitly defaulted shall
- be a special member function (11.4.4 [special]) or a comparison operator function (12.4.3 [over.binary], 11.10.1 [class.compare.default]), and
- not have default arguments (9.3.4.7 [dcl.fct.default]).
A defaulted comparison operator function (12.4.3 [over.binary])for some class Cshall be a non-template function that is
- a non-static const non-volatile member of some class C having one parameter of type const C& and either no ref-qualifier or the ref-qualifier &, or
- a friend of some class C having either two parameters of type const C& or two parameters of type C.
Such a comparison operator function is termed a comparison operator function for class C. A comparison operator function for class C that is defaulted on its first declaration ...
CWG 2023-12-01
A defaulted comparison function for an incomplete class later declared a friend for that class should be made ill-formed.
Proposed resolution (approved by CWG 2023-12-15):
A function definition whose function-body is of the form = default ; is called an explicitly-defaulted definition. A function that is explicitly defaulted shall
- be a special member function (11.4.4 [special]) or a comparison operator function (12.4.3 [over.binary], 11.10.1 [class.compare.default]), and
- not have default arguments (9.3.4.7 [dcl.fct.default]).
Change in 11.10.1 [class.compare.default] paragraph 1 as follows:
A defaulted comparison operator function (12.4.3 [over.binary])for some class Cshall be a non-template function thatisSuch a comparison operator function is termed a defaulted comparison operator function for class C. Name lookups in the implicit definition (9.5.2 [dcl.fct.def.default]) 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. [ Example:
- is a non-static member or friend of some class C,
- is defined as defaulted in C or in a context where C is complete, and
- either has two parameters of type const C& or two parameters of type C, where the implicit object parameter (if any) is considered to be the first parameter.
struct S; bool operator==(S, S) = default; // error: S is not complete struct S { friend bool operator==(S, const S&) = default; // error: parameters of different types }; enum E { }; bool operator==(E, E) = default; // error: not a member or friend of a class-- end example ]