From Jason Turner

[over.load]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp08xrpdrg/{from.md → to.md} +60 -29
tmp/tmp08xrpdrg/{from.md → to.md} RENAMED
@@ -1,35 +1,40 @@
1
  ## Overloadable declarations <a id="over.load">[[over.load]]</a>
2
 
3
  Not all function declarations can be overloaded. Those that cannot be
4
  overloaded are specified here. A program is ill-formed if it contains
5
- two such non-overloadable declarations in the same scope. This
6
- restriction applies to explicit declarations in a scope, and between
7
- such declarations and declarations made through a *using-declaration* (
8
- [[namespace.udecl]]). It does not apply to sets of functions fabricated
9
- as a result of name lookup (e.g., because of *using-directive*s) or
10
- overload resolution (e.g., for operator functions).
 
 
11
 
12
  Certain function declarations cannot be overloaded:
13
 
14
- - Function declarations that differ only in the return type cannot be
 
15
  overloaded.
16
  - Member function declarations with the same name and the same
17
- *parameter-type-list* cannot be overloaded if any of them is a
18
- `static` member function declaration ([[class.static]]). Likewise,
19
- member function template declarations with the same name, the same
20
- *parameter-type-list*, and the same template parameter lists cannot be
21
- overloaded if any of them is a `static` member function template
22
- declaration. The types of the implicit object parameters constructed
23
- for the member functions for the purpose of overload resolution (
24
- [[over.match.funcs]]) are not considered when comparing
25
  parameter-type-lists for enforcement of this rule. In contrast, if
26
  there is no `static` member function declaration among a set of member
27
  function declarations with the same name and the same
28
  parameter-type-list, then these member function declarations can be
29
  overloaded if they differ in the type of their implicit object
30
- parameter. the following illustrates this distinction:
 
 
31
  ``` cpp
32
  class X {
33
  static void f();
34
  void f(); // ill-formed
35
  void f() const; // ill-formed
@@ -37,15 +42,18 @@ Certain function declarations cannot be overloaded:
37
  void g();
38
  void g() const; // OK: no static g
39
  void g() const volatile; // OK: no static g
40
  };
41
  ```
 
 
42
  - Member function declarations with the same name and the same
43
- *parameter-type-list* as well as member function template declarations
44
- with the same name, the same *parameter-type-list*, and the same
45
- template parameter lists cannot be overloaded if any of them, but not
46
- all, have a *ref-qualifier* ([[dcl.fct]]).
 
47
  ``` cpp
48
  class Y {
49
  void h() &;
50
  void h() const &; // OK
51
  void h() &&; // OK, all declarations have a ref-qualifier
@@ -53,39 +61,49 @@ Certain function declarations cannot be overloaded:
53
  void i() const; // ill-formed, prior declaration of i
54
  // has a ref-qualifier
55
  };
56
  ```
57
 
 
 
 
 
58
  As specified in  [[dcl.fct]], function declarations that have equivalent
59
  parameter declarations declare the same function and therefore cannot be
60
  overloaded:
61
 
62
  - Parameter declarations that differ only in the use of equivalent
63
  typedef “types” are equivalent. A `typedef` is not a separate type,
64
  but only a synonym for another type ([[dcl.typedef]]).
 
65
  ``` cpp
66
  typedef int Int;
67
 
68
  void f(int i);
69
  void f(Int i); // OK: redeclaration of f(int)
70
- void f(int i) { /* ... */ }
71
- void f(Int i) { /* ... */ } // error: redefinition of f(int)
72
  ```
73
 
 
74
  Enumerations, on the other hand, are distinct types and can be used to
75
  distinguish overloaded function declarations.
 
76
  ``` cpp
77
  enum E { a };
78
 
79
- void f(int i) { /* ... */ }
80
- void f(E i) { /* ... */ }
81
  ```
 
 
82
  - Parameter declarations that differ only in a pointer `*` versus an
83
  array `[]` are equivalent. That is, the array declaration is adjusted
84
  to become a pointer declaration ([[dcl.fct]]). Only the second and
85
  subsequent array dimensions are significant in parameter types (
86
  [[dcl.array]]).
 
87
  ``` cpp
88
  int f(char*);
89
  int f(char[]); // same as f(char*);
90
  int f(char[7]); // same as f(char*);
91
  int f(char[9]); // same as f(char*);
@@ -93,43 +111,52 @@ overloaded:
93
  int g(char(*)[10]);
94
  int g(char[5][10]); // same as g(char(*)[10]);
95
  int g(char[7][10]); // same as g(char(*)[10]);
96
  int g(char(*)[20]); // different from g(char(*)[10]);
97
  ```
 
 
98
  - Parameter declarations that differ only in that one is a function type
99
  and the other is a pointer to the same function type are equivalent.
100
  That is, the function type is adjusted to become a pointer to function
101
  type ([[dcl.fct]]).
 
102
  ``` cpp
103
  void h(int());
104
  void h(int (*)()); // redeclaration of h(int())
105
  void h(int x()) { } // definition of h(int())
106
  void h(int (*x)()) { } // ill-formed: redefinition of h(int())
107
  ```
 
 
108
  - Parameter declarations that differ only in the presence or absence of
109
  `const` and/or `volatile` are equivalent. That is, the `const` and
110
  `volatile` type-specifiers for each parameter type are ignored when
111
  determining which function is being declared, defined, or called.
 
112
  ``` cpp
113
  typedef const int cInt;
114
 
115
  int f (int);
116
  int f (const int); // redeclaration of f(int)
117
- int f (int) { /* ... */ } // definition of f(int)
118
- int f (cInt) { /* ... */ } // error: redefinition of f(int)
119
  ```
120
 
 
121
  Only the `const` and `volatile` type-specifiers at the outermost level
122
  of the parameter type specification are ignored in this fashion;
123
  `const` and `volatile` type-specifiers buried within a parameter type
124
  specification are significant and can be used to distinguish
125
  overloaded function declarations.[^1] In particular, for any type `T`,
126
- “pointer to `T`,” “pointer to `const` `T`,” and “pointer to `volatile`
127
  `T`” are considered distinct parameter types, as are “reference to
128
- `T`,” “reference to `const` `T`,” and “reference to `volatile` `T`.
129
  - Two parameter declarations that differ only in their default arguments
130
- are equivalent. consider the following:
 
 
131
  ``` cpp
132
  void f (int i, int j);
133
  void f (int i, int j = 99); // OK: redeclaration of f(int, int)
134
  void f (int i = 88, int j); // OK: redeclaration of f(int, int)
135
  void f (); // OK: overloaded declaration of f
@@ -139,5 +166,9 @@ overloaded:
139
  f (1); // OK: call f(int, int)
140
  f (); // Error: f(int, int) or f()?
141
  }
142
  ```
143
 
 
 
 
 
 
1
  ## Overloadable declarations <a id="over.load">[[over.load]]</a>
2
 
3
  Not all function declarations can be overloaded. Those that cannot be
4
  overloaded are specified here. A program is ill-formed if it contains
5
+ two such non-overloadable declarations in the same scope.
6
+
7
+ [*Note 1*: This restriction applies to explicit declarations in a
8
+ scope, and between such declarations and declarations made through a
9
+ *using-declaration* ([[namespace.udecl]]). It does not apply to sets of
10
+ functions fabricated as a result of name lookup (e.g., because of
11
+ *using-directive*s) or overload resolution (e.g., for operator
12
+ functions). — *end note*]
13
 
14
  Certain function declarations cannot be overloaded:
15
 
16
+ - Function declarations that differ only in the return type, the
17
+ exception specification ([[except.spec]]), or both cannot be
18
  overloaded.
19
  - Member function declarations with the same name and the same
20
+ parameter-type-list ([[dcl.fct]]) cannot be overloaded if any of them
21
+ is a `static` member function declaration ([[class.static]]).
22
+ Likewise, member function template declarations with the same name,
23
+ the same parameter-type-list, and the same template parameter lists
24
+ cannot be overloaded if any of them is a `static` member function
25
+ template declaration. The types of the implicit object parameters
26
+ constructed for the member functions for the purpose of overload
27
+ resolution ([[over.match.funcs]]) are not considered when comparing
28
  parameter-type-lists for enforcement of this rule. In contrast, if
29
  there is no `static` member function declaration among a set of member
30
  function declarations with the same name and the same
31
  parameter-type-list, then these member function declarations can be
32
  overloaded if they differ in the type of their implicit object
33
+ parameter.
34
+ \[*Example 1*:
35
+ The following illustrates this distinction:
36
  ``` cpp
37
  class X {
38
  static void f();
39
  void f(); // ill-formed
40
  void f() const; // ill-formed
 
42
  void g();
43
  void g() const; // OK: no static g
44
  void g() const volatile; // OK: no static g
45
  };
46
  ```
47
+
48
+ — *end example*]
49
  - Member function declarations with the same name and the same
50
+ parameter-type-list ([[dcl.fct]]) as well as member function template
51
+ declarations with the same name, the same parameter-type-list, and the
52
+ same template parameter lists cannot be overloaded if any of them, but
53
+ not all, have a *ref-qualifier* ([[dcl.fct]]).
54
+ \[*Example 2*:
55
  ``` cpp
56
  class Y {
57
  void h() &;
58
  void h() const &; // OK
59
  void h() &&; // OK, all declarations have a ref-qualifier
 
61
  void i() const; // ill-formed, prior declaration of i
62
  // has a ref-qualifier
63
  };
64
  ```
65
 
66
+ — *end example*]
67
+
68
+ [*Note 2*:
69
+
70
  As specified in  [[dcl.fct]], function declarations that have equivalent
71
  parameter declarations declare the same function and therefore cannot be
72
  overloaded:
73
 
74
  - Parameter declarations that differ only in the use of equivalent
75
  typedef “types” are equivalent. A `typedef` is not a separate type,
76
  but only a synonym for another type ([[dcl.typedef]]).
77
+ \[*Example 3*:
78
  ``` cpp
79
  typedef int Int;
80
 
81
  void f(int i);
82
  void f(Int i); // OK: redeclaration of f(int)
83
+ void f(int i) { ... }
84
+ void f(Int i) { ... } // error: redefinition of f(int)
85
  ```
86
 
87
+ — *end example*]
88
  Enumerations, on the other hand, are distinct types and can be used to
89
  distinguish overloaded function declarations.
90
+ \[*Example 4*:
91
  ``` cpp
92
  enum E { a };
93
 
94
+ void f(int i) { ... }
95
+ void f(E i) { ... }
96
  ```
97
+
98
+ — *end example*]
99
  - Parameter declarations that differ only in a pointer `*` versus an
100
  array `[]` are equivalent. That is, the array declaration is adjusted
101
  to become a pointer declaration ([[dcl.fct]]). Only the second and
102
  subsequent array dimensions are significant in parameter types (
103
  [[dcl.array]]).
104
+ \[*Example 5*:
105
  ``` cpp
106
  int f(char*);
107
  int f(char[]); // same as f(char*);
108
  int f(char[7]); // same as f(char*);
109
  int f(char[9]); // same as f(char*);
 
111
  int g(char(*)[10]);
112
  int g(char[5][10]); // same as g(char(*)[10]);
113
  int g(char[7][10]); // same as g(char(*)[10]);
114
  int g(char(*)[20]); // different from g(char(*)[10]);
115
  ```
116
+
117
+ — *end example*]
118
  - Parameter declarations that differ only in that one is a function type
119
  and the other is a pointer to the same function type are equivalent.
120
  That is, the function type is adjusted to become a pointer to function
121
  type ([[dcl.fct]]).
122
+ \[*Example 6*:
123
  ``` cpp
124
  void h(int());
125
  void h(int (*)()); // redeclaration of h(int())
126
  void h(int x()) { } // definition of h(int())
127
  void h(int (*x)()) { } // ill-formed: redefinition of h(int())
128
  ```
129
+
130
+ — *end example*]
131
  - Parameter declarations that differ only in the presence or absence of
132
  `const` and/or `volatile` are equivalent. That is, the `const` and
133
  `volatile` type-specifiers for each parameter type are ignored when
134
  determining which function is being declared, defined, or called.
135
+ \[*Example 7*:
136
  ``` cpp
137
  typedef const int cInt;
138
 
139
  int f (int);
140
  int f (const int); // redeclaration of f(int)
141
+ int f (int) { ... } // definition of f(int)
142
+ int f (cInt) { ... } // error: redefinition of f(int)
143
  ```
144
 
145
+ — *end example*]
146
  Only the `const` and `volatile` type-specifiers at the outermost level
147
  of the parameter type specification are ignored in this fashion;
148
  `const` and `volatile` type-specifiers buried within a parameter type
149
  specification are significant and can be used to distinguish
150
  overloaded function declarations.[^1] In particular, for any type `T`,
151
+ “pointer to `T`”, “pointer to `const` `T`”, and “pointer to `volatile`
152
  `T`” are considered distinct parameter types, as are “reference to
153
+ `T`”, “reference to `const` `T`”, and “reference to `volatile` `T`”.
154
  - Two parameter declarations that differ only in their default arguments
155
+ are equivalent.
156
+ \[*Example 8*:
157
+ Consider the following:
158
  ``` cpp
159
  void f (int i, int j);
160
  void f (int i, int j = 99); // OK: redeclaration of f(int, int)
161
  void f (int i = 88, int j); // OK: redeclaration of f(int, int)
162
  void f (); // OK: overloaded declaration of f
 
166
  f (1); // OK: call f(int, int)
167
  f (); // Error: f(int, int) or f()?
168
  }
169
  ```
170
 
171
+ — *end example*]
172
+
173
+ — *end note*]
174
+