From Jason Turner

[expr.prop]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpxom9q95g/{from.md → to.md} +268 -0
tmp/tmpxom9q95g/{from.md → to.md} RENAMED
@@ -0,0 +1,268 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Properties of expressions <a id="expr.prop">[[expr.prop]]</a>
2
+
3
+ ### Value category <a id="basic.lval">[[basic.lval]]</a>
4
+
5
+ Expressions are categorized according to the taxonomy in Figure
6
+ [[fig:basic.lval]].
7
+
8
+ <a id="fig:basic.lval"></a>
9
+
10
+ ![Expression category taxonomy \[fig:basic.lval\]](images/valuecategories.svg)
11
+
12
+ - A *glvalue* is an expression whose evaluation determines the identity
13
+ of an object, bit-field, or function.
14
+ - A *prvalue* is an expression whose evaluation initializes an object or
15
+ a bit-field, or computes the value of an operand of an operator, as
16
+ specified by the context in which it appears, or an expression that
17
+ has type cv `void`.
18
+ - An *xvalue* is a glvalue that denotes an object or bit-field whose
19
+ resources can be reused (usually because it is near the end of its
20
+ lifetime).
21
+ - An *lvalue* is a glvalue that is not an xvalue.
22
+ - An *rvalue* is a prvalue or an xvalue.
23
+
24
+ Every expression belongs to exactly one of the fundamental
25
+ classifications in this taxonomy: lvalue, xvalue, or prvalue. This
26
+ property of an expression is called its *value category*.
27
+
28
+ [*Note 1*: The discussion of each built-in operator in
29
+ [[expr.compound]] indicates the category of the value it yields and the
30
+ value categories of the operands it expects. For example, the built-in
31
+ assignment operators expect that the left operand is an lvalue and that
32
+ the right operand is a prvalue and yield an lvalue as the result.
33
+ User-defined operators are functions, and the categories of values they
34
+ expect and yield are determined by their parameter and return
35
+ types. — *end note*]
36
+
37
+ [*Note 2*: Historically, lvalues and rvalues were so-called because
38
+ they could appear on the left- and right-hand side of an assignment
39
+ (although this is no longer generally true); glvalues are “generalized”
40
+ lvalues, prvalues are “pure” rvalues, and xvalues are “eXpiring”
41
+ lvalues. Despite their names, these terms classify expressions, not
42
+ values. — *end note*]
43
+
44
+ [*Note 3*:
45
+
46
+ An expression is an xvalue if it is:
47
+
48
+ - the result of calling a function, whether implicitly or explicitly,
49
+ whose return type is an rvalue reference to object type [[expr.call]],
50
+ - a cast to an rvalue reference to object type ([[expr.type.conv]],
51
+ [[expr.dynamic.cast]], [[expr.static.cast]] [[expr.reinterpret.cast]],
52
+ [[expr.const.cast]], [[expr.cast]]),
53
+ - a subscripting operation with an xvalue array operand [[expr.sub]],
54
+ - a class member access expression designating a non-static data member
55
+ of non-reference type in which the object expression is an xvalue
56
+ [[expr.ref]], or
57
+ - a `.*` pointer-to-member expression in which the first operand is an
58
+ xvalue and the second operand is a pointer to data member
59
+ [[expr.mptr.oper]].
60
+
61
+ In general, the effect of this rule is that named rvalue references are
62
+ treated as lvalues and unnamed rvalue references to objects are treated
63
+ as xvalues; rvalue references to functions are treated as lvalues
64
+ whether named or not.
65
+
66
+ — *end note*]
67
+
68
+ [*Example 1*:
69
+
70
+ ``` cpp
71
+ struct A {
72
+ int m;
73
+ };
74
+ A&& operator+(A, A);
75
+ A&& f();
76
+
77
+ A a;
78
+ A&& ar = static_cast<A&&>(a);
79
+ ```
80
+
81
+ The expressions `f()`, `f().m`, `static_cast<A&&>(a)`, and `a + a` are
82
+ xvalues. The expression `ar` is an lvalue.
83
+
84
+ — *end example*]
85
+
86
+ The *result* of a glvalue is the entity denoted by the expression. The
87
+ *result* of a prvalue is the value that the expression stores into its
88
+ context; a prvalue that has type cv `void` has no result. A prvalue
89
+ whose result is the value *V* is sometimes said to have or name the
90
+ value *V*. The *result object* of a prvalue is the object initialized by
91
+ the prvalue; a non-discarded prvalue that is used to compute the value
92
+ of an operand of a built-in operator or a prvalue that has type
93
+ cv `void` has no result object.
94
+
95
+ [*Note 4*: Except when the prvalue is the operand of a
96
+ *decltype-specifier*, a prvalue of class or array type always has a
97
+ result object. For a discarded prvalue that has type other than
98
+ cv `void`, a temporary object is materialized; see
99
+ [[expr.context]]. — *end note*]
100
+
101
+ Whenever a glvalue appears as an operand of an operator that expects a
102
+ prvalue for that operand, the lvalue-to-rvalue [[conv.lval]],
103
+ array-to-pointer [[conv.array]], or function-to-pointer [[conv.func]]
104
+ standard conversions are applied to convert the expression to a prvalue.
105
+
106
+ [*Note 5*: An attempt to bind an rvalue reference to an lvalue is not
107
+ such a context; see  [[dcl.init.ref]]. — *end note*]
108
+
109
+ [*Note 6*: Because cv-qualifiers are removed from the type of an
110
+ expression of non-class type when the expression is converted to a
111
+ prvalue, an lvalue of type `const int` can, for example, be used where a
112
+ prvalue of type `int` is required. — *end note*]
113
+
114
+ [*Note 7*: There are no prvalue bit-fields; if a bit-field is converted
115
+ to a prvalue [[conv.lval]], a prvalue of the type of the bit-field is
116
+ created, which might then be promoted [[conv.prom]]. — *end note*]
117
+
118
+ Whenever a prvalue appears as an operand of an operator that expects a
119
+ glvalue for that operand, the temporary materialization conversion
120
+ [[conv.rval]] is applied to convert the expression to an xvalue.
121
+
122
+ The discussion of reference initialization in  [[dcl.init.ref]] and of
123
+ temporaries in  [[class.temporary]] indicates the behavior of lvalues
124
+ and rvalues in other significant contexts.
125
+
126
+ Unless otherwise indicated [[dcl.type.simple]], a prvalue shall always
127
+ have complete type or the `void` type; if it has a class type or
128
+ (possibly multi-dimensional) array of class type, that class shall not
129
+ be an abstract class [[class.abstract]]. A glvalue shall not have type
130
+ cv `void`.
131
+
132
+ [*Note 8*: A glvalue may have complete or incomplete non-`void` type.
133
+ Class and array prvalues can have cv-qualified types; other prvalues
134
+ always have cv-unqualified types. See [[expr.type]]. — *end note*]
135
+
136
+ An lvalue is *modifiable* unless its type is const-qualified or is a
137
+ function type.
138
+
139
+ [*Note 9*: A program that attempts to modify an object through a
140
+ nonmodifiable lvalue or through an rvalue is ill-formed ([[expr.ass]],
141
+ [[expr.post.incr]], [[expr.pre.incr]]). — *end note*]
142
+
143
+ If a program attempts to access [[defns.access]] the stored value of an
144
+ object through a glvalue whose type is not similar [[conv.qual]] to one
145
+ of the following types the behavior is undefined:[^4]
146
+
147
+ - the dynamic type of the object,
148
+ - a type that is the signed or unsigned type corresponding to the
149
+ dynamic type of the object, or
150
+ - a `char`, `unsigned char`, or `std::byte` type.
151
+
152
+ If a program invokes a defaulted copy/move constructor or copy/move
153
+ assignment operator for a union of type `U` with a glvalue argument that
154
+ does not denote an object of type cv `U` within its lifetime, the
155
+ behavior is undefined.
156
+
157
+ [*Note 10*: Unlike in C, C++ has no accesses of class
158
+ type. — *end note*]
159
+
160
+ ### Type <a id="expr.type">[[expr.type]]</a>
161
+
162
+ If an expression initially has the type “reference to `T`” (
163
+ [[dcl.ref]], [[dcl.init.ref]]), the type is adjusted to `T` prior to any
164
+ further analysis. The expression designates the object or function
165
+ denoted by the reference, and the expression is an lvalue or an xvalue,
166
+ depending on the expression.
167
+
168
+ [*Note 1*: Before the lifetime of the reference has started or after it
169
+ has ended, the behavior is undefined (see 
170
+ [[basic.life]]). — *end note*]
171
+
172
+ If a prvalue initially has the type “cv `T`”, where `T` is a
173
+ cv-unqualified non-class, non-array type, the type of the expression is
174
+ adjusted to `T` prior to any further analysis.
175
+
176
+ The *composite pointer type* of two operands `p1` and `p2` having types
177
+ `T1` and `T2`, respectively, where at least one is a pointer or
178
+ pointer-to-member type or `std::nullptr_t`, is:
179
+
180
+ - if both `p1` and `p2` are null pointer constants, `std::nullptr_t`;
181
+ - if either `p1` or `p2` is a null pointer constant, `T2` or `T1`,
182
+ respectively;
183
+ - if `T1` or `T2` is “pointer to *cv1* `void`” and the other type is
184
+ “pointer to *cv2* `T`”, where `T` is an object type or `void`,
185
+ “pointer to *cv12* `void`”, where *cv12* is the union of *cv1* and
186
+ *cv2*;
187
+ - if `T1` or `T2` is “pointer to `noexcept` function” and the other type
188
+ is “pointer to function”, where the function types are otherwise the
189
+ same, “pointer to function”;
190
+ - if `T1` is “pointer to *cv1* `C1`” and `T2` is “pointer to *cv2*
191
+ `C2`”, where `C1` is reference-related to `C2` or `C2` is
192
+ reference-related to `C1` [[dcl.init.ref]], the cv-combined type
193
+ [[conv.qual]] of `T1` and `T2` or the cv-combined type of `T2` and
194
+ `T1`, respectively;
195
+ - if `T1` or `T2` is “pointer to member of `C1` of type function”, the
196
+ other type is “pointer to member of `C2` of type `noexcept` function”,
197
+ and `C1` is reference-related to `C2` or `C2` is reference-related to
198
+ `C1` [[dcl.init.ref]], where the function types are otherwise the
199
+ same, “pointer to member of `C2` of type function” or “pointer to
200
+ member of `C1` of type function”, respectively;
201
+ - if `T1` is “pointer to member of `C1` of type *cv1* `U`” and `T2` is
202
+ “pointer to member of `C2` of type *cv2* `U`”, for some non-function
203
+ type `U`, where `C1` is reference-related to `C2` or `C2` is
204
+ reference-related to `C1` [[dcl.init.ref]], the cv-combined type of
205
+ `T2` and `T1` or the cv-combined type of `T1` and `T2`, respectively;
206
+ - if `T1` and `T2` are similar types [[conv.qual]], the cv-combined type
207
+ of `T1` and `T2`;
208
+ - otherwise, a program that necessitates the determination of a
209
+ composite pointer type is ill-formed.
210
+
211
+ [*Example 1*:
212
+
213
+ ``` cpp
214
+ typedef void *p;
215
+ typedef const int *q;
216
+ typedef int **pi;
217
+ typedef const int **pci;
218
+ ```
219
+
220
+ The composite pointer type of `p` and `q` is “pointer to `const void`”;
221
+ the composite pointer type of `pi` and `pci` is “pointer to `const`
222
+ pointer to `const int`”.
223
+
224
+ — *end example*]
225
+
226
+ ### Context dependence <a id="expr.context">[[expr.context]]</a>
227
+
228
+ In some contexts, *unevaluated operands* appear ([[expr.prim.req]],
229
+ [[expr.typeid]], [[expr.sizeof]], [[expr.unary.noexcept]],
230
+ [[dcl.type.simple]], [[temp.pre]], [[temp.concept]]). An unevaluated
231
+ operand is not evaluated.
232
+
233
+ [*Note 1*: In an unevaluated operand, a non-static class member may be
234
+ named [[expr.prim.id]] and naming of objects or functions does not, by
235
+ itself, require that a definition be provided [[basic.def.odr]]. An
236
+ unevaluated operand is considered a full-expression
237
+ [[intro.execution]]. — *end note*]
238
+
239
+ In some contexts, an expression only appears for its side effects. Such
240
+ an expression is called a *discarded-value expression*. The
241
+ array-to-pointer [[conv.array]] and function-to-pointer [[conv.func]]
242
+ standard conversions are not applied. The lvalue-to-rvalue conversion
243
+ [[conv.lval]] is applied if and only if the expression is a glvalue of
244
+ volatile-qualified type and it is one of the following:
245
+
246
+ - `(` *expression* `)`, where *expression* is one of these expressions,
247
+ - *id-expression* [[expr.prim.id]],
248
+ - subscripting [[expr.sub]],
249
+ - class member access [[expr.ref]],
250
+ - indirection [[expr.unary.op]],
251
+ - pointer-to-member operation [[expr.mptr.oper]],
252
+ - conditional expression [[expr.cond]] where both the second and the
253
+ third operands are one of these expressions, or
254
+ - comma expression [[expr.comma]] where the right operand is one of
255
+ these expressions.
256
+
257
+ [*Note 2*: Using an overloaded operator causes a function call; the
258
+ above covers only operators with built-in meaning. — *end note*]
259
+
260
+ If the (possibly converted) expression is a prvalue, the temporary
261
+ materialization conversion [[conv.rval]] is applied.
262
+
263
+ [*Note 3*: If the expression is an lvalue of class type, it must have a
264
+ volatile copy constructor to initialize the temporary object that is the
265
+ result object of the lvalue-to-rvalue conversion. — *end note*]
266
+
267
+ The glvalue expression is evaluated and its value is discarded.
268
+