Init
This commit is contained in:
109
cppdraft/conv/lval.md
Normal file
109
cppdraft/conv/lval.md
Normal file
@@ -0,0 +1,109 @@
|
||||
[conv.lval]
|
||||
|
||||
# 7 Expressions [[expr]](./#expr)
|
||||
|
||||
## 7.3 Standard conversions [[conv]](conv#lval)
|
||||
|
||||
### 7.3.2 Lvalue-to-rvalue conversion [conv.lval]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L612)
|
||||
|
||||
A [glvalue](basic.lval#def:glvalue "7.2.1 Value category [basic.lval]") of a non-function, non-array type T can be converted to
|
||||
a prvalue[.](#1.sentence-1)[43](#footnote-43 "For historical reasons, this conversion is called the âlvalue-to-rvalueâ conversion, even though that name does not accurately reflect the taxonomy of expressions described in [basic.lval].")
|
||||
|
||||
If T is an incomplete type, a
|
||||
program that necessitates this conversion is ill-formed[.](#1.sentence-2)
|
||||
|
||||
If T is a non-class type, the type of the prvalue is
|
||||
the cv-unqualified version of T[.](#1.sentence-3)
|
||||
|
||||
Otherwise, the type of the
|
||||
prvalue is T[.](#1.sentence-4)[44](#footnote-44 "In C++ class and array prvalues can have cv-qualified types. This differs from C, in which non-lvalues never have cv-qualified types.")
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L634)
|
||||
|
||||
When an lvalue-to-rvalue conversion
|
||||
is applied to an expression E, and either
|
||||
|
||||
- [(2.1)](#2.1)
|
||||
|
||||
E is not potentially evaluated, or
|
||||
|
||||
- [(2.2)](#2.2)
|
||||
|
||||
the evaluation of E results in the evaluation of a member Ex of the set of potential results of E, and Ex names a variable x that is not odr-used by Ex ([[basic.def.odr]](basic.def.odr "6.3 One-definition rule")),
|
||||
|
||||
the value contained in the referenced object is not accessed[.](#2.sentence-1)
|
||||
|
||||
[*Example [1](#example-1)*: struct S { int n; };auto f() { S x { 1 };constexpr S y { 2 };return [&](bool b) { return (b ? y : x).n; };}auto g = f();int m = g(false); // undefined behavior: access of x.n outside its lifetimeint n = g(true); // OK, does not access y.n â *end example*]
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L659)
|
||||
|
||||
The result of the conversion is determined according to the
|
||||
following rules:
|
||||
|
||||
- [(3.1)](#3.1)
|
||||
|
||||
If T is cv std::nullptr_t, the result is a
|
||||
null pointer constant ([[conv.ptr]](conv.ptr "7.3.12 Pointer conversions"))[.](#3.1.sentence-1)
|
||||
[*Note [1](#note-1)*:
|
||||
Since the conversion does not access the object to which the glvalue refers,
|
||||
there is no side effect even if T is volatile-qualified ([[intro.execution]](intro.execution "6.10.1 Sequential execution")), and
|
||||
the glvalue can refer to an inactive member of a union ([[class.union]](class.union "11.5 Unions"))[.](#3.1.sentence-2)
|
||||
â *end note*]
|
||||
|
||||
- [(3.2)](#3.2)
|
||||
|
||||
Otherwise, if T has a class
|
||||
type, the conversion copy-initializes the result object from
|
||||
the glvalue[.](#3.2.sentence-1)
|
||||
|
||||
- [(3.3)](#3.3)
|
||||
|
||||
Otherwise, if the object to which the glvalue refers contains an invalid
|
||||
pointer value ([[basic.compound]](basic.compound "6.9.4 Compound types")), the behavior isimplementation-defined[.](#3.3.sentence-1)
|
||||
|
||||
- [(3.4)](#3.4)
|
||||
|
||||
Otherwise, if the bits in the value representation of
|
||||
the object to which the glvalue refers
|
||||
are not valid for the object's type, the behavior is undefined[.](#3.4.sentence-1)
|
||||
[*Example [2](#example-2)*: bool f() {bool b = true; char c = 42;
|
||||
memcpy(&b, &c, 1); return b; // undefined behavior if 42 is not a valid value representation for bool} â *end example*]
|
||||
|
||||
- [(3.5)](#3.5)
|
||||
|
||||
Otherwise, the object indicated by the glvalue is read ([[defns.access]](defns.access "3.1 access"))[.](#3.5.sentence-1)
|
||||
Let V be the value contained in the object[.](#3.5.sentence-2)
|
||||
If T is an integer type,
|
||||
the prvalue result is
|
||||
the value of type T congruent ([[basic.fundamental]](basic.fundamental "6.9.2 Fundamental types")) to V, andV otherwise[.](#3.5.sentence-3)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L702)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
See also [[basic.lval]](basic.lval "7.2.1 Value category")[.](#4.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[43)](#footnote-43)[43)](#footnoteref-43)
|
||||
|
||||
For historical reasons, this conversion is called the âlvalue-to-rvalueâ
|
||||
conversion, even though that name does not accurately reflect the taxonomy
|
||||
of expressions described in [[basic.lval]](basic.lval "7.2.1 Value category")[.](#footnote-43.sentence-1)
|
||||
|
||||
[44)](#footnote-44)[44)](#footnoteref-44)
|
||||
|
||||
In C++ class and array prvalues can have cv-qualified types[.](#footnote-44.sentence-1)
|
||||
|
||||
This differs from C, in which non-lvalues never have
|
||||
cv-qualified types[.](#footnote-44.sentence-2)
|
||||
Reference in New Issue
Block a user