tmp/tmpx8b0dppy/{from.md → to.md}
RENAMED
|
@@ -11,17 +11,17 @@ single expression [[dcl.init]], [[dcl.init.ref]].
|
|
| 11 |
|
| 12 |
Implicit conversion sequences are concerned only with the type,
|
| 13 |
cv-qualification, and value category of the argument and how these are
|
| 14 |
converted to match the corresponding properties of the parameter.
|
| 15 |
|
| 16 |
-
[*Note 1*: Other properties, such as the lifetime, storage
|
| 17 |
-
alignment, accessibility of the argument, whether the argument
|
| 18 |
-
bit-field, and whether a function is deleted
|
| 19 |
-
ignored. So, although an implicit conversion
|
| 20 |
-
a given argument-parameter pair, the
|
| 21 |
-
parameter might still be ill-formed
|
| 22 |
-
analysis. — *end note*]
|
| 23 |
|
| 24 |
A well-formed implicit conversion sequence is one of the following
|
| 25 |
forms:
|
| 26 |
|
| 27 |
- a standard conversion sequence [[over.ics.scs]],
|
|
@@ -78,40 +78,40 @@ parameter.
|
|
| 78 |
[*Note 3*: When the parameter has a class type, this is a conceptual
|
| 79 |
conversion defined for the purposes of [[over]]; the actual
|
| 80 |
initialization is defined in terms of constructors and is not a
|
| 81 |
conversion. — *end note*]
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
When the parameter has a class type and the argument expression has the
|
| 92 |
-
same type, the implicit conversion sequence is an identity conversion.
|
| 93 |
-
When the parameter has a class type and the argument expression has a
|
| 94 |
-
derived class type, the implicit conversion sequence is a
|
| 95 |
-
derived-to-base conversion from the derived class to the base class. A
|
| 96 |
-
derived-to-base conversion has Conversion rank [[over.ics.scs]].
|
| 97 |
|
| 98 |
[*Note 4*: There is no such standard conversion; this derived-to-base
|
| 99 |
conversion exists only in the description of implicit conversion
|
| 100 |
sequences. — *end note*]
|
| 101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
When the parameter is the implicit object parameter of a static member
|
| 103 |
function, the implicit conversion sequence is a standard conversion
|
| 104 |
sequence that is neither better nor worse than any other standard
|
| 105 |
conversion sequence.
|
| 106 |
|
| 107 |
In all contexts, when converting to the implicit object parameter or
|
| 108 |
when converting to the left operand of an assignment operation only
|
| 109 |
standard conversion sequences are allowed.
|
| 110 |
|
| 111 |
-
[*Note 5*: When
|
| 112 |
-
user-defined conversion sequences
|
| 113 |
|
| 114 |
If no conversions are required to match an argument to a parameter type,
|
| 115 |
the implicit conversion sequence is the standard conversion sequence
|
| 116 |
consisting of the identity conversion [[over.ics.scs]].
|
| 117 |
|
|
@@ -218,11 +218,11 @@ the special rules for initialization by user-defined conversion apply
|
|
| 218 |
when selecting the best user-defined conversion for a user-defined
|
| 219 |
conversion sequence (see [[over.match.best]] and [[over.best.ics]]).
|
| 220 |
|
| 221 |
If the user-defined conversion is specified by a specialization of a
|
| 222 |
conversion function template, the second standard conversion sequence
|
| 223 |
-
shall have
|
| 224 |
|
| 225 |
A conversion of an expression of class type to the same class type is
|
| 226 |
given Exact Match rank, and a conversion of an expression of class type
|
| 227 |
to a base class of that type is given Conversion rank, in spite of the
|
| 228 |
fact that a constructor (i.e., a user-defined conversion function) is
|
|
@@ -234,34 +234,47 @@ An ellipsis conversion sequence occurs when an argument in a function
|
|
| 234 |
call is matched with the ellipsis parameter specification of the
|
| 235 |
function called (see [[expr.call]]).
|
| 236 |
|
| 237 |
##### Reference binding <a id="over.ics.ref">[[over.ics.ref]]</a>
|
| 238 |
|
| 239 |
-
When a parameter of
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
sequence is a derived-to-base
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
|
| 245 |
[*Example 4*:
|
| 246 |
|
| 247 |
``` cpp
|
| 248 |
struct A {};
|
| 249 |
struct B : public A {} b;
|
| 250 |
int f(A&);
|
| 251 |
int f(B&);
|
| 252 |
int i = f(b); // calls f(B&), an exact match, rather than f(A&), a conversion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
```
|
| 254 |
|
| 255 |
— *end example*]
|
| 256 |
|
| 257 |
If the parameter binds directly to the result of applying a conversion
|
| 258 |
function to the argument expression, the implicit conversion sequence is
|
| 259 |
a user-defined conversion sequence [[over.ics.user]] whose second
|
| 260 |
-
standard conversion sequence is
|
| 261 |
-
conversion function returns an entity of a type that is a derived class
|
| 262 |
-
of the parameter type, a derived-to-base conversion.
|
| 263 |
|
| 264 |
When a parameter of reference type is not bound directly to an argument
|
| 265 |
expression, the conversion sequence is the one required to convert the
|
| 266 |
argument expression to the referenced type according to
|
| 267 |
[[over.best.ics]]. Conceptually, this conversion sequence corresponds to
|
|
@@ -271,11 +284,11 @@ the initialization itself and does not constitute a conversion.
|
|
| 271 |
|
| 272 |
Except for an implicit object parameter, for which see
|
| 273 |
[[over.match.funcs]], an implicit conversion sequence cannot be formed
|
| 274 |
if it requires binding an lvalue reference other than a reference to a
|
| 275 |
non-volatile `const` type to an rvalue or binding an rvalue reference to
|
| 276 |
-
an lvalue
|
| 277 |
|
| 278 |
[*Note 9*: This means, for example, that a candidate function cannot be
|
| 279 |
a viable function if it has a non-`const` lvalue reference parameter
|
| 280 |
(other than the implicit object parameter) and the corresponding
|
| 281 |
argument would require a temporary to be created to initialize the
|
|
@@ -298,16 +311,17 @@ non-`const` lvalue reference to a bit-field
|
|
| 298 |
|
| 299 |
When an argument is an initializer list [[dcl.init.list]], it is not an
|
| 300 |
expression and special rules apply for converting it to a parameter
|
| 301 |
type.
|
| 302 |
|
| 303 |
-
If the initializer list is a *designated-initializer-list*
|
| 304 |
-
is
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
|
|
|
| 309 |
|
| 310 |
[*Note 10*:
|
| 311 |
|
| 312 |
Aggregate initialization does not require that the members are declared
|
| 313 |
in designation order. If, after overload resolution, the order does not
|
|
@@ -363,11 +377,11 @@ f( {1,2,3} ); // OK, f(initializer_list<int>) identity convers
|
|
| 363 |
f( {'a','b'} ); // OK, f(initializer_list<int>) integral promotion
|
| 364 |
f( {1.0} ); // error: narrowing
|
| 365 |
|
| 366 |
struct A {
|
| 367 |
A(std::initializer_list<double>); // #1
|
| 368 |
-
A(std::initializer_list<complex<double>>);
|
| 369 |
A(std::initializer_list<std::string>); // #3
|
| 370 |
};
|
| 371 |
A a{ 1.0,2.0 }; // OK, uses #1
|
| 372 |
|
| 373 |
void g(A);
|
|
|
|
| 11 |
|
| 12 |
Implicit conversion sequences are concerned only with the type,
|
| 13 |
cv-qualification, and value category of the argument and how these are
|
| 14 |
converted to match the corresponding properties of the parameter.
|
| 15 |
|
| 16 |
+
[*Note 1*: Other properties, such as the lifetime, storage duration,
|
| 17 |
+
linkage, alignment, accessibility of the argument, whether the argument
|
| 18 |
+
is a bit-field, and whether a function is deleted
|
| 19 |
+
[[dcl.fct.def.delete]], are ignored. So, although an implicit conversion
|
| 20 |
+
sequence can be defined for a given argument-parameter pair, the
|
| 21 |
+
conversion from the argument to the parameter might still be ill-formed
|
| 22 |
+
in the final analysis. — *end note*]
|
| 23 |
|
| 24 |
A well-formed implicit conversion sequence is one of the following
|
| 25 |
forms:
|
| 26 |
|
| 27 |
- a standard conversion sequence [[over.ics.scs]],
|
|
|
|
| 78 |
[*Note 3*: When the parameter has a class type, this is a conceptual
|
| 79 |
conversion defined for the purposes of [[over]]; the actual
|
| 80 |
initialization is defined in terms of constructors and is not a
|
| 81 |
conversion. — *end note*]
|
| 82 |
|
| 83 |
+
When the cv-unqualified version of the type of the argument expression
|
| 84 |
+
is the same as the parameter type, the implicit conversion sequence is
|
| 85 |
+
an identity conversion. When the parameter has a class type and the
|
| 86 |
+
argument expression has a (possibly cv-qualified) derived class type,
|
| 87 |
+
the implicit conversion sequence is a derived-to-base conversion from
|
| 88 |
+
the derived class to the base class. A derived-to-base conversion has
|
| 89 |
+
Conversion rank [[over.ics.scs]].
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
[*Note 4*: There is no such standard conversion; this derived-to-base
|
| 92 |
conversion exists only in the description of implicit conversion
|
| 93 |
sequences. — *end note*]
|
| 94 |
|
| 95 |
+
[*Example 2*: An implicit conversion sequence from an argument of type
|
| 96 |
+
`const A` to a parameter of type `A` can be formed, even if overload
|
| 97 |
+
resolution for copy-initialization of `A` from the argument would not
|
| 98 |
+
find a viable function [[over.match.ctor]], [[over.match.viable]]. The
|
| 99 |
+
implicit conversion sequence for that case is the identity sequence; it
|
| 100 |
+
contains no “conversion” from `const A` to `A`. — *end example*]
|
| 101 |
+
|
| 102 |
When the parameter is the implicit object parameter of a static member
|
| 103 |
function, the implicit conversion sequence is a standard conversion
|
| 104 |
sequence that is neither better nor worse than any other standard
|
| 105 |
conversion sequence.
|
| 106 |
|
| 107 |
In all contexts, when converting to the implicit object parameter or
|
| 108 |
when converting to the left operand of an assignment operation only
|
| 109 |
standard conversion sequences are allowed.
|
| 110 |
|
| 111 |
+
[*Note 5*: When a conversion to the explicit object parameter occurs,
|
| 112 |
+
it can include user-defined conversion sequences. — *end note*]
|
| 113 |
|
| 114 |
If no conversions are required to match an argument to a parameter type,
|
| 115 |
the implicit conversion sequence is the standard conversion sequence
|
| 116 |
consisting of the identity conversion [[over.ics.scs]].
|
| 117 |
|
|
|
|
| 218 |
when selecting the best user-defined conversion for a user-defined
|
| 219 |
conversion sequence (see [[over.match.best]] and [[over.best.ics]]).
|
| 220 |
|
| 221 |
If the user-defined conversion is specified by a specialization of a
|
| 222 |
conversion function template, the second standard conversion sequence
|
| 223 |
+
shall have Exact Match rank.
|
| 224 |
|
| 225 |
A conversion of an expression of class type to the same class type is
|
| 226 |
given Exact Match rank, and a conversion of an expression of class type
|
| 227 |
to a base class of that type is given Conversion rank, in spite of the
|
| 228 |
fact that a constructor (i.e., a user-defined conversion function) is
|
|
|
|
| 234 |
call is matched with the ellipsis parameter specification of the
|
| 235 |
function called (see [[expr.call]]).
|
| 236 |
|
| 237 |
##### Reference binding <a id="over.ics.ref">[[over.ics.ref]]</a>
|
| 238 |
|
| 239 |
+
When a parameter of type “reference to cv `T`” binds directly
|
| 240 |
+
[[dcl.init.ref]] to an argument expression:
|
| 241 |
+
|
| 242 |
+
- If the argument expression has a type that is a derived class of the
|
| 243 |
+
parameter type, the implicit conversion sequence is a derived-to-base
|
| 244 |
+
conversion [[over.best.ics]].
|
| 245 |
+
- Otherwise, if the type of the argument is possibly cv-qualified `T`,
|
| 246 |
+
or if `T` is an array type of unknown bound with element type `U` and
|
| 247 |
+
the argument has an array type of known bound whose element type is
|
| 248 |
+
possibly cv-qualified `U`, the implicit conversion sequence is the
|
| 249 |
+
identity conversion.
|
| 250 |
+
- Otherwise, if `T` is a function type, the implicit conversion sequence
|
| 251 |
+
is a function pointer conversion.
|
| 252 |
+
- Otherwise, the implicit conversion sequence is a qualification
|
| 253 |
+
conversion.
|
| 254 |
|
| 255 |
[*Example 4*:
|
| 256 |
|
| 257 |
``` cpp
|
| 258 |
struct A {};
|
| 259 |
struct B : public A {} b;
|
| 260 |
int f(A&);
|
| 261 |
int f(B&);
|
| 262 |
int i = f(b); // calls f(B&), an exact match, rather than f(A&), a conversion
|
| 263 |
+
|
| 264 |
+
void g() noexcept;
|
| 265 |
+
int h(void (&)() noexcept); // #1
|
| 266 |
+
int h(void (&)()); // #2
|
| 267 |
+
int j = h(g); // calls #1, an exact match, rather than #2, a function pointer conversion
|
| 268 |
```
|
| 269 |
|
| 270 |
— *end example*]
|
| 271 |
|
| 272 |
If the parameter binds directly to the result of applying a conversion
|
| 273 |
function to the argument expression, the implicit conversion sequence is
|
| 274 |
a user-defined conversion sequence [[over.ics.user]] whose second
|
| 275 |
+
standard conversion sequence is determined by the above rules.
|
|
|
|
|
|
|
| 276 |
|
| 277 |
When a parameter of reference type is not bound directly to an argument
|
| 278 |
expression, the conversion sequence is the one required to convert the
|
| 279 |
argument expression to the referenced type according to
|
| 280 |
[[over.best.ics]]. Conceptually, this conversion sequence corresponds to
|
|
|
|
| 284 |
|
| 285 |
Except for an implicit object parameter, for which see
|
| 286 |
[[over.match.funcs]], an implicit conversion sequence cannot be formed
|
| 287 |
if it requires binding an lvalue reference other than a reference to a
|
| 288 |
non-volatile `const` type to an rvalue or binding an rvalue reference to
|
| 289 |
+
an lvalue of object type.
|
| 290 |
|
| 291 |
[*Note 9*: This means, for example, that a candidate function cannot be
|
| 292 |
a viable function if it has a non-`const` lvalue reference parameter
|
| 293 |
(other than the implicit object parameter) and the corresponding
|
| 294 |
argument would require a temporary to be created to initialize the
|
|
|
|
| 311 |
|
| 312 |
When an argument is an initializer list [[dcl.init.list]], it is not an
|
| 313 |
expression and special rules apply for converting it to a parameter
|
| 314 |
type.
|
| 315 |
|
| 316 |
+
If the initializer list is a *designated-initializer-list* and the
|
| 317 |
+
parameter is not a reference, a conversion is only possible if the
|
| 318 |
+
parameter has an aggregate type that can be initialized from the
|
| 319 |
+
initializer list according to the rules for aggregate initialization
|
| 320 |
+
[[dcl.init.aggr]], in which case the implicit conversion sequence is a
|
| 321 |
+
user-defined conversion sequence whose second standard conversion
|
| 322 |
+
sequence is an identity conversion.
|
| 323 |
|
| 324 |
[*Note 10*:
|
| 325 |
|
| 326 |
Aggregate initialization does not require that the members are declared
|
| 327 |
in designation order. If, after overload resolution, the order does not
|
|
|
|
| 377 |
f( {'a','b'} ); // OK, f(initializer_list<int>) integral promotion
|
| 378 |
f( {1.0} ); // error: narrowing
|
| 379 |
|
| 380 |
struct A {
|
| 381 |
A(std::initializer_list<double>); // #1
|
| 382 |
+
A(std::initializer_list<std::complex<double>>); // #2
|
| 383 |
A(std::initializer_list<std::string>); // #3
|
| 384 |
};
|
| 385 |
A a{ 1.0,2.0 }; // OK, uses #1
|
| 386 |
|
| 387 |
void g(A);
|