Created on 2022-03-07.00:00:00 last changed 4 months ago
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 ]
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 [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 ...
[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.
History | |||
---|---|---|---|
Date | User | Action | Args |
2024-07-20 13:52:34 | admin | set | status: dr -> drwp |
2024-04-05 21:43:46 | admin | set | status: ready -> dr |
2024-03-20 14:10:31 | admin | set | status: tentatively ready -> ready |
2023-12-16 00:18:01 | admin | set | status: review -> tentatively ready |
2023-12-03 16:28:48 | admin | set | messages: + msg7548 |
2023-12-03 16:28:48 | admin | set | messages: + msg7547 |
2023-06-15 19:36:24 | admin | set | status: open -> review |
2022-03-07 00:00:00 | admin | create | |
2022-02-18 07:47:23 | admin | set | messages: + msg6759 |