tmp/tmpeqd1o0fw/{from.md → to.md}
RENAMED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
### References <a id="dcl.init.ref">[[dcl.init.ref]]</a>
|
| 2 |
|
| 3 |
-
A variable whose declared type is “reference to
|
| 4 |
-
|
| 5 |
|
| 6 |
[*Example 1*:
|
| 7 |
|
| 8 |
``` cpp
|
| 9 |
int g(int) noexcept;
|
|
@@ -68,14 +68,14 @@ A reference to type “*cv1* `T1`” is initialized by an expression of type
|
|
| 68 |
“*cv3* `T3`”, where “*cv1* `T1`” is reference-compatible with “*cv3*
|
| 69 |
`T3`”[^7] (this conversion is selected by enumerating the applicable
|
| 70 |
conversion functions [[over.match.ref]] and choosing the best one
|
| 71 |
through overload resolution [[over.match]]),
|
| 72 |
|
| 73 |
-
then the reference
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
\[*Note 2*: The usual lvalue-to-rvalue [[conv.lval]], array-to-pointer
|
| 78 |
[[conv.array]], and function-to-pointer [[conv.func]] standard
|
| 79 |
conversions are not needed, and therefore are suppressed, when such
|
| 80 |
direct bindings to lvalues are done. — *end note*]
|
| 81 |
\[*Example 3*:
|
|
@@ -109,55 +109,57 @@ A reference to type “*cv1* `T1`” is initialized by an expression of type
|
|
| 109 |
- has a class type (i.e., `T2` is a class type), where `T1` is not
|
| 110 |
reference-related to `T2`, and can be converted to an rvalue or
|
| 111 |
function lvalue of type “*cv3* `T3`”, where “*cv1* `T1`” is
|
| 112 |
reference-compatible with “*cv3* `T3`” (see [[over.match.ref]]),
|
| 113 |
|
| 114 |
-
then the
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
class subobject).
|
| 121 |
\[*Example 5*:
|
| 122 |
``` cpp
|
| 123 |
struct A { };
|
| 124 |
struct B : A { } b;
|
| 125 |
extern B f();
|
| 126 |
-
const A& rca2 = f(); //
|
| 127 |
A&& rra = f(); // same as above
|
| 128 |
struct X {
|
| 129 |
operator B();
|
| 130 |
operator int&();
|
| 131 |
} x;
|
| 132 |
-
const A& r = x; //
|
| 133 |
int i2 = 42;
|
| 134 |
-
int&& rri = static_cast<int&&>(i2); //
|
| 135 |
-
B&& rrb = x; //
|
| 136 |
```
|
| 137 |
|
| 138 |
— *end example*]
|
| 139 |
- Otherwise:
|
| 140 |
- If `T1` or `T2` is a class type and `T1` is not reference-related to
|
| 141 |
`T2`, user-defined conversions are considered using the rules for
|
| 142 |
copy-initialization of an object of type “*cv1* `T1`” by
|
| 143 |
-
user-defined conversion
|
| 144 |
-
[[over.match.conv]]
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
non-reference copy-initialization, is
|
| 148 |
-
the reference. For this
|
| 149 |
-
conversions are not considered.
|
| 150 |
- Otherwise, the initializer expression is implicitly converted to a
|
| 151 |
-
prvalue of type “
|
| 152 |
-
|
|
|
|
| 153 |
|
| 154 |
If `T1` is reference-related to `T2`:
|
| 155 |
- *cv1* shall be the same cv-qualification as, or greater
|
| 156 |
cv-qualification than, *cv2*; and
|
| 157 |
- if the reference is an rvalue reference, the initializer expression
|
| 158 |
-
shall not be an lvalue.
|
|
|
|
|
|
|
| 159 |
|
| 160 |
\[*Example 6*:
|
| 161 |
``` cpp
|
| 162 |
struct Banana { };
|
| 163 |
struct Enigma { operator const Banana(); };
|
|
@@ -188,8 +190,8 @@ A reference to type “*cv1* `T1`” is initialized by an expression of type
|
|
| 188 |
|
| 189 |
In all cases except the last (i.e., implicitly converting the
|
| 190 |
initializer expression to the referenced type), the reference is said to
|
| 191 |
*bind directly* to the initializer expression.
|
| 192 |
|
| 193 |
-
[*Note
|
| 194 |
bound to references. — *end note*]
|
| 195 |
|
|
|
|
| 1 |
### References <a id="dcl.init.ref">[[dcl.init.ref]]</a>
|
| 2 |
|
| 3 |
+
A variable whose declared type is “reference to `T`” [[dcl.ref]] shall
|
| 4 |
+
be initialized.
|
| 5 |
|
| 6 |
[*Example 1*:
|
| 7 |
|
| 8 |
``` cpp
|
| 9 |
int g(int) noexcept;
|
|
|
|
| 68 |
“*cv3* `T3`”, where “*cv1* `T1`” is reference-compatible with “*cv3*
|
| 69 |
`T3`”[^7] (this conversion is selected by enumerating the applicable
|
| 70 |
conversion functions [[over.match.ref]] and choosing the best one
|
| 71 |
through overload resolution [[over.match]]),
|
| 72 |
|
| 73 |
+
then the reference binds to the initializer expression lvalue in the
|
| 74 |
+
first case and to the lvalue result of the conversion in the second
|
| 75 |
+
case (or, in either case, to the appropriate base class subobject of
|
| 76 |
+
the object).
|
| 77 |
\[*Note 2*: The usual lvalue-to-rvalue [[conv.lval]], array-to-pointer
|
| 78 |
[[conv.array]], and function-to-pointer [[conv.func]] standard
|
| 79 |
conversions are not needed, and therefore are suppressed, when such
|
| 80 |
direct bindings to lvalues are done. — *end note*]
|
| 81 |
\[*Example 3*:
|
|
|
|
| 109 |
- has a class type (i.e., `T2` is a class type), where `T1` is not
|
| 110 |
reference-related to `T2`, and can be converted to an rvalue or
|
| 111 |
function lvalue of type “*cv3* `T3`”, where “*cv1* `T1`” is
|
| 112 |
reference-compatible with “*cv3* `T3`” (see [[over.match.ref]]),
|
| 113 |
|
| 114 |
+
then the initializer expression in the first case and the converted
|
| 115 |
+
expression in the second case is called the converted initializer. If
|
| 116 |
+
the converted initializer is a prvalue, its type `T4` is adjusted to
|
| 117 |
+
type “*cv1* `T4`” [[conv.qual]] and the temporary materialization
|
| 118 |
+
conversion [[conv.rval]] is applied. In any case, the reference binds
|
| 119 |
+
to the resulting glvalue (or to an appropriate base class subobject).
|
|
|
|
| 120 |
\[*Example 5*:
|
| 121 |
``` cpp
|
| 122 |
struct A { };
|
| 123 |
struct B : A { } b;
|
| 124 |
extern B f();
|
| 125 |
+
const A& rca2 = f(); // binds to the A subobject of the B rvalue.
|
| 126 |
A&& rra = f(); // same as above
|
| 127 |
struct X {
|
| 128 |
operator B();
|
| 129 |
operator int&();
|
| 130 |
} x;
|
| 131 |
+
const A& r = x; // binds to the A subobject of the result of the conversion
|
| 132 |
int i2 = 42;
|
| 133 |
+
int&& rri = static_cast<int&&>(i2); // binds directly to i2
|
| 134 |
+
B&& rrb = x; // binds directly to the result of operator B
|
| 135 |
```
|
| 136 |
|
| 137 |
— *end example*]
|
| 138 |
- Otherwise:
|
| 139 |
- If `T1` or `T2` is a class type and `T1` is not reference-related to
|
| 140 |
`T2`, user-defined conversions are considered using the rules for
|
| 141 |
copy-initialization of an object of type “*cv1* `T1`” by
|
| 142 |
+
user-defined conversion
|
| 143 |
+
[[dcl.init]], [[over.match.copy]], [[over.match.conv]]; the program
|
| 144 |
+
is ill-formed if the corresponding non-reference copy-initialization
|
| 145 |
+
would be ill-formed. The result of the call to the conversion
|
| 146 |
+
function, as described for the non-reference copy-initialization, is
|
| 147 |
+
then used to direct-initialize the reference. For this
|
| 148 |
+
direct-initialization, user-defined conversions are not considered.
|
| 149 |
- Otherwise, the initializer expression is implicitly converted to a
|
| 150 |
+
prvalue of type “`T1`”. The temporary materialization conversion is
|
| 151 |
+
applied, considering the type of the prvalue to be “*cv1* `T1`”, and
|
| 152 |
+
the reference is bound to the result.
|
| 153 |
|
| 154 |
If `T1` is reference-related to `T2`:
|
| 155 |
- *cv1* shall be the same cv-qualification as, or greater
|
| 156 |
cv-qualification than, *cv2*; and
|
| 157 |
- if the reference is an rvalue reference, the initializer expression
|
| 158 |
+
shall not be an lvalue. \[*Note 3*: This can be affected by whether
|
| 159 |
+
the initializer expression is move-eligible
|
| 160 |
+
[[expr.prim.id.unqual]]. — *end note*]
|
| 161 |
|
| 162 |
\[*Example 6*:
|
| 163 |
``` cpp
|
| 164 |
struct Banana { };
|
| 165 |
struct Enigma { operator const Banana(); };
|
|
|
|
| 190 |
|
| 191 |
In all cases except the last (i.e., implicitly converting the
|
| 192 |
initializer expression to the referenced type), the reference is said to
|
| 193 |
*bind directly* to the initializer expression.
|
| 194 |
|
| 195 |
+
[*Note 4*: [[class.temporary]] describes the lifetime of temporaries
|
| 196 |
bound to references. — *end note*]
|
| 197 |
|