tmp/tmpzyk95oqn/{from.md → to.md}
RENAMED
|
@@ -1,20 +1,20 @@
|
|
| 1 |
-
## Lvalue-to-rvalue conversion <a id="conv.lval">[[conv.lval]]</a>
|
| 2 |
|
| 3 |
-
A glvalue
|
| 4 |
-
converted to a prvalue.[^
|
| 5 |
necessitates this conversion is ill-formed. If `T` is a non-class type,
|
| 6 |
the type of the prvalue is the cv-unqualified version of `T`. Otherwise,
|
| 7 |
-
the type of the prvalue is `T`. [^
|
| 8 |
|
| 9 |
-
When an lvalue-to-rvalue conversion is applied to an expression
|
| 10 |
either
|
| 11 |
|
| 12 |
-
-
|
| 13 |
-
- the evaluation of
|
| 14 |
-
|
| 15 |
-
|
| 16 |
|
| 17 |
the value contained in the referenced object is not accessed.
|
| 18 |
|
| 19 |
[*Example 1*:
|
| 20 |
|
|
@@ -24,30 +24,31 @@ auto f() {
|
|
| 24 |
S x { 1 };
|
| 25 |
constexpr S y { 2 };
|
| 26 |
return [&](bool b) { return (b ? y : x).n; };
|
| 27 |
}
|
| 28 |
auto g = f();
|
| 29 |
-
int m = g(false); // undefined behavior
|
| 30 |
int n = g(true); // OK, does not access y.n
|
| 31 |
```
|
| 32 |
|
| 33 |
— *end example*]
|
| 34 |
|
| 35 |
The result of the conversion is determined according to the following
|
| 36 |
rules:
|
| 37 |
|
| 38 |
-
- If `T` is cv `std::nullptr_t`, the result is a null pointer constant
|
| 39 |
-
[[conv.ptr]]
|
| 40 |
-
there is no side effect
|
| 41 |
-
|
| 42 |
-
|
| 43 |
- Otherwise, if `T` has a class type, the conversion copy-initializes
|
| 44 |
the result object from the glvalue.
|
| 45 |
- Otherwise, if the object to which the glvalue refers contains an
|
| 46 |
invalid pointer value ([[basic.stc.dynamic.deallocation]],
|
| 47 |
[[basic.stc.dynamic.safety]]), the behavior is
|
| 48 |
*implementation-defined*.
|
| 49 |
-
- Otherwise, the
|
| 50 |
-
is the prvalue
|
|
|
|
| 51 |
|
| 52 |
[*Note 2*: See also [[basic.lval]]. — *end note*]
|
| 53 |
|
|
|
|
| 1 |
+
### Lvalue-to-rvalue conversion <a id="conv.lval">[[conv.lval]]</a>
|
| 2 |
|
| 3 |
+
A glvalue [[basic.lval]] of a non-function, non-array type `T` can be
|
| 4 |
+
converted to a prvalue.[^5] If `T` is an incomplete type, a program that
|
| 5 |
necessitates this conversion is ill-formed. If `T` is a non-class type,
|
| 6 |
the type of the prvalue is the cv-unqualified version of `T`. Otherwise,
|
| 7 |
+
the type of the prvalue is `T`. [^6]
|
| 8 |
|
| 9 |
+
When an lvalue-to-rvalue conversion is applied to an expression E, and
|
| 10 |
either
|
| 11 |
|
| 12 |
+
- E is not potentially evaluated, or
|
| 13 |
+
- the evaluation of E results in the evaluation of a member E_`x` of the
|
| 14 |
+
set of potential results of E, and E_`x` names a variable `x` that is
|
| 15 |
+
not odr-used by E_`x` [[basic.def.odr]],
|
| 16 |
|
| 17 |
the value contained in the referenced object is not accessed.
|
| 18 |
|
| 19 |
[*Example 1*:
|
| 20 |
|
|
|
|
| 24 |
S x { 1 };
|
| 25 |
constexpr S y { 2 };
|
| 26 |
return [&](bool b) { return (b ? y : x).n; };
|
| 27 |
}
|
| 28 |
auto g = f();
|
| 29 |
+
int m = g(false); // undefined behavior: access of x.n outside its lifetime
|
| 30 |
int n = g(true); // OK, does not access y.n
|
| 31 |
```
|
| 32 |
|
| 33 |
— *end example*]
|
| 34 |
|
| 35 |
The result of the conversion is determined according to the following
|
| 36 |
rules:
|
| 37 |
|
| 38 |
+
- If `T` is cv `std::nullptr_t`, the result is a null pointer constant
|
| 39 |
+
[[conv.ptr]]. \[*Note 1*: Since the conversion does not access the
|
| 40 |
+
object to which the glvalue refers, there is no side effect even if
|
| 41 |
+
`T` is volatile-qualified [[intro.execution]], and the glvalue can
|
| 42 |
+
refer to an inactive member of a union [[class.union]]. — *end note*]
|
| 43 |
- Otherwise, if `T` has a class type, the conversion copy-initializes
|
| 44 |
the result object from the glvalue.
|
| 45 |
- Otherwise, if the object to which the glvalue refers contains an
|
| 46 |
invalid pointer value ([[basic.stc.dynamic.deallocation]],
|
| 47 |
[[basic.stc.dynamic.safety]]), the behavior is
|
| 48 |
*implementation-defined*.
|
| 49 |
+
- Otherwise, the object indicated by the glvalue is read
|
| 50 |
+
[[defns.access]], and the value contained in the object is the prvalue
|
| 51 |
+
result.
|
| 52 |
|
| 53 |
[*Note 2*: See also [[basic.lval]]. — *end note*]
|
| 54 |
|