Title
Restrictions on operator functions that are explicit object member functions
Status
review
Section
12.4.1 [over.oper.general]
Submitter
Barry Revzin

Created on 2024-08-26.00:00:00 last changed 6 days ago

Messages

Date: 2024-09-27.21:20:46

Proposed resolution:

Change in 12.4.1 [over.oper.general] paragraph 7 as follows, removing the bullets:

An operator function shall either
  • be a member function or
  • be a non-member function that has have at least one non-object parameter or implicit object parameter whose type is a class, a reference to a class, an enumeration, or a reference to an enumeration.
Date: 2024-08-26.00:00:00

(From submission #600.)

With the introduction of explicit object member functions, the restrictions on operator functions became inconsistent. Subclause 12.4.1 [over.oper.general] paragraph 7 specifies:

An operator function shall either
  • be a member function or
  • be a non-member function that has at least one non-object parameter whose type is a class, a reference to a class, an enumeration, or a reference to an enumeration.

Talking about non-object parameters in a bullet discussing non-member functions makes no sense. The following example ought to be prohibited, for consistency with operator==(int, int):

  struct B {
    bool operator==(this int, int);
    operator int() const;
  };
History
Date User Action Args
2024-09-27 21:20:46adminsetstatus: open -> review
2024-08-31 06:23:59adminsetmessages: + msg7812
2024-08-26 00:00:00admincreate