From Jason Turner

[diff.cpp17.over]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpdl_ubr1g/{from.md → to.md} +28 -5
tmp/tmpdl_ubr1g/{from.md → to.md} RENAMED
@@ -1,15 +1,16 @@
1
  ### [[over]]: overloading <a id="diff.cpp17.over">[[diff.cpp17.over]]</a>
2
 
3
  **Change:** Equality and inequality expressions can now find reversed
4
  and rewritten candidates. **Rationale:** Improve consistency of equality
5
  with three-way comparison and make it easier to write the full
6
- complement of equality operations. **Effect on original feature:**
7
- Equality and inequality expressions between two objects of different
8
- types, where one is convertible to the other, could invoke a different
9
- operator. Equality and inequality expressions between two objects of the
10
- same type could become ambiguous.
 
11
 
12
  ``` cpp
13
  struct A {
14
  operator int() const;
15
  };
@@ -23,5 +24,27 @@ int check(A x, A y) {
23
  (10 == x) + // calls #1, previously selected #2
24
  (10 != x); // calls #1, previously selected #3
25
  }
26
  ```
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ### [[over]]: overloading <a id="diff.cpp17.over">[[diff.cpp17.over]]</a>
2
 
3
  **Change:** Equality and inequality expressions can now find reversed
4
  and rewritten candidates. **Rationale:** Improve consistency of equality
5
  with three-way comparison and make it easier to write the full
6
+ complement of equality operations. **Effect on original feature:** For
7
+ certain pairs of types where one is convertible to the other, equality
8
+ or inequality expressions between an object of one type and an object of
9
+ the other type invoke a different operator. Also, for certain types,
10
+ equality or inequality expressions between two objects of that type
11
+ become ambiguous. For example:
12
 
13
  ``` cpp
14
  struct A {
15
  operator int() const;
16
  };
 
24
  (10 == x) + // calls #1, previously selected #2
25
  (10 != x); // calls #1, previously selected #3
26
  }
27
  ```
28
 
29
+ **Change:** Overload resolution may change for equality operators
30
+ [[expr.eq]]. **Rationale:** Support calling `operator==` with reversed
31
+ order of arguments. **Effect on original feature:** Valid C++17 code
32
+ that uses equality operators with conversion functions may be ill-formed
33
+ or have different semantics in this revision of C++. For example:
34
+
35
+ ``` cpp
36
+ struct A {
37
+ operator int() const { return 10; }
38
+ };
39
+
40
+ bool operator==(A, int); // #1
41
+ // #2 is built-in candidate: bool operator==(int, int);
42
+ bool b = 10 == A(); // calls #1 with reversed order of arguments; previously selected #2
43
+
44
+ struct B {
45
+ bool operator==(const B&); // member function with no cv-qualifier
46
+ };
47
+ B b1;
48
+ bool eq = (b1 == b1); // ambiguous; previously well-formed
49
+ ```
50
+