2.4 KiB
[diff.cpp17.over]
Annex C (informative) Compatibility [diff]
C.3 C++ and ISO C++ 2017 [diff.cpp17]
C.3.7 [over]: overloading [diff.cpp17.over]
Affected subclause: [over.match.oper]
Change: Equality and inequality expressions can now find reversed and rewritten candidates.
Rationale: Improve consistency of equality with three-way comparison and make it easier to write the full complement of equality operations.
Effect on original feature: For certain pairs of types where one is convertible to the other, equality or inequality expressions between an object of one type and an object of the other type invoke a different operator.
Also, for certain types, equality or inequality expressions between two objects of that type become ambiguous.
[Example 1: struct A {operator int() const;};
bool operator==(A, int); // #1// #2 is built-in candidate: bool operator==(int, int);// #3 is built-in candidate: bool operator!=(int, int);int check(A x, A y) {return (x == y) + // ill-formed; previously well-formed(10 == x) + // calls #1, previously selected #2(10 != x); // calls #1, previously selected #3} â end example]
Affected subclause: [over.match.oper]
Change: Overload resolution may change for equality operators ([expr.eq]).
Rationale: Support calling operator== with reversed order of arguments.
Effect on original feature: Valid C++ 2017 code that uses equality operators with conversion functions may be ill-formed or have different semantics in this revision of C++.
[Example 2: struct A {operator int() const { return 10; }};
bool operator==(A, int); // #1// #2 is built-in candidate: bool operator==(int, int);bool b = 10 == A(); // calls #1 with reversed order of arguments; previously selected #2struct B {bool operator==(const B&); // member function with no cv-qualifier}; B b1;bool eq = (b1 == b1); // ambiguous; previously well-formed â end example]