tmp/tmpi_3sid88/{from.md → to.md}
RENAMED
|
@@ -4,51 +4,57 @@ When a parameter of reference type binds directly ([[dcl.init.ref]]) to
|
|
| 4 |
an argument expression, the implicit conversion sequence is the identity
|
| 5 |
conversion, unless the argument expression has a type that is a derived
|
| 6 |
class of the parameter type, in which case the implicit conversion
|
| 7 |
sequence is a derived-to-base Conversion ([[over.best.ics]]).
|
| 8 |
|
|
|
|
|
|
|
| 9 |
``` cpp
|
| 10 |
struct A {};
|
| 11 |
struct B : public A {} b;
|
| 12 |
int f(A&);
|
| 13 |
int f(B&);
|
| 14 |
-
int i = f(b);
|
| 15 |
-
// f(A&), a conversion
|
| 16 |
```
|
| 17 |
|
|
|
|
|
|
|
| 18 |
If the parameter binds directly to the result of applying a conversion
|
| 19 |
function to the argument expression, the implicit conversion sequence is
|
| 20 |
a user-defined conversion sequence ([[over.ics.user]]), with the second
|
| 21 |
standard conversion sequence either an identity conversion or, if the
|
| 22 |
conversion function returns an entity of a type that is a derived class
|
| 23 |
of the parameter type, a derived-to-base Conversion.
|
| 24 |
|
| 25 |
When a parameter of reference type is not bound directly to an argument
|
| 26 |
expression, the conversion sequence is the one required to convert the
|
| 27 |
-
argument expression to the
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
conversion.
|
| 33 |
|
| 34 |
Except for an implicit object parameter, for which see
|
| 35 |
[[over.match.funcs]], a standard conversion sequence cannot be formed if
|
| 36 |
it requires binding an lvalue reference other than a reference to a
|
| 37 |
non-volatile `const` type to an rvalue or binding an rvalue reference to
|
| 38 |
-
an lvalue other than a function lvalue.
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
| 43 |
|
| 44 |
Other restrictions on binding a reference to a particular argument that
|
| 45 |
are not based on the types of the reference and the argument do not
|
| 46 |
-
affect the formation of a standard conversion sequence, however.
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
| 54 |
|
|
|
|
| 4 |
an argument expression, the implicit conversion sequence is the identity
|
| 5 |
conversion, unless the argument expression has a type that is a derived
|
| 6 |
class of the parameter type, in which case the implicit conversion
|
| 7 |
sequence is a derived-to-base Conversion ([[over.best.ics]]).
|
| 8 |
|
| 9 |
+
[*Example 4*:
|
| 10 |
+
|
| 11 |
``` cpp
|
| 12 |
struct A {};
|
| 13 |
struct B : public A {} b;
|
| 14 |
int f(A&);
|
| 15 |
int f(B&);
|
| 16 |
+
int i = f(b); // calls f(B&), an exact match, rather than f(A&), a conversion
|
|
|
|
| 17 |
```
|
| 18 |
|
| 19 |
+
— *end example*]
|
| 20 |
+
|
| 21 |
If the parameter binds directly to the result of applying a conversion
|
| 22 |
function to the argument expression, the implicit conversion sequence is
|
| 23 |
a user-defined conversion sequence ([[over.ics.user]]), with the second
|
| 24 |
standard conversion sequence either an identity conversion or, if the
|
| 25 |
conversion function returns an entity of a type that is a derived class
|
| 26 |
of the parameter type, a derived-to-base Conversion.
|
| 27 |
|
| 28 |
When a parameter of reference type is not bound directly to an argument
|
| 29 |
expression, the conversion sequence is the one required to convert the
|
| 30 |
+
argument expression to the referenced type according to
|
| 31 |
+
[[over.best.ics]]. Conceptually, this conversion sequence corresponds to
|
| 32 |
+
copy-initializing a temporary of the referenced type with the argument
|
| 33 |
+
expression. Any difference in top-level cv-qualification is subsumed by
|
| 34 |
+
the initialization itself and does not constitute a conversion.
|
|
|
|
| 35 |
|
| 36 |
Except for an implicit object parameter, for which see
|
| 37 |
[[over.match.funcs]], a standard conversion sequence cannot be formed if
|
| 38 |
it requires binding an lvalue reference other than a reference to a
|
| 39 |
non-volatile `const` type to an rvalue or binding an rvalue reference to
|
| 40 |
+
an lvalue other than a function lvalue.
|
| 41 |
+
|
| 42 |
+
[*Note 7*: This means, for example, that a candidate function cannot be
|
| 43 |
+
a viable function if it has a non-`const` lvalue reference parameter
|
| 44 |
+
(other than the implicit object parameter) and the corresponding
|
| 45 |
+
argument would require a temporary to be created to initialize the
|
| 46 |
+
lvalue reference (see [[dcl.init.ref]]). — *end note*]
|
| 47 |
|
| 48 |
Other restrictions on binding a reference to a particular argument that
|
| 49 |
are not based on the types of the reference and the argument do not
|
| 50 |
+
affect the formation of a standard conversion sequence, however.
|
| 51 |
+
|
| 52 |
+
[*Example 5*: A function with an “lvalue reference to `int`” parameter
|
| 53 |
+
can be a viable candidate even if the corresponding argument is an `int`
|
| 54 |
+
bit-field. The formation of implicit conversion sequences treats the
|
| 55 |
+
`int` bit-field as an `int` lvalue and finds an exact match with the
|
| 56 |
+
parameter. If the function is selected by overload resolution, the call
|
| 57 |
+
will nonetheless be ill-formed because of the prohibition on binding a
|
| 58 |
+
non-`const` lvalue reference to a bit-field (
|
| 59 |
+
[[dcl.init.ref]]). — *end example*]
|
| 60 |
|