cplusplus / CWG

Core Working Group
23 stars 7 forks source link

CWG2787 [special] Kind of Explicit Object Assignment Functions #390

Open cor3ntin opened 1 year ago

cor3ntin commented 1 year ago

11.4.4.5 says

Two special member functions are of the same kind if [...] they are both copy or move assignment operators with the same first parameter type and the same cv-qualifiers and ref-qualifier, if any.

This seems to imply that

struct S {
   auto & operator=(this S &, S&&);
   auto & operator=(this S &, const S&);
};

Are of the same kind (and we could presumably constrain one to make the other non-eligible).

We probably want to say instead

Two special member functions are of the same kind if [...] they are both copy or move assignment operators with the same first non-object parameter type and the same cv-qualifiers and ref-qualifier, if any type of their object parameter is the same.

frederick-vs-ja commented 1 year ago

In the following example, #1 and #2 have the same implicit object parameter type S&, but they are not (and perhaps should still be not) of the same kind due to the ref-qualifier.

Perhaps we want #2 and #3 to be of the same kind.

struct S {
  S& operator=(const S&) requires B1;          // #1
  S& operator=(const S&) & requires B2;        // #2
  S& operator=(this S&, const S&) requires B3; // #3
};

Possible resolution:

  • they are both copy or move assignment operators that are implicit object member functions and with the same first non-object parameter type and the same cv-qualifiers ~and ref-qualifier, if any.~, and none of them has ref-qualifier, or
  • they are both copy or move assignment operators with the same first non-object parameter type and the same object parameter parameter type, and none of them is an implicit object member function that has no ref-qualifier.
jensmaurer commented 1 year ago

CWG2787