tmp/tmpulzcrkoa/{from.md → to.md}
RENAMED
|
@@ -22,20 +22,41 @@ forms:
|
|
| 22 |
|
| 23 |
- a *standard conversion sequence* ([[over.ics.scs]]),
|
| 24 |
- a *user-defined conversion sequence* ([[over.ics.user]]), or
|
| 25 |
- an *ellipsis conversion sequence* ([[over.ics.ellipsis]]).
|
| 26 |
|
| 27 |
-
However,
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
[[over.match.
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
For the case where the parameter type is a reference, see
|
| 39 |
[[over.ics.ref]].
|
| 40 |
|
| 41 |
When the parameter type is not a reference, the implicit conversion
|
|
@@ -153,12 +174,12 @@ conversion function template, the second standard conversion sequence
|
|
| 153 |
shall have exact match rank.
|
| 154 |
|
| 155 |
A conversion of an expression of class type to the same class type is
|
| 156 |
given Exact Match rank, and a conversion of an expression of class type
|
| 157 |
to a base class of that type is given Conversion rank, in spite of the
|
| 158 |
-
fact that a
|
| 159 |
-
|
| 160 |
|
| 161 |
##### Ellipsis conversion sequences <a id="over.ics.ellipsis">[[over.ics.ellipsis]]</a>
|
| 162 |
|
| 163 |
An ellipsis conversion sequence occurs when an argument in a function
|
| 164 |
call is matched with the ellipsis parameter specification of the
|
|
@@ -216,29 +237,27 @@ formation of implicit conversion sequences treats the `int` bit-field as
|
|
| 216 |
an `int` lvalue and finds an exact match with the parameter. If the
|
| 217 |
function is selected by overload resolution, the call will nonetheless
|
| 218 |
be ill-formed because of the prohibition on binding a non-`const` lvalue
|
| 219 |
reference to a bit-field ([[dcl.init.ref]]).
|
| 220 |
|
| 221 |
-
The binding of a reference to an expression that is
|
| 222 |
-
*reference-compatible with added qualification* influences the rank of a
|
| 223 |
-
standard conversion; see [[over.ics.rank]] and [[dcl.init.ref]].
|
| 224 |
-
|
| 225 |
##### List-initialization sequence <a id="over.ics.list">[[over.ics.list]]</a>
|
| 226 |
|
| 227 |
When an argument is an initializer list ([[dcl.init.list]]), it is not
|
| 228 |
an expression and special rules apply for converting it to a parameter
|
| 229 |
type.
|
| 230 |
|
| 231 |
-
If the parameter type is `std::initializer_list<X>`
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
conversion can be a user-defined
|
| 236 |
-
call to an initializer-list
|
|
|
|
| 237 |
|
| 238 |
``` cpp
|
| 239 |
void f(std::initializer_list<int>);
|
|
|
|
| 240 |
f( {1,2,3} ); // OK: f(initializer_list<int>) identity conversion
|
| 241 |
f( {'a','b'} ); // OK: f(initializer_list<int>) integral promotion
|
| 242 |
f( {1.0} ); // error: narrowing
|
| 243 |
|
| 244 |
struct A {
|
|
@@ -254,19 +273,27 @@ g({ "foo", "bar" }); // OK, uses #3
|
|
| 254 |
typedef int IA[3];
|
| 255 |
void h(const IA&);
|
| 256 |
h({ 1, 2, 3 }); // OK: identity conversion
|
| 257 |
```
|
| 258 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
Otherwise, if the parameter is a non-aggregate class `X` and overload
|
| 260 |
resolution per [[over.match.list]] chooses a single best constructor of
|
| 261 |
`X` to perform the initialization of an object of type `X` from the
|
| 262 |
argument initializer list, the implicit conversion sequence is a
|
| 263 |
-
user-defined conversion sequence
|
| 264 |
-
|
| 265 |
-
the
|
| 266 |
-
|
| 267 |
-
|
|
|
|
| 268 |
|
| 269 |
``` cpp
|
| 270 |
struct A {
|
| 271 |
A(std::initializer_list<int>);
|
| 272 |
};
|
|
@@ -276,11 +303,11 @@ f( {'a', 'b'} ); // OK: f(A(std::initializer_list<int>)) user-defined
|
|
| 276 |
struct B {
|
| 277 |
B(int, double);
|
| 278 |
};
|
| 279 |
void g(B);
|
| 280 |
g( {'a', 'b'} ); // OK: g(B(int,double)) user-defined conversion
|
| 281 |
-
g( {1.0, 1
|
| 282 |
|
| 283 |
void f(B);
|
| 284 |
f( {'a', 'b'} ); // error: ambiguous f(A) or f(B)
|
| 285 |
|
| 286 |
struct C {
|
|
@@ -288,20 +315,21 @@ struct C {
|
|
| 288 |
};
|
| 289 |
void h(C);
|
| 290 |
h({"foo"}); // OK: h(C(std::string("foo")))
|
| 291 |
|
| 292 |
struct D {
|
| 293 |
-
|
| 294 |
};
|
| 295 |
void i(D);
|
| 296 |
i({ {1,2}, {"bar"} }); // OK: i(D(A(std::initializer_list<int>{1,2\),C(std::string("bar"))))}
|
| 297 |
```
|
| 298 |
|
| 299 |
Otherwise, if the parameter has an aggregate type which can be
|
| 300 |
initialized from the initializer list according to the rules for
|
| 301 |
aggregate initialization ([[dcl.init.aggr]]), the implicit conversion
|
| 302 |
-
sequence is a user-defined conversion sequence
|
|
|
|
| 303 |
|
| 304 |
``` cpp
|
| 305 |
struct A {
|
| 306 |
int m1;
|
| 307 |
double m2;
|
|
|
|
| 22 |
|
| 23 |
- a *standard conversion sequence* ([[over.ics.scs]]),
|
| 24 |
- a *user-defined conversion sequence* ([[over.ics.user]]), or
|
| 25 |
- an *ellipsis conversion sequence* ([[over.ics.ellipsis]]).
|
| 26 |
|
| 27 |
+
However, if the target is
|
| 28 |
+
|
| 29 |
+
- the first parameter of a constructor or
|
| 30 |
+
- the implicit object parameter of a user-defined conversion function
|
| 31 |
+
|
| 32 |
+
and the constructor or user-defined conversion function is a candidate
|
| 33 |
+
by
|
| 34 |
+
|
| 35 |
+
- [[over.match.ctor]], when the argument is the temporary in the second
|
| 36 |
+
step of a class copy-initialization,
|
| 37 |
+
- [[over.match.copy]], [[over.match.conv]], or [[over.match.ref]] (in
|
| 38 |
+
all cases), or
|
| 39 |
+
- the second phase of [[over.match.list]] when the initializer list has
|
| 40 |
+
exactly one element, and the target is the first parameter of a
|
| 41 |
+
constructor of class `X`, and the conversion is to `X` or reference to
|
| 42 |
+
(possibly cv-qualified) `X`,
|
| 43 |
+
|
| 44 |
+
user-defined conversion sequences are not considered. These rules
|
| 45 |
+
prevent more than one user-defined conversion from being applied during
|
| 46 |
+
overload resolution, thereby avoiding infinite recursion.
|
| 47 |
+
|
| 48 |
+
``` cpp
|
| 49 |
+
struct Y { Y(int); };
|
| 50 |
+
struct A { operator int(); };
|
| 51 |
+
Y y1 = A(); // error: A::operator int() is not a candidate
|
| 52 |
+
|
| 53 |
+
struct X { };
|
| 54 |
+
struct B { operator X(); };
|
| 55 |
+
B b;
|
| 56 |
+
X x({b}); // error: B::operator X() is not a candidate
|
| 57 |
+
```
|
| 58 |
|
| 59 |
For the case where the parameter type is a reference, see
|
| 60 |
[[over.ics.ref]].
|
| 61 |
|
| 62 |
When the parameter type is not a reference, the implicit conversion
|
|
|
|
| 174 |
shall have exact match rank.
|
| 175 |
|
| 176 |
A conversion of an expression of class type to the same class type is
|
| 177 |
given Exact Match rank, and a conversion of an expression of class type
|
| 178 |
to a base class of that type is given Conversion rank, in spite of the
|
| 179 |
+
fact that a constructor (i.e., a user-defined conversion function) is
|
| 180 |
+
called for those cases.
|
| 181 |
|
| 182 |
##### Ellipsis conversion sequences <a id="over.ics.ellipsis">[[over.ics.ellipsis]]</a>
|
| 183 |
|
| 184 |
An ellipsis conversion sequence occurs when an argument in a function
|
| 185 |
call is matched with the ellipsis parameter specification of the
|
|
|
|
| 237 |
an `int` lvalue and finds an exact match with the parameter. If the
|
| 238 |
function is selected by overload resolution, the call will nonetheless
|
| 239 |
be ill-formed because of the prohibition on binding a non-`const` lvalue
|
| 240 |
reference to a bit-field ([[dcl.init.ref]]).
|
| 241 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
##### List-initialization sequence <a id="over.ics.list">[[over.ics.list]]</a>
|
| 243 |
|
| 244 |
When an argument is an initializer list ([[dcl.init.list]]), it is not
|
| 245 |
an expression and special rules apply for converting it to a parameter
|
| 246 |
type.
|
| 247 |
|
| 248 |
+
If the parameter type is `std::initializer_list<X>` and all the elements
|
| 249 |
+
of the initializer list can be implicitly converted to `X`, the implicit
|
| 250 |
+
conversion sequence is the worst conversion necessary to convert an
|
| 251 |
+
element of the list to `X`, or if the initializer list has no elements,
|
| 252 |
+
the identity conversion. This conversion can be a user-defined
|
| 253 |
+
conversion even in the context of a call to an initializer-list
|
| 254 |
+
constructor.
|
| 255 |
|
| 256 |
``` cpp
|
| 257 |
void f(std::initializer_list<int>);
|
| 258 |
+
f( {} ); // OK: f(initializer_list<int>) identity conversion
|
| 259 |
f( {1,2,3} ); // OK: f(initializer_list<int>) identity conversion
|
| 260 |
f( {'a','b'} ); // OK: f(initializer_list<int>) integral promotion
|
| 261 |
f( {1.0} ); // error: narrowing
|
| 262 |
|
| 263 |
struct A {
|
|
|
|
| 273 |
typedef int IA[3];
|
| 274 |
void h(const IA&);
|
| 275 |
h({ 1, 2, 3 }); // OK: identity conversion
|
| 276 |
```
|
| 277 |
|
| 278 |
+
Otherwise, if the parameter type is “array of `N` `X`”[^12], if the
|
| 279 |
+
initializer list has exactly `N` elements or if it has fewer than `N`
|
| 280 |
+
elements and `X` is default-constructible, and if all the elements of
|
| 281 |
+
the initializer list can be implicitly converted to `X`, the implicit
|
| 282 |
+
conversion sequence is the worst conversion necessary to convert an
|
| 283 |
+
element of the list to `X`.
|
| 284 |
+
|
| 285 |
Otherwise, if the parameter is a non-aggregate class `X` and overload
|
| 286 |
resolution per [[over.match.list]] chooses a single best constructor of
|
| 287 |
`X` to perform the initialization of an object of type `X` from the
|
| 288 |
argument initializer list, the implicit conversion sequence is a
|
| 289 |
+
user-defined conversion sequence with the second standard conversion
|
| 290 |
+
sequence an identity conversion. If multiple constructors are viable but
|
| 291 |
+
none is better than the others, the implicit conversion sequence is the
|
| 292 |
+
ambiguous conversion sequence. User-defined conversions are allowed for
|
| 293 |
+
conversion of the initializer list elements to the constructor parameter
|
| 294 |
+
types except as noted in [[over.best.ics]].
|
| 295 |
|
| 296 |
``` cpp
|
| 297 |
struct A {
|
| 298 |
A(std::initializer_list<int>);
|
| 299 |
};
|
|
|
|
| 303 |
struct B {
|
| 304 |
B(int, double);
|
| 305 |
};
|
| 306 |
void g(B);
|
| 307 |
g( {'a', 'b'} ); // OK: g(B(int,double)) user-defined conversion
|
| 308 |
+
g( {1.0, 1.0} ); // error: narrowing
|
| 309 |
|
| 310 |
void f(B);
|
| 311 |
f( {'a', 'b'} ); // error: ambiguous f(A) or f(B)
|
| 312 |
|
| 313 |
struct C {
|
|
|
|
| 315 |
};
|
| 316 |
void h(C);
|
| 317 |
h({"foo"}); // OK: h(C(std::string("foo")))
|
| 318 |
|
| 319 |
struct D {
|
| 320 |
+
D(A, C);
|
| 321 |
};
|
| 322 |
void i(D);
|
| 323 |
i({ {1,2}, {"bar"} }); // OK: i(D(A(std::initializer_list<int>{1,2\),C(std::string("bar"))))}
|
| 324 |
```
|
| 325 |
|
| 326 |
Otherwise, if the parameter has an aggregate type which can be
|
| 327 |
initialized from the initializer list according to the rules for
|
| 328 |
aggregate initialization ([[dcl.init.aggr]]), the implicit conversion
|
| 329 |
+
sequence is a user-defined conversion sequence with the second standard
|
| 330 |
+
conversion sequence an identity conversion.
|
| 331 |
|
| 332 |
``` cpp
|
| 333 |
struct A {
|
| 334 |
int m1;
|
| 335 |
double m2;
|