tmp/tmpr6ddbi34/{from.md → to.md}
RENAMED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
#### Ranking implicit conversion sequences <a id="over.ics.rank">[[over.ics.rank]]</a>
|
| 2 |
|
| 3 |
-
|
| 4 |
sequences based on the relationships *better conversion sequence* and
|
| 5 |
*better conversion*. If an implicit conversion sequence S1 is defined by
|
| 6 |
these rules to be a better conversion sequence than S2, then it is also
|
| 7 |
the case that S2 is a *worse conversion sequence* than S1. If conversion
|
| 8 |
sequence S1 is neither better than nor worse than conversion sequence
|
|
@@ -19,10 +19,31 @@ defined in [[over.best.ics]])
|
|
| 19 |
[[over.ics.ellipsis]]).
|
| 20 |
|
| 21 |
Two implicit conversion sequences of the same form are indistinguishable
|
| 22 |
conversion sequences unless one of the following rules applies:
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
- Standard conversion sequence `S1` is a better conversion sequence than
|
| 25 |
standard conversion sequence `S2` if
|
| 26 |
- `S1` is a proper subsequence of `S2` (comparing the conversion
|
| 27 |
sequences in the canonical form defined by [[over.ics.scs]],
|
| 28 |
excluding any Lvalue Transformation; the identity conversion
|
|
@@ -32,11 +53,12 @@ conversion sequences unless one of the following rules applies:
|
|
| 32 |
have the same rank and are distinguishable by the rules in the
|
| 33 |
paragraph below, or, if not that,
|
| 34 |
- `S1` and `S2` are reference bindings ([[dcl.init.ref]]) and neither
|
| 35 |
refers to an implicit object parameter of a non-static member
|
| 36 |
function declared without a *ref-qualifier*, and `S1` binds an
|
| 37 |
-
rvalue reference to an rvalue and `S2` binds an lvalue reference
|
|
|
|
| 38 |
``` cpp
|
| 39 |
int i;
|
| 40 |
int f1();
|
| 41 |
int&& f2();
|
| 42 |
int g(const int&);
|
|
@@ -58,41 +80,47 @@ conversion sequences unless one of the following rules applies:
|
|
| 58 |
a << 'c'; // calls A::operator<<(int)
|
| 59 |
A().p(); // calls A::p()&&
|
| 60 |
a.p(); // calls A::p()&
|
| 61 |
```
|
| 62 |
|
|
|
|
| 63 |
or, if not that,
|
| 64 |
- `S1` and `S2` are reference bindings ([[dcl.init.ref]]) and `S1`
|
| 65 |
binds an lvalue reference to a function lvalue and `S2` binds an
|
| 66 |
-
rvalue reference to a function lvalue
|
|
|
|
| 67 |
``` cpp
|
| 68 |
int f(void(&)()); // #1
|
| 69 |
int f(void(&&)()); // #2
|
| 70 |
void g();
|
| 71 |
int i1 = f(g); // calls #1
|
| 72 |
```
|
| 73 |
|
|
|
|
| 74 |
or, if not that,
|
| 75 |
- `S1`
|
| 76 |
and `S2` differ only in their qualification conversion and yield
|
| 77 |
similar types `T1` and `T2` ([[conv.qual]]), respectively, and the
|
| 78 |
cv-qualification signature of type `T1` is a proper subset of the
|
| 79 |
-
cv-qualification signature of type `T2`
|
|
|
|
| 80 |
``` cpp
|
| 81 |
int f(const volatile int *);
|
| 82 |
int f(const int *);
|
| 83 |
int i;
|
| 84 |
int j = f(&i); // calls f(const int*)
|
| 85 |
```
|
| 86 |
|
|
|
|
| 87 |
or, if not that,
|
| 88 |
- `S1`
|
| 89 |
and `S2` are reference bindings ([[dcl.init.ref]]), and the types
|
| 90 |
to which the references refer are the same type except for top-level
|
| 91 |
cv-qualifiers, and the type to which the reference initialized by
|
| 92 |
`S2` refers is more cv-qualified than the type to which the
|
| 93 |
reference initialized by `S1` refers.
|
|
|
|
| 94 |
``` cpp
|
| 95 |
int f(const int &);
|
| 96 |
int f(int &);
|
| 97 |
int g(const int &);
|
| 98 |
int g(int);
|
|
@@ -108,31 +136,30 @@ conversion sequences unless one of the following rules applies:
|
|
| 108 |
void g(const X& a, X b) {
|
| 109 |
a.f(); // calls X::f() const
|
| 110 |
b.f(); // calls X::f()
|
| 111 |
}
|
| 112 |
```
|
|
|
|
|
|
|
| 113 |
- User-defined conversion sequence `U1` is a better conversion sequence
|
| 114 |
than another user-defined conversion sequence `U2` if they contain the
|
| 115 |
same user-defined conversion function or constructor or they
|
| 116 |
initialize the same class in an aggregate initialization and in either
|
| 117 |
case the second standard conversion sequence of `U1` is better than
|
| 118 |
the second standard conversion sequence of `U2`.
|
|
|
|
| 119 |
``` cpp
|
| 120 |
struct A {
|
| 121 |
operator short();
|
| 122 |
} a;
|
| 123 |
int f(int);
|
| 124 |
int f(float);
|
| 125 |
int i = f(a); // calls f(int), because short → int is
|
| 126 |
// better than short → float.
|
| 127 |
```
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
- `L1` converts to `std::initializer_list<X>` for some `X` and `L2`
|
| 131 |
-
does not, or, if not that,
|
| 132 |
-
- `L1` converts to type “array of `N1` `T`”, `L2` converts to type
|
| 133 |
-
“array of `N2` `T`”, and `N1` is smaller than `N2`.
|
| 134 |
|
| 135 |
Standard conversion sequences are ordered by their ranks: an Exact Match
|
| 136 |
is a better conversion than a Promotion, which is a better conversion
|
| 137 |
than a Conversion. Two conversion sequences with the same rank are
|
| 138 |
indistinguishable unless one of the following rules applies:
|
|
@@ -148,19 +175,22 @@ indistinguishable unless one of the following rules applies:
|
|
| 148 |
of `B*` to `void*`.
|
| 149 |
- If class `B` is derived directly or indirectly from class `A` and
|
| 150 |
class `C` is derived directly or indirectly from `B`,
|
| 151 |
- conversion of `C*` to `B*` is better than conversion of `C*` to
|
| 152 |
`A*`,
|
|
|
|
| 153 |
``` cpp
|
| 154 |
struct A {};
|
| 155 |
struct B : public A {};
|
| 156 |
struct C : public B {};
|
| 157 |
C* pc;
|
| 158 |
int f(A*);
|
| 159 |
int f(B*);
|
| 160 |
int i = f(pc); // calls f(B*)
|
| 161 |
```
|
|
|
|
|
|
|
| 162 |
- binding of an expression of type `C` to a reference to type `B` is
|
| 163 |
better than binding an expression of type `C` to a reference to type
|
| 164 |
`A`,
|
| 165 |
- conversion of `A::*` to `B::*` is better than conversion of `A::*`
|
| 166 |
to `C::*`,
|
|
@@ -172,11 +202,11 @@ indistinguishable unless one of the following rules applies:
|
|
| 172 |
`A`,
|
| 173 |
- conversion of `B::*` to `C::*` is better than conversion of `A::*`
|
| 174 |
to `C::*`, and
|
| 175 |
- conversion of `B` to `A` is better than conversion of `C` to `A`.
|
| 176 |
|
| 177 |
-
Compared conversion sequences will have different source
|
| 178 |
-
the context of comparing the second standard conversion
|
| 179 |
-
initialization by user-defined conversion (see
|
| 180 |
-
in all other contexts, the source types will be
|
| 181 |
-
target types will be different.
|
| 182 |
|
|
|
|
| 1 |
#### Ranking implicit conversion sequences <a id="over.ics.rank">[[over.ics.rank]]</a>
|
| 2 |
|
| 3 |
+
This subclause defines a partial ordering of implicit conversion
|
| 4 |
sequences based on the relationships *better conversion sequence* and
|
| 5 |
*better conversion*. If an implicit conversion sequence S1 is defined by
|
| 6 |
these rules to be a better conversion sequence than S2, then it is also
|
| 7 |
the case that S2 is a *worse conversion sequence* than S1. If conversion
|
| 8 |
sequence S1 is neither better than nor worse than conversion sequence
|
|
|
|
| 19 |
[[over.ics.ellipsis]]).
|
| 20 |
|
| 21 |
Two implicit conversion sequences of the same form are indistinguishable
|
| 22 |
conversion sequences unless one of the following rules applies:
|
| 23 |
|
| 24 |
+
- List-initialization sequence `L1` is a better conversion sequence than
|
| 25 |
+
list-initialization sequence `L2` if
|
| 26 |
+
- `L1` converts to `std::initializer_list<X>` for some `X` and `L2`
|
| 27 |
+
does not, or, if not that,
|
| 28 |
+
- `L1` converts to type “array of `N1` `T`”, `L2` converts to type
|
| 29 |
+
“array of `N2` `T`”, and `N1` is smaller than `N2`,
|
| 30 |
+
|
| 31 |
+
even if one of the other rules in this paragraph would otherwise
|
| 32 |
+
apply.
|
| 33 |
+
\[*Example 1*:
|
| 34 |
+
``` cpp
|
| 35 |
+
void f1(int); // #1
|
| 36 |
+
void f1(std::initializer_list<long>); // #2
|
| 37 |
+
void g1() { f1({42}); } // chooses #2
|
| 38 |
+
|
| 39 |
+
void f2(std::pair<const char*, const char*>); // #3
|
| 40 |
+
void f2(std::initializer_list<std::string>); // #4
|
| 41 |
+
void g2() { f2({"foo","bar"}); } // chooses #4
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
— *end example*]
|
| 45 |
- Standard conversion sequence `S1` is a better conversion sequence than
|
| 46 |
standard conversion sequence `S2` if
|
| 47 |
- `S1` is a proper subsequence of `S2` (comparing the conversion
|
| 48 |
sequences in the canonical form defined by [[over.ics.scs]],
|
| 49 |
excluding any Lvalue Transformation; the identity conversion
|
|
|
|
| 53 |
have the same rank and are distinguishable by the rules in the
|
| 54 |
paragraph below, or, if not that,
|
| 55 |
- `S1` and `S2` are reference bindings ([[dcl.init.ref]]) and neither
|
| 56 |
refers to an implicit object parameter of a non-static member
|
| 57 |
function declared without a *ref-qualifier*, and `S1` binds an
|
| 58 |
+
rvalue reference to an rvalue and `S2` binds an lvalue reference
|
| 59 |
+
\[*Example 2*:
|
| 60 |
``` cpp
|
| 61 |
int i;
|
| 62 |
int f1();
|
| 63 |
int&& f2();
|
| 64 |
int g(const int&);
|
|
|
|
| 80 |
a << 'c'; // calls A::operator<<(int)
|
| 81 |
A().p(); // calls A::p()&&
|
| 82 |
a.p(); // calls A::p()&
|
| 83 |
```
|
| 84 |
|
| 85 |
+
— *end example*]
|
| 86 |
or, if not that,
|
| 87 |
- `S1` and `S2` are reference bindings ([[dcl.init.ref]]) and `S1`
|
| 88 |
binds an lvalue reference to a function lvalue and `S2` binds an
|
| 89 |
+
rvalue reference to a function lvalue
|
| 90 |
+
\[*Example 3*:
|
| 91 |
``` cpp
|
| 92 |
int f(void(&)()); // #1
|
| 93 |
int f(void(&&)()); // #2
|
| 94 |
void g();
|
| 95 |
int i1 = f(g); // calls #1
|
| 96 |
```
|
| 97 |
|
| 98 |
+
— *end example*]
|
| 99 |
or, if not that,
|
| 100 |
- `S1`
|
| 101 |
and `S2` differ only in their qualification conversion and yield
|
| 102 |
similar types `T1` and `T2` ([[conv.qual]]), respectively, and the
|
| 103 |
cv-qualification signature of type `T1` is a proper subset of the
|
| 104 |
+
cv-qualification signature of type `T2`
|
| 105 |
+
\[*Example 4*:
|
| 106 |
``` cpp
|
| 107 |
int f(const volatile int *);
|
| 108 |
int f(const int *);
|
| 109 |
int i;
|
| 110 |
int j = f(&i); // calls f(const int*)
|
| 111 |
```
|
| 112 |
|
| 113 |
+
— *end example*]
|
| 114 |
or, if not that,
|
| 115 |
- `S1`
|
| 116 |
and `S2` are reference bindings ([[dcl.init.ref]]), and the types
|
| 117 |
to which the references refer are the same type except for top-level
|
| 118 |
cv-qualifiers, and the type to which the reference initialized by
|
| 119 |
`S2` refers is more cv-qualified than the type to which the
|
| 120 |
reference initialized by `S1` refers.
|
| 121 |
+
\[*Example 5*:
|
| 122 |
``` cpp
|
| 123 |
int f(const int &);
|
| 124 |
int f(int &);
|
| 125 |
int g(const int &);
|
| 126 |
int g(int);
|
|
|
|
| 136 |
void g(const X& a, X b) {
|
| 137 |
a.f(); // calls X::f() const
|
| 138 |
b.f(); // calls X::f()
|
| 139 |
}
|
| 140 |
```
|
| 141 |
+
|
| 142 |
+
— *end example*]
|
| 143 |
- User-defined conversion sequence `U1` is a better conversion sequence
|
| 144 |
than another user-defined conversion sequence `U2` if they contain the
|
| 145 |
same user-defined conversion function or constructor or they
|
| 146 |
initialize the same class in an aggregate initialization and in either
|
| 147 |
case the second standard conversion sequence of `U1` is better than
|
| 148 |
the second standard conversion sequence of `U2`.
|
| 149 |
+
\[*Example 6*:
|
| 150 |
``` cpp
|
| 151 |
struct A {
|
| 152 |
operator short();
|
| 153 |
} a;
|
| 154 |
int f(int);
|
| 155 |
int f(float);
|
| 156 |
int i = f(a); // calls f(int), because short → int is
|
| 157 |
// better than short → float.
|
| 158 |
```
|
| 159 |
+
|
| 160 |
+
— *end example*]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
Standard conversion sequences are ordered by their ranks: an Exact Match
|
| 163 |
is a better conversion than a Promotion, which is a better conversion
|
| 164 |
than a Conversion. Two conversion sequences with the same rank are
|
| 165 |
indistinguishable unless one of the following rules applies:
|
|
|
|
| 175 |
of `B*` to `void*`.
|
| 176 |
- If class `B` is derived directly or indirectly from class `A` and
|
| 177 |
class `C` is derived directly or indirectly from `B`,
|
| 178 |
- conversion of `C*` to `B*` is better than conversion of `C*` to
|
| 179 |
`A*`,
|
| 180 |
+
\[*Example 7*:
|
| 181 |
``` cpp
|
| 182 |
struct A {};
|
| 183 |
struct B : public A {};
|
| 184 |
struct C : public B {};
|
| 185 |
C* pc;
|
| 186 |
int f(A*);
|
| 187 |
int f(B*);
|
| 188 |
int i = f(pc); // calls f(B*)
|
| 189 |
```
|
| 190 |
+
|
| 191 |
+
— *end example*]
|
| 192 |
- binding of an expression of type `C` to a reference to type `B` is
|
| 193 |
better than binding an expression of type `C` to a reference to type
|
| 194 |
`A`,
|
| 195 |
- conversion of `A::*` to `B::*` is better than conversion of `A::*`
|
| 196 |
to `C::*`,
|
|
|
|
| 202 |
`A`,
|
| 203 |
- conversion of `B::*` to `C::*` is better than conversion of `A::*`
|
| 204 |
to `C::*`, and
|
| 205 |
- conversion of `B` to `A` is better than conversion of `C` to `A`.
|
| 206 |
|
| 207 |
+
\[*Note 1*: Compared conversion sequences will have different source
|
| 208 |
+
types only in the context of comparing the second standard conversion
|
| 209 |
+
sequence of an initialization by user-defined conversion (see
|
| 210 |
+
[[over.match.best]]); in all other contexts, the source types will be
|
| 211 |
+
the same and the target types will be different. — *end note*]
|
| 212 |
|