tmp/tmpc6hncmd7/{from.md → to.md}
RENAMED
|
@@ -4,78 +4,80 @@ 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*
|
| 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
|
| 18 |
-
|
| 19 |
-
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
cannot be overloaded if any of them is a
|
| 25 |
-
template declaration. The types of the
|
| 26 |
-
constructed for the member functions for
|
| 27 |
-
resolution
|
| 28 |
-
parameter-type-lists for enforcement of this
|
| 29 |
-
there is no `static` member function declaration
|
| 30 |
-
function declarations with the same name
|
| 31 |
-
parameter-type-list,
|
| 32 |
-
|
| 33 |
-
parameter.
|
| 34 |
\[*Example 1*:
|
| 35 |
The following illustrates this distinction:
|
| 36 |
``` cpp
|
| 37 |
class X {
|
| 38 |
static void f();
|
| 39 |
-
void f(); //
|
| 40 |
-
void f() const; //
|
| 41 |
-
void f() const volatile; //
|
| 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
|
| 50 |
-
parameter-type-list
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
| 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
|
| 60 |
void i() &;
|
| 61 |
-
void i() const; //
|
| 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
|
|
|
|
| 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
|
| 77 |
\[*Example 3*:
|
| 78 |
``` cpp
|
| 79 |
typedef int Int;
|
| 80 |
|
| 81 |
void f(int i);
|
|
@@ -96,13 +98,13 @@ overloaded:
|
|
| 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
|
| 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*);
|
|
@@ -116,17 +118,17 @@ overloaded:
|
|
| 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
|
| 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)()) { } //
|
| 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
|
|
@@ -162,11 +164,11 @@ overloaded:
|
|
| 162 |
void f (); // OK: overloaded declaration of f
|
| 163 |
|
| 164 |
void prog () {
|
| 165 |
f (1, 2); // OK: call f(int, int)
|
| 166 |
f (1); // OK: call f(int, int)
|
| 167 |
-
f (); //
|
| 168 |
}
|
| 169 |
```
|
| 170 |
|
| 171 |
— *end example*]
|
| 172 |
|
|
|
|
| 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 overloaded.
|
| 18 |
+
- Member function declarations with the same name, the same
|
| 19 |
+
parameter-type-list [[dcl.fct]], and the same trailing
|
| 20 |
+
*requires-clause* (if any) cannot be overloaded if any of them is a
|
| 21 |
+
`static` member function declaration [[class.static]]. Likewise,
|
| 22 |
+
member function template declarations with the same name, the same
|
| 23 |
+
parameter-type-list, the same trailing *requires-clause* (if any), and
|
| 24 |
+
the same *template-head* cannot be overloaded if any of them is a
|
| 25 |
+
`static` member function template declaration. The types of the
|
| 26 |
+
implicit object parameters constructed for the member functions for
|
| 27 |
+
the purpose of overload resolution [[over.match.funcs]] are not
|
| 28 |
+
considered when comparing parameter-type-lists for enforcement of this
|
| 29 |
+
rule. In contrast, if there is no `static` member function declaration
|
| 30 |
+
among a set of member function declarations with the same name, the
|
| 31 |
+
same parameter-type-list, and the same trailing *requires-clause* (if
|
| 32 |
+
any), then these member function declarations can be overloaded if
|
| 33 |
+
they differ in the type of their implicit object parameter.
|
| 34 |
\[*Example 1*:
|
| 35 |
The following illustrates this distinction:
|
| 36 |
``` cpp
|
| 37 |
class X {
|
| 38 |
static void f();
|
| 39 |
+
void f(); // error
|
| 40 |
+
void f() const; // error
|
| 41 |
+
void f() const volatile; // error
|
| 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, the same
|
| 50 |
+
parameter-type-list [[dcl.fct]], and the same trailing
|
| 51 |
+
*requires-clause* (if any), as well as member function template
|
| 52 |
+
declarations with the same name, the same parameter-type-list, the
|
| 53 |
+
same trailing *requires-clause* (if any), and the same
|
| 54 |
+
*template-head*, cannot be overloaded if any of them, but not all,
|
| 55 |
+
have a *ref-qualifier* [[dcl.fct]].
|
| 56 |
\[*Example 2*:
|
| 57 |
``` cpp
|
| 58 |
class Y {
|
| 59 |
void h() &;
|
| 60 |
void h() const &; // OK
|
| 61 |
void h() &&; // OK, all declarations have a ref-qualifier
|
| 62 |
void i() &;
|
| 63 |
+
void i() const; // error: prior declaration of i has a ref-qualifier
|
|
|
|
| 64 |
};
|
| 65 |
```
|
| 66 |
|
| 67 |
— *end example*]
|
| 68 |
|
| 69 |
[*Note 2*:
|
| 70 |
|
| 71 |
As specified in [[dcl.fct]], function declarations that have equivalent
|
| 72 |
+
parameter declarations and *requires-clause*s, if any
|
| 73 |
+
[[temp.constr.decl]], declare the same function and therefore cannot be
|
| 74 |
overloaded:
|
| 75 |
|
| 76 |
- Parameter declarations that differ only in the use of equivalent
|
| 77 |
typedef “types” are equivalent. A `typedef` is not a separate type,
|
| 78 |
+
but only a synonym for another type [[dcl.typedef]].
|
| 79 |
\[*Example 3*:
|
| 80 |
``` cpp
|
| 81 |
typedef int Int;
|
| 82 |
|
| 83 |
void f(int i);
|
|
|
|
| 98 |
```
|
| 99 |
|
| 100 |
— *end example*]
|
| 101 |
- Parameter declarations that differ only in a pointer `*` versus an
|
| 102 |
array `[]` are equivalent. That is, the array declaration is adjusted
|
| 103 |
+
to become a pointer declaration [[dcl.fct]]. Only the second and
|
| 104 |
+
subsequent array dimensions are significant in parameter types
|
| 105 |
+
[[dcl.array]].
|
| 106 |
\[*Example 5*:
|
| 107 |
``` cpp
|
| 108 |
int f(char*);
|
| 109 |
int f(char[]); // same as f(char*);
|
| 110 |
int f(char[7]); // same as f(char*);
|
|
|
|
| 118 |
|
| 119 |
— *end example*]
|
| 120 |
- Parameter declarations that differ only in that one is a function type
|
| 121 |
and the other is a pointer to the same function type are equivalent.
|
| 122 |
That is, the function type is adjusted to become a pointer to function
|
| 123 |
+
type [[dcl.fct]].
|
| 124 |
\[*Example 6*:
|
| 125 |
``` cpp
|
| 126 |
void h(int());
|
| 127 |
void h(int (*)()); // redeclaration of h(int())
|
| 128 |
void h(int x()) { } // definition of h(int())
|
| 129 |
+
void h(int (*x)()) { } // error: redefinition of h(int())
|
| 130 |
```
|
| 131 |
|
| 132 |
— *end example*]
|
| 133 |
- Parameter declarations that differ only in the presence or absence of
|
| 134 |
`const` and/or `volatile` are equivalent. That is, the `const` and
|
|
|
|
| 164 |
void f (); // OK: overloaded declaration of f
|
| 165 |
|
| 166 |
void prog () {
|
| 167 |
f (1, 2); // OK: call f(int, int)
|
| 168 |
f (1); // OK: call f(int, int)
|
| 169 |
+
f (); // error: f(int, int) or f()?
|
| 170 |
}
|
| 171 |
```
|
| 172 |
|
| 173 |
— *end example*]
|
| 174 |
|