From Jason Turner

[over.match.oper]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp4414dl9k/{from.md → to.md} +25 -9
tmp/tmp4414dl9k/{from.md → to.md} RENAMED
@@ -17,13 +17,13 @@ struct String {
17
  };
18
  String operator + (const String&, const String&);
19
 
20
  void f(void) {
21
  const char* p= "one" + "two"; // ill-formed because neither
22
- // operand has user-defined type
23
  int I = 1 + 1; // Always evaluates to 2 even if
24
- // user-defined types exist which
25
  // would perform the operation.
26
  }
27
  ```
28
 
29
  If either operand has a type that is a class or an enumeration, a
@@ -54,13 +54,14 @@ version is `T1`, and for a binary operator `@` with a left operand of a
54
  type whose cv-unqualified version is `T1` and a right operand of a type
55
  whose cv-unqualified version is `T2`, three sets of candidate functions,
56
  designated *member candidates*, *non-member candidates* and *built-in
57
  candidates*, are constructed as follows:
58
 
59
- - If `T1` is a complete class type, the set of member candidates is the
60
- result of the qualified lookup of `T1::operator@` (
61
- [[over.call.func]]); otherwise, the set of member candidates is empty.
 
62
  - The set of non-member candidates is the result of the unqualified
63
  lookup of `operator@` in the context of the expression according to
64
  the usual rules for name lookup in unqualified function calls (
65
  [[basic.lookup.argdep]]) except that all member functions are ignored.
66
  However, if no operand has a class type, only those non-member
@@ -75,12 +76,12 @@ candidates*, are constructed as follows:
75
  defined in  [[over.built]] that, compared to the given operator,
76
  - have the same operator name, and
77
  - accept the same number of operands, and
78
  - accept operand types to which the given operand or operands can be
79
  converted according to [[over.best.ics]], and
80
- - do not have the same parameter-type-list as any non-template
81
- non-member candidate.
82
 
83
  For the built-in assignment operators, conversions of the left operand
84
  are restricted as follows:
85
 
86
  - no temporaries are introduced to hold the left operand, and
@@ -106,15 +107,30 @@ void m() {
106
  a + b; // operator+(a,b) chosen over int(a) + int(b)
107
  }
108
  ```
109
 
110
  If a built-in candidate is selected by overload resolution, the operands
111
- are converted to the types of the corresponding parameters of the
112
- selected operation function. Then the operator is treated as the
 
 
113
  corresponding built-in operator and interpreted according to Clause 
114
  [[expr]].
115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  The second operand of operator `->` is ignored in selecting an
117
  `operator->` function, and is not an argument when the `operator->`
118
  function is called. When `operator->` returns, the operator `->` is
119
  applied to the value returned, with the original second operand.[^7]
120
 
 
17
  };
18
  String operator + (const String&, const String&);
19
 
20
  void f(void) {
21
  const char* p= "one" + "two"; // ill-formed because neither
22
+ // operand has class or enumeration type
23
  int I = 1 + 1; // Always evaluates to 2 even if
24
+ // class or enumeration types exist that
25
  // would perform the operation.
26
  }
27
  ```
28
 
29
  If either operand has a type that is a class or an enumeration, a
 
54
  type whose cv-unqualified version is `T1` and a right operand of a type
55
  whose cv-unqualified version is `T2`, three sets of candidate functions,
56
  designated *member candidates*, *non-member candidates* and *built-in
57
  candidates*, are constructed as follows:
58
 
59
+ - If `T1` is a complete class type or a class currently being defined,
60
+ the set of member candidates is the result of the qualified lookup of
61
+ `T1::operator@` ([[over.call.func]]); otherwise, the set of member
62
+ candidates is empty.
63
  - The set of non-member candidates is the result of the unqualified
64
  lookup of `operator@` in the context of the expression according to
65
  the usual rules for name lookup in unqualified function calls (
66
  [[basic.lookup.argdep]]) except that all member functions are ignored.
67
  However, if no operand has a class type, only those non-member
 
76
  defined in  [[over.built]] that, compared to the given operator,
77
  - have the same operator name, and
78
  - accept the same number of operands, and
79
  - accept operand types to which the given operand or operands can be
80
  converted according to [[over.best.ics]], and
81
+ - do not have the same parameter-type-list as any non-member candidate
82
+ that is not a function template specialization.
83
 
84
  For the built-in assignment operators, conversions of the left operand
85
  are restricted as follows:
86
 
87
  - no temporaries are introduced to hold the left operand, and
 
107
  a + b; // operator+(a,b) chosen over int(a) + int(b)
108
  }
109
  ```
110
 
111
  If a built-in candidate is selected by overload resolution, the operands
112
+ of class type are converted to the types of the corresponding parameters
113
+ of the selected operation function, except that the second standard
114
+ conversion sequence of a user-defined conversion sequence (
115
+ [[over.ics.user]]) is not applied. Then the operator is treated as the
116
  corresponding built-in operator and interpreted according to Clause 
117
  [[expr]].
118
 
119
+ ``` cpp
120
+ struct X {
121
+ operator double();
122
+ };
123
+
124
+ struct Y {
125
+ operator int*();
126
+ };
127
+
128
+ int *a = Y() + 100.0; // error: pointer arithmetic requires integral operand
129
+ int *b = Y() + X(); // error: pointer arithmetic requires integral operand
130
+ ```
131
+
132
  The second operand of operator `->` is ignored in selecting an
133
  `operator->` function, and is not an argument when the `operator->`
134
  function is called. When `operator->` returns, the operator `->` is
135
  applied to the value returned, with the original second operand.[^7]
136