From Jason Turner

[conv.lval]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp8yjdot1l/{from.md → to.md} +38 -15
tmp/tmp8yjdot1l/{from.md → to.md} RENAMED
@@ -1,23 +1,46 @@
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.[^1] If `T` is an incomplete type, a program that
5
- necessitates this conversion is ill-formed. If the object to which the
6
- glvalue refers is not an object of type `T` and is not an object of a
7
- type derived from `T`, or if the object is uninitialized, a program that
8
- necessitates this conversion has undefined behavior. If `T` is a
9
- non-class type, the type of the prvalue is the cv-unqualified version of
10
- `T`. Otherwise, the type of the prvalue is `T`.[^2]
11
 
12
- When an lvalue-to-rvalue conversion occurs in an unevaluated operand or
13
- a subexpression thereof (Clause  [[expr]]) the value contained in the
14
- referenced object is not accessed. Otherwise, if the glvalue has a class
15
- type, the conversion copy-initializes a temporary of type `T` from the
16
- glvalue and the result of the conversion is a prvalue for the temporary.
17
- Otherwise, if the glvalue has (possibly cv-qualified) type
18
- `std::nullptr_t`, the prvalue result is a null pointer constant (
19
- [[conv.ptr]]). Otherwise, the value contained in the object indicated by
20
- the glvalue is the prvalue result.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  See also  [[basic.lval]].
23
 
 
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.[^1] 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`.[^2]
 
 
 
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 `ex` of
14
+ the set of potential results of `e`, and `ex` names a variable `x`
15
+ that is not odr-used by `ex` ([[basic.def.odr]]),
16
+
17
+ the value contained in the referenced object is not accessed.
18
+
19
+ ``` cpp
20
+ struct S { int n; };
21
+ auto f() {
22
+ S x { 1 };
23
+ constexpr S y { 2 };
24
+ return [&](bool b) { return (b ? y : x).n; };
25
+ }
26
+ auto g = f();
27
+ int m = g(false); // undefined behavior due to access of x.n outside its lifetime
28
+ int n = g(true); // OK, does not access y.n
29
+ ```
30
+
31
+ In all other cases, the result of the conversion is determined according
32
+ to the following rules:
33
+
34
+ - If `T` is (possibly cv-qualified) `std::nullptr_t`, the result is a
35
+ null pointer constant ([[conv.ptr]]).
36
+ - Otherwise, if `T` has a class type, the conversion copy-initializes a
37
+ temporary of type `T` from the glvalue and the result of the
38
+ conversion is a prvalue for the temporary.
39
+ - Otherwise, if the object to which the glvalue refers contains an
40
+ invalid pointer value ([[basic.stc.dynamic.deallocation]],
41
+ [[basic.stc.dynamic.safety]]), the behavior is implementation-defined.
42
+ - Otherwise, the value contained in the object indicated by the glvalue
43
+ is the prvalue result.
44
 
45
  See also  [[basic.lval]].
46