From Jason Turner

[expr.post]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp3ojjc2m1/{from.md → to.md} +424 -413
tmp/tmp3ojjc2m1/{from.md → to.md} RENAMED
@@ -1,6 +1,6 @@
1
- ## Postfix expressions <a id="expr.post">[[expr.post]]</a>
2
 
3
  Postfix expressions group left-to-right.
4
 
5
  ``` bnf
6
  postfix-expression:
@@ -9,156 +9,172 @@ postfix-expression:
9
  postfix-expression '(' expression-listₒₚₜ ')'
10
  simple-type-specifier '(' expression-listₒₚₜ ')'
11
  typename-specifier '(' expression-listₒₚₜ ')'
12
  simple-type-specifier braced-init-list
13
  typename-specifier braced-init-list
14
- postfix-expression '. template'ₒₚₜ id-expression
15
- postfix-expression '-> template'ₒₚₜ id-expression
16
- postfix-expression '.' pseudo-destructor-name
17
- postfix-expression '->' pseudo-destructor-name
18
  postfix-expression '++'
19
  postfix-expression '-{-}'
20
- 'dynamic_cast <' type-id '> (' expression ')'
21
- 'static_cast <' type-id '> (' expression ')'
22
- 'reinterpret_cast <' type-id '> (' expression ')'
23
- 'const_cast <' type-id '> (' expression ')'
24
- 'typeid (' expression ')'
25
- 'typeid (' type-id ')'
26
  ```
27
 
28
  ``` bnf
29
  expression-list:
30
  initializer-list
31
  ```
32
 
33
- ``` bnf
34
- pseudo-destructor-name:
35
- nested-name-specifierₒₚₜ type-name ':: ~' type-name
36
- nested-name-specifier 'template' simple-template-id ':: ~' type-name
37
- '~' type-name
38
- '~' decltype-specifier
39
- ```
40
-
41
  [*Note 1*: The `>` token following the *type-id* in a `dynamic_cast`,
42
  `static_cast`, `reinterpret_cast`, or `const_cast` may be the product of
43
- replacing a `>{>}` token by two consecutive `>` tokens (
44
- [[temp.names]]). — *end note*]
45
 
46
- ### Subscripting <a id="expr.sub">[[expr.sub]]</a>
47
 
48
  A postfix expression followed by an expression in square brackets is a
49
  postfix expression. One of the expressions shall be a glvalue of type
50
  “array of `T`” or a prvalue of type “pointer to `T`” and the other shall
51
  be a prvalue of unscoped enumeration or integral type. The result is of
52
  type “`T`”. The type “`T`” shall be a completely-defined object
53
- type.[^5] The expression `E1[E2]` is identical (by definition) to
54
- `*((E1)+(E2))`
 
 
55
 
56
- [*Note 1*: see  [[expr.unary]] and  [[expr.add]] for details of `*` and
57
- `+` and  [[dcl.array]] for details of arrays. *end note*]
 
58
 
59
- , except that in the case of an array operand, the result is an lvalue
60
- if that operand is an lvalue and an xvalue otherwise. The expression
61
- `E1` is sequenced before the expression `E2`.
 
62
 
63
  A *braced-init-list* shall not be used with the built-in subscript
64
  operator.
65
 
66
- ### Function call <a id="expr.call">[[expr.call]]</a>
67
 
68
  A function call is a postfix expression followed by parentheses
69
  containing a possibly empty, comma-separated list of
70
  *initializer-clause*s which constitute the arguments to the function.
 
 
 
 
 
71
  The postfix expression shall have function type or function pointer
72
  type. For a call to a non-member function or to a static member
73
- function, the postfix expression shall be either an lvalue that refers
74
- to a function (in which case the function-to-pointer standard
75
- conversion ([[conv.func]]) is suppressed on the postfix expression), or
76
- it shall have function pointer type. Calling a function through an
77
- expression whose function type is different from the function type of
78
- the called function’s definition results in undefined behavior (
79
- [[dcl.link]]). For a call to a non-static member function, the postfix
80
- expression shall be an implicit ([[class.mfct.non-static]], 
81
- [[class.static]]) or explicit class member access ([[expr.ref]]) whose
82
- *id-expression* is a function member name, or a pointer-to-member
83
- expression ([[expr.mptr.oper]]) selecting a function member; the call
84
- is as a member of the class object referred to by the object expression.
85
- In the case of an implicit class member access, the implied object is
86
- the one pointed to by `this`.
87
 
88
- [*Note 1*: A member function call of the form `f()` is interpreted as
 
 
 
 
 
 
 
 
 
89
  `(*this).f()` (see  [[class.mfct.non-static]]). — *end note*]
90
 
91
- If a function or member function name is used, the name can be
92
- overloaded (Clause  [[over]]), in which case the appropriate function
93
- shall be selected according to the rules in  [[over.match]]. If the
94
- selected function is non-virtual, or if the *id-expression* in the class
95
- member access expression is a *qualified-id*, that function is called.
96
- Otherwise, its final overrider ([[class.virtual]]) in the dynamic type
97
- of the object expression is called; such a call is referred to as a
98
  *virtual function call*.
99
 
100
- [*Note 2*: The dynamic type is the type of the object referred to by
101
  the current value of the object expression. [[class.cdtor]] describes
102
  the behavior of virtual function calls when the object expression refers
103
  to an object under construction or destruction. — *end note*]
104
 
105
- [*Note 3*: If a function or member function name is used, and name
106
- lookup ([[basic.lookup]]) does not find a declaration of that name, the
107
  program is ill-formed. No function is implicitly declared by such a
108
  call. — *end note*]
109
 
110
- If the *postfix-expression* designates a destructor ([[class.dtor]]),
111
- the type of the function call expression is `void`; otherwise, the type
112
- of the function call expression is the return type of the statically
113
- chosen function (i.e., ignoring the `virtual` keyword), even if the type
114
- of the function actually called is different. This return type shall be
115
- an object type, a reference type or cv `void`.
116
-
117
- When a function is called, each parameter ([[dcl.fct]]) shall be
118
- initialized ([[dcl.init]],  [[class.copy]],  [[class.ctor]]) with its
119
- corresponding argument. If the function is a non-static member function,
120
- the `this` parameter of the function ([[class.this]]) shall be
121
- initialized with a pointer to the object of the call, converted as if by
122
- an explicit type conversion ([[expr.cast]]).
123
-
124
- [*Note 4*: There is no access or ambiguity checking on this conversion;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  the access checking and disambiguation are done as part of the (possibly
126
- implicit) class member access operator. See  [[class.member.lookup]], 
127
  [[class.access.base]], and  [[expr.ref]]. — *end note*]
128
 
129
- When a function is called, the parameters that have object type shall
130
- have completely-defined object type.
131
 
132
- [*Note 5*: this still allows a parameter to be a pointer or reference
133
- to an incomplete class type. However, it prevents a passed-by-value
134
- parameter to have an incomplete class type. — *end note*]
135
 
136
  It is *implementation-defined* whether the lifetime of a parameter ends
137
  when the function in which it is defined returns or at the end of the
138
  enclosing full-expression. The initialization and destruction of each
139
  parameter occurs within the context of the calling function.
140
 
141
- [*Example 1*: The access of the constructor, conversion functions or
142
  destructor is checked at the point of call in the calling function. If a
143
  constructor or destructor for a function parameter throws an exception,
144
  the search for a handler starts in the scope of the calling function; in
145
- particular, if the function called has a *function-try-block* (Clause 
146
- [[except]]) with a handler that could handle the exception, this handler
147
- is not considered. — *end example*]
148
 
149
  The *postfix-expression* is sequenced before each *expression* in the
150
  *expression-list* and any default argument. The initialization of a
151
  parameter, including every associated value computation and side effect,
152
  is indeterminately sequenced with respect to that of any other
153
  parameter.
154
 
155
- [*Note 6*: All side effects of argument evaluations are sequenced
156
  before the function is entered (see 
157
  [[intro.execution]]). — *end note*]
158
 
159
- [*Example 2*:
160
 
161
  ``` cpp
162
  void f() {
163
  std::string s = "but I have heard it works even if you don't believe in it";
164
  s.replace(0, 4, "").replace(s.find("even"), 4, "only").replace(s.find(" don't"), 6, "");
@@ -166,15 +182,15 @@ void f() {
166
  }
167
  ```
168
 
169
  — *end example*]
170
 
171
- [*Note 7*: If an operator function is invoked using operator notation,
172
  argument evaluation is sequenced as specified for the built-in operator;
173
  see  [[over.match.oper]]. — *end note*]
174
 
175
- [*Example 3*:
176
 
177
  ``` cpp
178
  struct S {
179
  S(int);
180
  };
@@ -188,213 +204,202 @@ After performing the initializations, the value of `i` is 2 (see 
188
  [[expr.shift]]), but it is unspecified whether the value of `j` is 1 or
189
  2.
190
 
191
  — *end example*]
192
 
193
- The result of a function call is the result of the operand of the
194
- evaluated `return` statement ([[stmt.return]]) in the called function
195
- (if any), except in a virtual function call if the return type of the
196
- final overrider is different from the return type of the statically
197
- chosen function, the value returned from the final overrider is
198
- converted to the return type of the statically chosen function.
 
199
 
200
- [*Note 8*: A function can change the values of its non-const
201
  parameters, but these changes cannot affect the values of the arguments
202
- except where a parameter is of a reference type ([[dcl.ref]]); if the
203
  reference is to a const-qualified type, `const_cast` is required to be
204
  used to cast away the constness in order to modify the argument’s value.
205
  Where a parameter is of `const` reference type a temporary object is
206
- introduced if needed ([[dcl.type]],  [[lex.literal]],  [[lex.string]], 
207
- [[dcl.array]],  [[class.temporary]]). In addition, it is possible to
208
  modify the values of non-constant objects through pointer
209
  parameters. — *end note*]
210
 
211
  A function can be declared to accept fewer arguments (by declaring
212
- default arguments ([[dcl.fct.default]])) or more arguments (by using
213
- the ellipsis, `...`, or a function parameter pack ([[dcl.fct]])) than
214
- the number of parameters in the function definition ([[dcl.fct.def]]).
215
 
216
- [*Note 9*: This implies that, except where the ellipsis (`...`) or a
217
  function parameter pack is used, a parameter is available for each
218
  argument. — *end note*]
219
 
220
  When there is no parameter for a given argument, the argument is passed
221
  in such a way that the receiving function can obtain the value of the
222
- argument by invoking `va_arg` ([[support.runtime]]).
223
 
224
- [*Note 10*: This paragraph does not apply to arguments passed to a
225
  function parameter pack. Function parameter packs are expanded during
226
- template instantiation ([[temp.variadic]]), thus each such argument has
227
- a corresponding parameter when a function template specialization is
228
  actually called. — *end note*]
229
 
230
- The lvalue-to-rvalue ([[conv.lval]]), array-to-pointer (
231
- [[conv.array]]), and function-to-pointer ([[conv.func]]) standard
232
- conversions are performed on the argument expression. An argument that
233
- has type cv `std::nullptr_t` is converted to type `void*` (
234
- [[conv.ptr]]). After these conversions, if the argument does not have
235
- arithmetic, enumeration, pointer, pointer to member, or class type, the
236
- program is ill-formed. Passing a potentially-evaluated argument of class
237
- type (Clause  [[class]]) having a non-trivial copy constructor, a
238
- non-trivial move constructor, or a non-trivial destructor, with no
239
- corresponding parameter, is conditionally-supported with
240
- *implementation-defined* semantics. If the argument has integral or
241
- enumeration type that is subject to the integral promotions (
242
- [[conv.prom]]), or a floating-point type that is subject to the
243
- floating-point promotion ([[conv.fpprom]]), the value of the argument
244
- is converted to the promoted type before the call. These promotions are
245
  referred to as the *default argument promotions*.
246
 
247
- Recursive calls are permitted, except to the `main` function (
248
- [[basic.start.main]]).
249
 
250
  A function call is an lvalue if the result type is an lvalue reference
251
  type or an rvalue reference to function type, an xvalue if the result
252
  type is an rvalue reference to object type, and a prvalue otherwise.
253
 
254
- ### Explicit type conversion (functional notation) <a id="expr.type.conv">[[expr.type.conv]]</a>
255
 
256
- A *simple-type-specifier* ([[dcl.type.simple]]) or
257
- *typename-specifier* ([[temp.res]]) followed by a parenthesized
258
- optional *expression-list* or by a *braced-init-list* (the initializer)
259
- constructs a value of the specified type given the initializer. If the
260
- type is a placeholder for a deduced class type, it is replaced by the
261
- return type of the function selected by overload resolution for class
262
- template deduction ([[over.match.class.deduct]]) for the remainder of
263
- this section.
264
 
265
  If the initializer is a parenthesized single expression, the type
266
- conversion expression is equivalent (in definedness, and if defined in
267
- meaning) to the corresponding cast expression ([[expr.cast]]). If the
268
- type is cv `void` and the initializer is `()`, the expression is a
269
  prvalue of the specified type that performs no initialization.
270
  Otherwise, the expression is a prvalue of the specified type whose
271
- result object is direct-initialized ([[dcl.init]]) with the
272
- initializer. For an expression of the form `T()`, `T` shall not be an
273
- array type.
274
 
275
- ### Pseudo destructor call <a id="expr.pseudo">[[expr.pseudo]]</a>
276
-
277
- The use of a *pseudo-destructor-name* after a dot `.` or arrow `->`
278
- operator represents the destructor for the non-class type denoted by
279
- *type-name* or *decltype-specifier*. The result shall only be used as
280
- the operand for the function call operator `()`, and the result of such
281
- a call has type `void`. The only effect is the evaluation of the
282
- *postfix-expression* before the dot or arrow.
283
-
284
- The left-hand side of the dot operator shall be of scalar type. The
285
- left-hand side of the arrow operator shall be of pointer to scalar type.
286
- This scalar type is the object type. The *cv*-unqualified versions of
287
- the object type and of the type designated by the
288
- *pseudo-destructor-name* shall be the same type. Furthermore, the two
289
- *type-name*s in a *pseudo-destructor-name* of the form
290
-
291
- ``` bnf
292
- nested-name-specifierₒₚₜ type-name ':: ~' type-name
293
- ```
294
-
295
- shall designate the same scalar type (ignoring cv-qualification).
296
-
297
- ### Class member access <a id="expr.ref">[[expr.ref]]</a>
298
 
299
  A postfix expression followed by a dot `.` or an arrow `->`, optionally
300
- followed by the keyword `template` ([[temp.names]]), and then followed
301
- by an *id-expression*, is a postfix expression. The postfix expression
302
- before the dot or arrow is evaluated;[^6] the result of that evaluation,
303
- together with the *id-expression*, determines the result of the entire
304
- postfix expression.
305
-
306
- For the first option (dot) the first expression shall be a glvalue
307
- having complete class type. For the second option (arrow) the first
308
- expression shall be a prvalue having pointer to complete class type. The
309
- expression `E1->E2` is converted to the equivalent form `(*(E1)).E2`;
310
- the remainder of [[expr.ref]] will address only the first option
311
- (dot).[^7] In either case, the *id-expression* shall name a member of
312
- the class or of one of its base classes.
313
-
314
- [*Note 1*: Because the name of a class is inserted in its class scope
315
- (Clause  [[class]]), the name of a class is also considered a nested
316
- member of that class. — *end note*]
317
-
318
- [*Note 2*: [[basic.lookup.classref]] describes how names are looked up
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
319
  after the `.` and `->` operators. — *end note*]
320
 
321
- Abbreviating *postfix-expression.id-expression* as `E1.E2`, `E1` is
322
- called the *object expression*. If `E2` is a bit-field, `E1.E2` is a
323
- bit-field. The type and value category of `E1.E2` are determined as
324
- follows. In the remainder of  [[expr.ref]], *cq* represents either
325
- `const` or the absence of `const` and *vq* represents either `volatile`
326
- or the absence of `volatile`. *cv* represents an arbitrary set of
327
- cv-qualifiers, as defined in  [[basic.type.qualifier]].
328
 
329
  If `E2` is declared to have type “reference to `T`”, then `E1.E2` is an
330
  lvalue; the type of `E1.E2` is `T`. Otherwise, one of the following
331
  rules applies.
332
 
333
  - If `E2` is a static data member and the type of `E2` is `T`, then
334
  `E1.E2` is an lvalue; the expression designates the named member of
335
  the class. The type of `E1.E2` is `T`.
336
  - If `E2` is a non-static data member and the type of `E1` is “*cq1 vq1*
337
  `X`”, and the type of `E2` is “*cq2 vq2* `T`”, the expression
338
- designates the named member of the object designated by the first
339
- expression. If `E1` is an lvalue, then `E1.E2` is an lvalue; otherwise
340
- `E1.E2` is an xvalue. Let the notation *vq12* stand for the “union” of
341
- *vq1* and *vq2*; that is, if *vq1* or *vq2* is `volatile`, then *vq12*
342
- is `volatile`. Similarly, let the notation *cq12* stand for the
343
- “union” of *cq1* and *cq2*; that is, if *cq1* or *cq2* is `const`,
344
- then *cq12* is `const`. If `E2` is declared to be a `mutable` member,
345
- then the type of `E1.E2` is “*vq12* `T`”. If `E2` is not declared to
346
- be a `mutable` member, then the type of `E1.E2` is “*cq12* *vq12*
347
- `T`”.
348
  - If `E2` is a (possibly overloaded) member function, function overload
349
- resolution ([[over.match]]) is used to determine whether `E1.E2`
350
- refers to a static or a non-static member function.
351
- - If it refers to a static member function and the type of `E2` is
352
- “function of parameter-type-list returning `T`”, then `E1.E2` is an
353
- lvalue; the expression designates the static member function. The
354
- type of `E1.E2` is the same type as that of `E2`, namely “function
355
- of parameter-type-list returning `T`”.
356
- - Otherwise, if `E1.E2` refers to a non-static member function and the
357
- type of `E2` is “function of parameter-type-list *cv*
358
- *ref-qualifier*ₒₚₜ returning `T`”, then `E1.E2` is a prvalue. The
359
- expression designates a non-static member function. The expression
360
- can be used only as the left-hand operand of a member function
361
- call ([[class.mfct]]). \[*Note 3*: Any redundant set of parentheses
362
- surrounding the expression is ignored (
363
- [[expr.prim]]). — *end note*] The type of `E1.E2` is “function of
364
- parameter-type-list *cv* returning `T`”.
365
  - If `E2` is a nested type, the expression `E1.E2` is ill-formed.
366
  - If `E2` is a member enumerator and the type of `E2` is `T`, the
367
  expression `E1.E2` is a prvalue. The type of `E1.E2` is `T`.
368
 
369
  If `E2` is a non-static data member or a non-static member function, the
370
  program is ill-formed if the class of which `E2` is directly a member is
371
- an ambiguous base ([[class.member.lookup]]) of the naming class (
372
- [[class.access.base]]) of `E2`.
373
 
374
- [*Note 4*: The program is also ill-formed if the naming class is an
375
  ambiguous base of the class type of the object expression; see 
376
  [[class.access.base]]. — *end note*]
377
 
378
- ### Increment and decrement <a id="expr.post.incr">[[expr.post.incr]]</a>
379
 
380
  The value of a postfix `++` expression is the value of its operand.
381
 
382
  [*Note 1*: The value obtained is a copy of the original
383
- value — *end note*]
384
 
385
  The operand shall be a modifiable lvalue. The type of the operand shall
386
  be an arithmetic type other than cv `bool`, or a pointer to a complete
387
- object type. The value of the operand object is modified by adding `1`
388
- to it. The value computation of the `++` expression is sequenced before
389
- the modification of the operand object. With respect to an
390
- indeterminately-sequenced function call, the operation of postfix `++`
391
- is a single evaluation.
 
392
 
393
- [*Note 2*: Therefore, a function call shall not intervene between the
394
  lvalue-to-rvalue conversion and the side effect associated with any
395
- single postfix ++ operator. — *end note*]
396
 
397
  The result is a prvalue. The type of the result is the cv-unqualified
398
  version of the type of the operand. If the operand is a bit-field that
399
  cannot represent the incremented value, the resulting value of the
400
  bit-field is *implementation-defined*. See also  [[expr.add]] and 
@@ -404,40 +409,37 @@ The operand of postfix `\dcr` is decremented analogously to the postfix
404
  `++` operator.
405
 
406
  [*Note 3*: For prefix increment and decrement, see 
407
  [[expr.pre.incr]]. — *end note*]
408
 
409
- ### Dynamic cast <a id="expr.dynamic.cast">[[expr.dynamic.cast]]</a>
410
 
411
  The result of the expression `dynamic_cast<T>(v)` is the result of
412
  converting the expression `v` to type `T`. `T` shall be a pointer or
413
- reference to a complete class type, or “pointer to *cv* `void`”. The
414
- `dynamic_cast` operator shall not cast away constness (
415
- [[expr.const.cast]]).
416
 
417
  If `T` is a pointer type, `v` shall be a prvalue of a pointer to
418
  complete class type, and the result is a prvalue of type `T`. If `T` is
419
  an lvalue reference type, `v` shall be an lvalue of a complete class
420
  type, and the result is an lvalue of the type referred to by `T`. If `T`
421
  is an rvalue reference type, `v` shall be a glvalue having a complete
422
  class type, and the result is an xvalue of the type referred to by `T`.
423
 
424
- If the type of `v` is the same as `T`, or it is the same as `T` except
425
- that the class object type in `T` is more cv-qualified than the class
426
- object type in `v`, the result is `v` (converted if necessary).
427
-
428
- If the value of `v` is a null pointer value in the pointer case, the
429
- result is the null pointer value of type `T`.
430
 
431
  If `T` is “pointer to *cv1* `B`” and `v` has type “pointer to *cv2* `D`”
432
  such that `B` is a base class of `D`, the result is a pointer to the
433
- unique `B` subobject of the `D` object pointed to by `v`. Similarly, if
434
- `T` is “reference to *cv1* `B`” and `v` has type *cv2* `D` such that `B`
435
- is a base class of `D`, the result is the unique `B` subobject of the
436
- `D` object referred to by `v`.[^8] In both the pointer and reference
437
- cases, the program is ill-formed if *cv2* has greater cv-qualification
438
- than *cv1* or if `B` is an inaccessible or ambiguous base class of `D`.
 
439
 
440
  [*Example 1*:
441
 
442
  ``` cpp
443
  struct B { };
@@ -447,37 +449,37 @@ void foo(D* dp) {
447
  }
448
  ```
449
 
450
  — *end example*]
451
 
452
- Otherwise, `v` shall be a pointer to or a glvalue of a polymorphic
453
- type ([[class.virtual]]).
454
 
455
- If `T` is “pointer to *cv* `void`”, then the result is a pointer to the
 
 
456
  most derived object pointed to by `v`. Otherwise, a runtime check is
457
  applied to see if the object pointed or referred to by `v` can be
458
  converted to the type pointed or referred to by `T`.
459
 
460
  If `C` is the class type to which `T` points or refers, the runtime
461
  check logically executes as follows:
462
 
463
  - If, in the most derived object pointed (referred) to by `v`, `v`
464
- points (refers) to a `public` base class subobject of a `C` object,
465
- and if only one object of type `C` is derived from the subobject
466
- pointed (referred) to by `v` the result points (refers) to that `C`
467
- object.
468
- - Otherwise, if `v` points (refers) to a `public` base class subobject
469
- of the most derived object, and the type of the most derived object
470
- has a base class, of type `C`, that is unambiguous and `public`, the
471
- result points (refers) to the `C` subobject of the most derived
472
- object.
473
  - Otherwise, the runtime check *fails*.
474
 
475
  The value of a failed cast to pointer type is the null pointer value of
476
  the required result type. A failed cast to reference type throws an
477
- exception ([[except.throw]]) of a type that would match a handler (
478
- [[except.handle]]) of type `std::bad_cast` ([[bad.cast]]).
479
 
480
  [*Example 2*:
481
 
482
  ``` cpp
483
  class A { virtual void f(); };
@@ -498,58 +500,61 @@ class E : public D, public B { };
498
  class F : public E, public D { };
499
  void h() {
500
  F f;
501
  A* ap = &f; // succeeds: finds unique A
502
  D* dp = dynamic_cast<D*>(ap); // fails: yields null; f has two D subobjects
503
- E* ep = (E*)ap; // ill-formed: cast from virtual base
504
  E* ep1 = dynamic_cast<E*>(ap); // succeeds
505
  }
506
  ```
507
 
508
  — *end example*]
509
 
510
- [*Note 1*: [[class.cdtor]] describes the behavior of a `dynamic_cast`
511
- applied to an object under construction or destruction. — *end note*]
 
512
 
513
- ### Type identification <a id="expr.typeid">[[expr.typeid]]</a>
514
 
515
  The result of a `typeid` expression is an lvalue of static type `const`
516
- `std::type_info` ([[type.info]]) and dynamic type `const`
517
- `std::type_info` or `const` *name* where *name* is an
518
- *implementation-defined* class publicly derived from `std::type_info`
519
- which preserves the behavior described in  [[type.info]].[^9] The
520
- lifetime of the object referred to by the lvalue extends to the end of
521
- the program. Whether or not the destructor is called for the
522
- `std::type_info` object at the end of the program is unspecified.
523
 
524
- When `typeid` is applied to a glvalue expression whose type is a
525
- polymorphic class type ([[class.virtual]]), the result refers to a
526
- `std::type_info` object representing the type of the most derived
527
- object ([[intro.object]]) (that is, the dynamic type) to which the
528
- glvalue refers. If the glvalue expression is obtained by applying the
529
- unary `*` operator to a pointer[^10] and the pointer is a null pointer
530
- value ([[conv.ptr]]), the `typeid` expression throws an exception (
531
- [[except.throw]]) of a type that would match a handler of type
532
- `std::bad_typeid` exception ([[bad.typeid]]).
533
 
534
  When `typeid` is applied to an expression other than a glvalue of a
535
  polymorphic class type, the result refers to a `std::type_info` object
536
- representing the static type of the expression. Lvalue-to-rvalue (
537
- [[conv.lval]]), array-to-pointer ([[conv.array]]), and
538
- function-to-pointer ([[conv.func]]) conversions are not applied to the
539
- expression. If the expression is a prvalue, the temporary
540
- materialization conversion ([[conv.rval]]) is applied. The expression
541
- is an unevaluated operand (Clause  [[expr]]).
542
 
543
  When `typeid` is applied to a *type-id*, the result refers to a
544
  `std::type_info` object representing the type of the *type-id*. If the
545
  type of the *type-id* is a reference to a possibly cv-qualified type,
546
  the result of the `typeid` expression refers to a `std::type_info`
547
  object representing the cv-unqualified referenced type. If the type of
548
  the *type-id* is a class type or a reference to a class type, the class
549
  shall be completely-defined.
550
 
 
 
 
551
  If the type of the expression or *type-id* is a cv-qualified type, the
552
  result of the `typeid` expression refers to a `std::type_info` object
553
  representing the cv-unqualified type.
554
 
555
  [*Example 1*:
@@ -565,32 +570,32 @@ typeid(D) == typeid(d2); // yields true
565
  typeid(D) == typeid(const D&); // yields true
566
  ```
567
 
568
  — *end example*]
569
 
570
- If the header `<typeinfo>` ([[type.info]]) is not included prior to a
571
- use of `typeid`, the program is ill-formed.
572
 
573
- [*Note 1*: [[class.cdtor]] describes the behavior of `typeid` applied
574
- to an object under construction or destruction. — *end note*]
575
 
576
- ### Static cast <a id="expr.static.cast">[[expr.static.cast]]</a>
577
 
578
  The result of the expression `static_cast<T>(v)` is the result of
579
  converting the expression `v` to type `T`. If `T` is an lvalue reference
580
  type or an rvalue reference to function type, the result is an lvalue;
581
  if `T` is an rvalue reference to object type, the result is an xvalue;
582
  otherwise, the result is a prvalue. The `static_cast` operator shall not
583
- cast away constness ([[expr.const.cast]]).
584
 
585
  An lvalue of type “*cv1* `B`”, where `B` is a class type, can be cast to
586
- type “reference to *cv2* `D`”, where `D` is a class derived (Clause 
587
- [[class.derived]]) from `B`, if *cv2* is the same cv-qualification as,
588
- or greater cv-qualification than, *cv1*. If `B` is a virtual base class
589
- of `D` or a base class of a virtual base class of `D`, or if no valid
590
- standard conversion from “pointer to `D`” to “pointer to `B`” exists (
591
- [[conv.ptr]]), the program is ill-formed. An xvalue of type “*cv1* `B`”
592
  can be cast to type “rvalue reference to *cv2* `D`” with the same
593
  constraints as for an lvalue of type “*cv1* `B`”. If the object of type
594
  “*cv1* `B`” is actually a base class subobject of an object of type `D`,
595
  the result refers to the enclosing object of type `D`. Otherwise, the
596
  behavior is undefined.
@@ -601,65 +606,70 @@ behavior is undefined.
601
  struct B { };
602
  struct D : public B { };
603
  D d;
604
  B &br = d;
605
 
606
- static_cast<D&>(br); // produces lvalue to the original d object
607
  ```
608
 
609
  — *end example*]
610
 
611
  An lvalue of type “*cv1* `T1`” can be cast to type “rvalue reference to
612
- *cv2* `T2`” if “*cv2* `T2`” is reference-compatible with “*cv1* `T1`” (
613
- [[dcl.init.ref]]). If the value is not a bit-field, the result refers to
614
  the object or the specified base class subobject thereof; otherwise, the
615
- lvalue-to-rvalue conversion ([[conv.lval]]) is applied to the bit-field
616
  and the resulting prvalue is used as the *expression* of the
617
- `static_cast` for the remainder of this section. If `T2` is an
618
- inaccessible (Clause  [[class.access]]) or ambiguous (
619
- [[class.member.lookup]]) base class of `T1`, a program that necessitates
620
- such a cast is ill-formed.
621
 
622
- An expression `e` can be explicitly converted to a type `T` if there is
623
- an implicit conversion sequence ([[over.best.ics]]) from `e` to `T`, or
624
- if overload resolution for a direct-initialization ([[dcl.init]]) of an
625
- object or reference of type `T` from `e` would find at least one viable
626
- function ([[over.match.viable]]). If `T` is a reference type, the
627
- effect is the same as performing the declaration and initialization
 
 
 
628
 
629
  ``` cpp
630
- T t(e);
631
  ```
632
 
633
- for some invented temporary variable `t` ([[dcl.init]]) and then using
634
- the temporary variable as the result of the conversion. Otherwise, the
635
- result object is direct-initialized from `e`.
636
 
637
  [*Note 1*: The conversion is ill-formed when attempting to convert an
638
  expression of class type to an inaccessible or ambiguous base
639
  class. — *end note*]
640
 
 
 
 
 
641
  Otherwise, the `static_cast` shall perform one of the conversions listed
642
  below. No other conversion shall be performed explicitly using a
643
  `static_cast`.
644
 
645
  Any expression can be explicitly converted to type cv `void`, in which
646
- case it becomes a discarded-value expression (Clause  [[expr]]).
647
 
648
- [*Note 2*: However, if the value is in a temporary object (
649
- [[class.temporary]]), the destructor for that object is not executed
650
  until the usual time, and the value of the object is preserved for the
651
  purpose of executing the destructor. — *end note*]
652
 
653
- The inverse of any standard conversion sequence (Clause  [[conv]]) not
654
- containing an lvalue-to-rvalue ([[conv.lval]]), array-to-pointer (
655
- [[conv.array]]), function-to-pointer ([[conv.func]]), null pointer (
656
- [[conv.ptr]]), null member pointer ([[conv.mem]]), boolean (
657
- [[conv.bool]]), or function pointer ([[conv.fctptr]]) conversion, can
658
- be performed explicitly using `static_cast`. A program is ill-formed if
659
- it uses `static_cast` to perform the inverse of an ill-formed standard
660
- conversion sequence.
661
 
662
  [*Example 2*:
663
 
664
  ``` cpp
665
  struct B { };
@@ -670,63 +680,68 @@ void f() {
670
  }
671
  ```
672
 
673
  — *end example*]
674
 
675
- The lvalue-to-rvalue ([[conv.lval]]), array-to-pointer (
676
- [[conv.array]]), and function-to-pointer ([[conv.func]]) conversions
677
- are applied to the operand. Such a `static_cast` is subject to the
678
- restriction that the explicit conversion does not cast away constness (
679
- [[expr.const.cast]]), and the following additional rules for specific
680
- cases:
681
 
682
- A value of a scoped enumeration type ([[dcl.enum]]) can be explicitly
683
- converted to an integral type. When that type is cv `bool`, the
684
- resulting value is `false` if the original value is zero and `true` for
685
- all other values. For the remaining integral types, the value is
686
- unchanged if the original value can be represented by the specified
687
- type. Otherwise, the resulting value is unspecified. A value of a scoped
688
- enumeration type can also be explicitly converted to a floating-point
689
- type; the result is the same as that of converting from the original
690
- value to the floating-point type.
691
 
692
  A value of integral or enumeration type can be explicitly converted to a
693
- complete enumeration type. The value is unchanged if the original value
694
- is within the range of the enumeration values ([[dcl.enum]]).
695
- Otherwise, the behavior is undefined. A value of floating-point type can
696
- also be explicitly converted to an enumeration type. The resulting value
697
- is the same as converting the original value to the underlying type of
698
- the enumeration ([[conv.fpint]]), and subsequently to the enumeration
699
- type.
 
 
 
700
 
701
  A prvalue of type “pointer to *cv1* `B`”, where `B` is a class type, can
702
  be converted to a prvalue of type “pointer to *cv2* `D`”, where `D` is a
703
- class derived (Clause  [[class.derived]]) from `B`, if *cv2* is the same
704
  cv-qualification as, or greater cv-qualification than, *cv1*. If `B` is
705
  a virtual base class of `D` or a base class of a virtual base class of
706
  `D`, or if no valid standard conversion from “pointer to `D`” to
707
- “pointer to `B`” exists ([[conv.ptr]]), the program is ill-formed. The
708
- null pointer value ([[conv.ptr]]) is converted to the null pointer
709
  value of the destination type. If the prvalue of type “pointer to *cv1*
710
  `B`” points to a `B` that is actually a subobject of an object of type
711
  `D`, the resulting pointer points to the enclosing object of type `D`.
712
  Otherwise, the behavior is undefined.
713
 
714
  A prvalue of type “pointer to member of `D` of type *cv1* `T`” can be
715
  converted to a prvalue of type “pointer to member of `B` of type *cv2*
716
- `T`”, where `B` is a base class (Clause  [[class.derived]]) of `D`, if
717
- *cv2* is the same cv-qualification as, or greater cv-qualification than,
718
- *cv1*.[^11] If no valid standard conversion from “pointer to member of
719
- `B` of type `T`” to “pointer to member of `D` of type `T`” exists (
720
- [[conv.mem]]), the program is ill-formed. The null member pointer
721
- value ([[conv.mem]]) is converted to the null member pointer value of
722
- the destination type. If class `B` contains the original member, or is a
723
- base or derived class of the class containing the original member, the
724
- resulting pointer to member points to the original member. Otherwise,
725
- the behavior is undefined.
726
 
727
- [*Note 3*: Although class `B` need not contain the original member, the
 
 
 
 
 
 
 
 
 
 
 
 
 
728
  dynamic type of the object with which indirection through the pointer to
729
  member is performed must contain the original member; see 
730
  [[expr.mptr.oper]]. — *end note*]
731
 
732
  A prvalue of type “pointer to *cv1* `void`” can be converted to a
@@ -735,11 +750,11 @@ prvalue of type “pointer to *cv2* `T`”, where `T` is an object type and
735
  *cv1*. If the original pointer value represents the address `A` of a
736
  byte in memory and `A` does not satisfy the alignment requirement of
737
  `T`, then the resulting pointer value is unspecified. Otherwise, if the
738
  original pointer value points to an object *a*, and there is an object
739
  *b* of type `T` (ignoring cv-qualification) that is
740
- pointer-interconvertible ([[basic.compound]]) with *a*, the result is a
741
  pointer to *b*. Otherwise, the pointer value is unchanged by the
742
  conversion.
743
 
744
  [*Example 3*:
745
 
@@ -749,34 +764,35 @@ const T* p2 = static_cast<const T*>(static_cast<void*>(p1));
749
  bool b = p1 == p2; // b will have the value true.
750
  ```
751
 
752
  — *end example*]
753
 
754
- ### Reinterpret cast <a id="expr.reinterpret.cast">[[expr.reinterpret.cast]]</a>
755
 
756
  The result of the expression `reinterpret_cast<T>(v)` is the result of
757
  converting the expression `v` to type `T`. If `T` is an lvalue reference
758
  type or an rvalue reference to function type, the result is an lvalue;
759
  if `T` is an rvalue reference to object type, the result is an xvalue;
760
- otherwise, the result is a prvalue and the lvalue-to-rvalue (
761
- [[conv.lval]]), array-to-pointer ([[conv.array]]), and
762
- function-to-pointer ([[conv.func]]) standard conversions are performed
763
- on the expression `v`. Conversions that can be performed explicitly
764
- using `reinterpret_cast` are listed below. No other conversion can be
765
- performed explicitly using `reinterpret_cast`.
766
 
767
- The `reinterpret_cast` operator shall not cast away constness (
768
- [[expr.const.cast]]). An expression of integral, enumeration, pointer,
769
- or pointer-to-member type can be explicitly converted to its own type;
770
- such a cast yields the value of its operand.
771
 
772
  [*Note 1*: The mapping performed by `reinterpret_cast` might, or might
773
  not, produce a representation different from the original
774
  value. — *end note*]
775
 
776
  A pointer can be explicitly converted to any integral type large enough
777
- to hold it. The mapping function is *implementation-defined*.
 
778
 
779
  [*Note 2*: It is intended to be unsurprising to those who know the
780
  addressing structure of the underlying machine. — *end note*]
781
 
782
  A value of type `std::nullptr_t` can be converted to an integral type;
@@ -798,23 +814,23 @@ value. — *end note*]
798
 
799
  A function pointer can be explicitly converted to a function pointer of
800
  a different type.
801
 
802
  [*Note 5*: The effect of calling a function through a pointer to a
803
- function type ([[dcl.fct]]) that is not the same as the type used in
804
- the definition of the function is undefined. — *end note*]
805
 
806
  Except that converting a prvalue of type “pointer to `T1`” to the type
807
  “pointer to `T2`” (where `T1` and `T2` are function types) and back to
808
  its original type yields the original pointer value, the result of such
809
  a pointer conversion is unspecified.
810
 
811
  [*Note 6*: See also  [[conv.ptr]] for more details of pointer
812
  conversions. — *end note*]
813
 
814
  An object pointer can be explicitly converted to an object pointer of a
815
- different type.[^12] When a prvalue `v` of object pointer type is
816
  converted to the object pointer type “pointer to cv `T`”, the result is
817
  `static_cast<cv T*>(static_cast<cv~void*>(v))`.
818
 
819
  [*Note 7*: Converting a prvalue of type “pointer to `T1`” to the type
820
  “pointer to `T2`” (where `T1` and `T2` are object types and where the
@@ -827,76 +843,72 @@ conditionally-supported. The meaning of such a conversion is
827
  *implementation-defined*, except that if an implementation supports
828
  conversions in both directions, converting a prvalue of one type to the
829
  other type and back, possibly with different cv-qualification, shall
830
  yield the original pointer value.
831
 
832
- The null pointer value ([[conv.ptr]]) is converted to the null pointer
833
- value of the destination type.
834
 
835
  [*Note 8*: A null pointer constant of type `std::nullptr_t` cannot be
836
  converted to a pointer type, and a null pointer constant of integral
837
  type is not necessarily converted to a null pointer
838
  value. — *end note*]
839
 
840
  A prvalue of type “pointer to member of `X` of type `T1`” can be
841
  explicitly converted to a prvalue of a different type “pointer to member
842
  of `Y` of type `T2`” if `T1` and `T2` are both function types or both
843
- object types.[^13] The null member pointer value ([[conv.mem]]) is
844
  converted to the null member pointer value of the destination type. The
845
  result of this conversion is unspecified, except in the following cases:
846
 
847
- - converting a prvalue of type “pointer to member function” to a
848
- different pointer to member function type and back to its original
849
- type yields the original pointer to member value.
850
- - converting a prvalue of type “pointer to data member of `X` of type
851
  `T1`” to the type “pointer to data member of `Y` of type `T2`” (where
852
  the alignment requirements of `T2` are no stricter than those of `T1`)
853
- and back to its original type yields the original pointer to member
854
  value.
855
 
856
- A glvalue expression of type `T1` can be cast to the type “reference to
857
- `T2`” if an expression of type “pointer to `T1`” can be explicitly
858
- converted to the type “pointer to `T2`” using a `reinterpret_cast`. The
859
- result refers to the same object as the source glvalue, but with the
860
- specified type.
 
 
861
 
862
- [*Note 9*: That is, for lvalues, a reference cast
863
- `reinterpret_cast<T&>(x)` has the same effect as the conversion
864
- `*reinterpret_cast<T*>(&x)` with the built-in `&` and `*` operators (and
865
- similarly for `reinterpret_cast<T&&>(x)`). — *end note*]
866
-
867
- No temporary is created, no copy is made, and constructors (
868
- [[class.ctor]]) or conversion functions ([[class.conv]]) are not
869
- called.[^14]
870
-
871
- ### Const cast <a id="expr.const.cast">[[expr.const.cast]]</a>
872
 
873
  The result of the expression `const_cast<T>(v)` is of type `T`. If `T`
874
  is an lvalue reference to object type, the result is an lvalue; if `T`
875
  is an rvalue reference to object type, the result is an xvalue;
876
- otherwise, the result is a prvalue and the lvalue-to-rvalue (
877
- [[conv.lval]]), array-to-pointer ([[conv.array]]), and
878
- function-to-pointer ([[conv.func]]) standard conversions are performed
879
- on the expression `v`. Conversions that can be performed explicitly
880
- using `const_cast` are listed below. No other conversion shall be
881
- performed explicitly using `const_cast`.
882
 
883
- [*Note 1*: Subject to the restrictions in this section, an expression
884
  may be cast to its own type using a `const_cast`
885
  operator. — *end note*]
886
 
887
- For two similar types `T1` and `T2` ([[conv.qual]]), a prvalue of type
888
- `T1` may be explicitly converted to the type `T2` using a `const_cast`.
889
- The result of a `const_cast` refers to the original entity.
 
 
890
 
891
  [*Example 1*:
892
 
893
  ``` cpp
894
  typedef int *A[3]; // array of 3 pointer to int
895
  typedef const int *const CA[3]; // array of 3 const pointer to const int
896
 
897
- CA &&r = A{}; // OK, reference binds to temporary array object after qualification conversion to type CA
 
898
  A &&r1 = const_cast<A>(CA{}); // error: temporary array decayed to pointer
899
  A &&r2 = const_cast<A&&>(CA{}); // OK
900
  ```
901
 
902
  — *end example*]
@@ -912,26 +924,25 @@ then the following conversions can also be made:
912
  - if `T1` is a class type, a prvalue of type `T1` can be explicitly
913
  converted to an xvalue of type `T2` using the cast `const_cast<T2&&>`.
914
 
915
  The result of a reference `const_cast` refers to the original object if
916
  the operand is a glvalue and to the result of applying the temporary
917
- materialization conversion ([[conv.rval]]) otherwise.
918
 
919
- A null pointer value ([[conv.ptr]]) is converted to the null pointer
920
- value of the destination type. The null member pointer value (
921
- [[conv.mem]]) is converted to the null member pointer value of the
922
  destination type.
923
 
924
  [*Note 2*: Depending on the type of the object, a write operation
925
  through the pointer, lvalue or pointer to data member resulting from a
926
- `const_cast` that casts away a const-qualifier[^15] may produce
927
- undefined behavior ([[dcl.type.cv]]). — *end note*]
928
 
929
  A conversion from a type `T1` to a type `T2` *casts away constness* if
930
- `T1` and `T2` are different, there is a cv-decomposition (
931
- [[conv.qual]]) of `T1` yielding *n* such that `T2` has a
932
- cv-decomposition of the form
933
 
934
  and there is no qualification conversion that converts `T1` to
935
 
936
  Casting from an lvalue of type `T1` to an lvalue of type `T2` using an
937
  lvalue reference cast or casting from an expression of type `T1` to an
 
1
+ ### Postfix expressions <a id="expr.post">[[expr.post]]</a>
2
 
3
  Postfix expressions group left-to-right.
4
 
5
  ``` bnf
6
  postfix-expression:
 
9
  postfix-expression '(' expression-listₒₚₜ ')'
10
  simple-type-specifier '(' expression-listₒₚₜ ')'
11
  typename-specifier '(' expression-listₒₚₜ ')'
12
  simple-type-specifier braced-init-list
13
  typename-specifier braced-init-list
14
+ postfix-expression '.' 'template'ₒₚₜ id-expression
15
+ postfix-expression '->' 'template'ₒₚₜ id-expression
 
 
16
  postfix-expression '++'
17
  postfix-expression '-{-}'
18
+ dynamic_cast '<' type-id '>' '(' expression ')'
19
+ static_cast '<' type-id '>' '(' expression ')'
20
+ reinterpret_cast '<' type-id '>' '(' expression ')'
21
+ const_cast '<' type-id '>' '(' expression ')'
22
+ typeid '(' expression ')'
23
+ typeid '(' type-id ')'
24
  ```
25
 
26
  ``` bnf
27
  expression-list:
28
  initializer-list
29
  ```
30
 
 
 
 
 
 
 
 
 
31
  [*Note 1*: The `>` token following the *type-id* in a `dynamic_cast`,
32
  `static_cast`, `reinterpret_cast`, or `const_cast` may be the product of
33
+ replacing a `>{>}` token by two consecutive `>` tokens
34
+ [[temp.names]]. — *end note*]
35
 
36
+ #### Subscripting <a id="expr.sub">[[expr.sub]]</a>
37
 
38
  A postfix expression followed by an expression in square brackets is a
39
  postfix expression. One of the expressions shall be a glvalue of type
40
  “array of `T`” or a prvalue of type “pointer to `T`” and the other shall
41
  be a prvalue of unscoped enumeration or integral type. The result is of
42
  type “`T`”. The type “`T`” shall be a completely-defined object
43
+ type.[^11] The expression `E1[E2]` is identical (by definition) to
44
+ `*((E1)+(E2))`, except that in the case of an array operand, the result
45
+ is an lvalue if that operand is an lvalue and an xvalue otherwise. The
46
+ expression `E1` is sequenced before the expression `E2`.
47
 
48
+ [*Note 1*: A comma expression [[expr.comma]] appearing as the
49
+ *expr-or-braced-init-list* of a subscripting expression is deprecated;
50
+ see [[depr.comma.subscript]]. — *end note*]
51
 
52
+ [*Note 2*: Despite its asymmetric appearance, subscripting is a
53
+ commutative operation except for sequencing. See  [[expr.unary]] and 
54
+ [[expr.add]] for details of `*` and `+` and  [[dcl.array]] for details
55
+ of array types. — *end note*]
56
 
57
  A *braced-init-list* shall not be used with the built-in subscript
58
  operator.
59
 
60
+ #### Function call <a id="expr.call">[[expr.call]]</a>
61
 
62
  A function call is a postfix expression followed by parentheses
63
  containing a possibly empty, comma-separated list of
64
  *initializer-clause*s which constitute the arguments to the function.
65
+
66
+ [*Note 1*: If the postfix expression is a function or member function
67
+ name, the appropriate function and the validity of the call are
68
+ determined according to the rules in  [[over.match]]. — *end note*]
69
+
70
  The postfix expression shall have function type or function pointer
71
  type. For a call to a non-member function or to a static member
72
+ function, the postfix expression shall either be an lvalue that refers
73
+ to a function (in which case the function-to-pointer standard conversion
74
+ [[conv.func]] is suppressed on the postfix expression), or have function
75
+ pointer type.
 
 
 
 
 
 
 
 
 
 
76
 
77
+ For a call to a non-static member function, the postfix expression shall
78
+ be an implicit ([[class.mfct.non-static]], [[class.static]]) or
79
+ explicit class member access [[expr.ref]] whose *id-expression* is a
80
+ function member name, or a pointer-to-member expression
81
+ [[expr.mptr.oper]] selecting a function member; the call is as a member
82
+ of the class object referred to by the object expression. In the case of
83
+ an implicit class member access, the implied object is the one pointed
84
+ to by `this`.
85
+
86
+ [*Note 2*: A member function call of the form `f()` is interpreted as
87
  `(*this).f()` (see  [[class.mfct.non-static]]). — *end note*]
88
 
89
+ If the selected function is non-virtual, or if the *id-expression* in
90
+ the class member access expression is a *qualified-id*, that function is
91
+ called. Otherwise, its final overrider [[class.virtual]] in the dynamic
92
+ type of the object expression is called; such a call is referred to as a
 
 
 
93
  *virtual function call*.
94
 
95
+ [*Note 3*: The dynamic type is the type of the object referred to by
96
  the current value of the object expression. [[class.cdtor]] describes
97
  the behavior of virtual function calls when the object expression refers
98
  to an object under construction or destruction. — *end note*]
99
 
100
+ [*Note 4*: If a function or member function name is used, and name
101
+ lookup [[basic.lookup]] does not find a declaration of that name, the
102
  program is ill-formed. No function is implicitly declared by such a
103
  call. — *end note*]
104
 
105
+ If the *postfix-expression* names a destructor or pseudo-destructor
106
+ [[expr.prim.id.dtor]], the type of the function call expression is
107
+ `void`; otherwise, the type of the function call expression is the
108
+ return type of the statically chosen function (i.e., ignoring the
109
+ `virtual` keyword), even if the type of the function actually called is
110
+ different. This return type shall be an object type, a reference type or
111
+ cv `void`. If the *postfix-expression* names a pseudo-destructor (in
112
+ which case the *postfix-expression* is a possibly-parenthesized class
113
+ member access), the function call destroys the object of scalar type
114
+ denoted by the object expression of the class member access (
115
+ [[expr.ref]], [[basic.life]]).
116
+
117
+ Calling a function through an expression whose function type is
118
+ different from the function type of the called function’s definition
119
+ results in undefined behavior.
120
+
121
+ When a function is called, each parameter [[dcl.fct]] is initialized (
122
+ [[dcl.init]], [[class.copy.ctor]]) with its corresponding argument. If
123
+ there is no corresponding argument, the default argument for the
124
+ parameter is used.
125
+
126
+ [*Example 1*:
127
+
128
+ ``` cpp
129
+ template<typename ...T> int f(int n = 0, T ...t);
130
+ int x = f<int>(); // error: no argument for second function parameter
131
+ ```
132
+
133
+ — *end example*]
134
+
135
+ If the function is a non-static member function, the `this` parameter of
136
+ the function [[class.this]] is initialized with a pointer to the object
137
+ of the call, converted as if by an explicit type conversion
138
+ [[expr.cast]].
139
+
140
+ [*Note 5*: There is no access or ambiguity checking on this conversion;
141
  the access checking and disambiguation are done as part of the (possibly
142
+ implicit) class member access operator. See  [[class.member.lookup]],
143
  [[class.access.base]], and  [[expr.ref]]. — *end note*]
144
 
145
+ When a function is called, the type of any parameter shall not be a
146
+ class type that is either incomplete or abstract.
147
 
148
+ [*Note 6*: This still allows a parameter to be a pointer or reference
149
+ to such a type. However, it prevents a passed-by-value parameter to have
150
+ an incomplete or abstract class type. — *end note*]
151
 
152
  It is *implementation-defined* whether the lifetime of a parameter ends
153
  when the function in which it is defined returns or at the end of the
154
  enclosing full-expression. The initialization and destruction of each
155
  parameter occurs within the context of the calling function.
156
 
157
+ [*Example 2*: The access of the constructor, conversion functions or
158
  destructor is checked at the point of call in the calling function. If a
159
  constructor or destructor for a function parameter throws an exception,
160
  the search for a handler starts in the scope of the calling function; in
161
+ particular, if the function called has a *function-try-block*
162
+ [[except.pre]] with a handler that could handle the exception, this
163
+ handler is not considered. — *end example*]
164
 
165
  The *postfix-expression* is sequenced before each *expression* in the
166
  *expression-list* and any default argument. The initialization of a
167
  parameter, including every associated value computation and side effect,
168
  is indeterminately sequenced with respect to that of any other
169
  parameter.
170
 
171
+ [*Note 7*: All side effects of argument evaluations are sequenced
172
  before the function is entered (see 
173
  [[intro.execution]]). — *end note*]
174
 
175
+ [*Example 3*:
176
 
177
  ``` cpp
178
  void f() {
179
  std::string s = "but I have heard it works even if you don't believe in it";
180
  s.replace(0, 4, "").replace(s.find("even"), 4, "only").replace(s.find(" don't"), 6, "");
 
182
  }
183
  ```
184
 
185
  — *end example*]
186
 
187
+ [*Note 8*: If an operator function is invoked using operator notation,
188
  argument evaluation is sequenced as specified for the built-in operator;
189
  see  [[over.match.oper]]. — *end note*]
190
 
191
+ [*Example 4*:
192
 
193
  ``` cpp
194
  struct S {
195
  S(int);
196
  };
 
204
  [[expr.shift]]), but it is unspecified whether the value of `j` is 1 or
205
  2.
206
 
207
  — *end example*]
208
 
209
+ The result of a function call is the result of the possibly-converted
210
+ operand of the `return` statement [[stmt.return]] that transferred
211
+ control out of the called function (if any), except in a virtual
212
+ function call if the return type of the final overrider is different
213
+ from the return type of the statically chosen function, the value
214
+ returned from the final overrider is converted to the return type of the
215
+ statically chosen function.
216
 
217
+ [*Note 9*: A function can change the values of its non-const
218
  parameters, but these changes cannot affect the values of the arguments
219
+ except where a parameter is of a reference type [[dcl.ref]]; if the
220
  reference is to a const-qualified type, `const_cast` is required to be
221
  used to cast away the constness in order to modify the argument’s value.
222
  Where a parameter is of `const` reference type a temporary object is
223
+ introduced if needed ([[dcl.type]], [[lex.literal]], [[lex.string]],
224
+ [[dcl.array]], [[class.temporary]]). In addition, it is possible to
225
  modify the values of non-constant objects through pointer
226
  parameters. — *end note*]
227
 
228
  A function can be declared to accept fewer arguments (by declaring
229
+ default arguments [[dcl.fct.default]]) or more arguments (by using the
230
+ ellipsis, `...`, or a function parameter pack [[dcl.fct]]) than the
231
+ number of parameters in the function definition [[dcl.fct.def]].
232
 
233
+ [*Note 10*: This implies that, except where the ellipsis (`...`) or a
234
  function parameter pack is used, a parameter is available for each
235
  argument. — *end note*]
236
 
237
  When there is no parameter for a given argument, the argument is passed
238
  in such a way that the receiving function can obtain the value of the
239
+ argument by invoking `va_arg` [[support.runtime]].
240
 
241
+ [*Note 11*: This paragraph does not apply to arguments passed to a
242
  function parameter pack. Function parameter packs are expanded during
243
+ template instantiation [[temp.variadic]], thus each such argument has a
244
+ corresponding parameter when a function template specialization is
245
  actually called. — *end note*]
246
 
247
+ The lvalue-to-rvalue [[conv.lval]], array-to-pointer [[conv.array]], and
248
+ function-to-pointer [[conv.func]] standard conversions are performed on
249
+ the argument expression. An argument that has type cv `std::nullptr_t`
250
+ is converted to type `void*` [[conv.ptr]]. After these conversions, if
251
+ the argument does not have arithmetic, enumeration, pointer,
252
+ pointer-to-member, or class type, the program is ill-formed. Passing a
253
+ potentially-evaluated argument of a scoped enumeration type or of a
254
+ class type [[class]] having an eligible non-trivial copy constructor, an
255
+ eligible non-trivial move constructor, or a non-trivial destructor
256
+ [[special]], with no corresponding parameter, is conditionally-supported
257
+ with *implementation-defined* semantics. If the argument has integral or
258
+ enumeration type that is subject to the integral promotions
259
+ [[conv.prom]], or a floating-point type that is subject to the
260
+ floating-point promotion [[conv.fpprom]], the value of the argument is
261
+ converted to the promoted type before the call. These promotions are
262
  referred to as the *default argument promotions*.
263
 
264
+ Recursive calls are permitted, except to the `main` function
265
+ [[basic.start.main]].
266
 
267
  A function call is an lvalue if the result type is an lvalue reference
268
  type or an rvalue reference to function type, an xvalue if the result
269
  type is an rvalue reference to object type, and a prvalue otherwise.
270
 
271
+ #### Explicit type conversion (functional notation) <a id="expr.type.conv">[[expr.type.conv]]</a>
272
 
273
+ A *simple-type-specifier* [[dcl.type.simple]] or *typename-specifier*
274
+ [[temp.res]] followed by a parenthesized optional *expression-list* or
275
+ by a *braced-init-list* (the initializer) constructs a value of the
276
+ specified type given the initializer. If the type is a placeholder for a
277
+ deduced class type, it is replaced by the return type of the function
278
+ selected by overload resolution for class template deduction
279
+ [[over.match.class.deduct]] for the remainder of this subclause.
 
280
 
281
  If the initializer is a parenthesized single expression, the type
282
+ conversion expression is equivalent to the corresponding cast expression
283
+ [[expr.cast]]. Otherwise, if the type is cv `void` and the initializer
284
+ is `()` or `{}` (after pack expansion, if any), the expression is a
285
  prvalue of the specified type that performs no initialization.
286
  Otherwise, the expression is a prvalue of the specified type whose
287
+ result object is direct-initialized [[dcl.init]] with the initializer.
288
+ If the initializer is a parenthesized optional *expression-list*, the
289
+ specified type shall not be an array type.
290
 
291
+ #### Class member access <a id="expr.ref">[[expr.ref]]</a>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
292
 
293
  A postfix expression followed by a dot `.` or an arrow `->`, optionally
294
+ followed by the keyword `template` [[temp.names]], and then followed by
295
+ an *id-expression*, is a postfix expression. The postfix expression
296
+ before the dot or arrow is evaluated;[^12] the result of that
297
+ evaluation, together with the *id-expression*, determines the result of
298
+ the entire postfix expression.
299
+
300
+ For the first option (dot) the first expression shall be a glvalue. For
301
+ the second option (arrow) the first expression shall be a prvalue having
302
+ pointer type. The expression `E1->E2` is converted to the equivalent
303
+ form `(*(E1)).E2`; the remainder of [[expr.ref]] will address only the
304
+ first option (dot).[^13]
305
+
306
+ Abbreviating *postfix-expression*`.`*id-expression* as `E1.E2`, `E1` is
307
+ called the *object expression*. If the object expression is of scalar
308
+ type, `E2` shall name the pseudo-destructor of that same type (ignoring
309
+ cv-qualifications) and `E1.E2` is an lvalue of type “function of ()
310
+ returning `void`”.
311
+
312
+ [*Note 1*: This value can only be used for a notional function call
313
+ [[expr.prim.id.dtor]]. — *end note*]
314
+
315
+ Otherwise, the object expression shall be of class type. The class type
316
+ shall be complete unless the class member access appears in the
317
+ definition of that class.
318
+
319
+ [*Note 2*: If the class is incomplete, lookup in the complete class
320
+ type is required to refer to the same declaration
321
+ [[basic.scope.class]]. — *end note*]
322
+
323
+ The *id-expression* shall name a member of the class or of one of its
324
+ base classes.
325
+
326
+ [*Note 3*: Because the name of a class is inserted in its class scope
327
+ [[class]], the name of a class is also considered a nested member of
328
+ that class. — *end note*]
329
+
330
+ [*Note 4*: [[basic.lookup.classref]] describes how names are looked up
331
  after the `.` and `->` operators. — *end note*]
332
 
333
+ If `E2` is a bit-field, `E1.E2` is a bit-field. The type and value
334
+ category of `E1.E2` are determined as follows. In the remainder of 
335
+ [[expr.ref]], *cq* represents either `const` or the absence of `const`
336
+ and *vq* represents either `volatile` or the absence of `volatile`. *cv*
337
+ represents an arbitrary set of cv-qualifiers, as defined in 
338
+ [[basic.type.qualifier]].
 
339
 
340
  If `E2` is declared to have type “reference to `T`”, then `E1.E2` is an
341
  lvalue; the type of `E1.E2` is `T`. Otherwise, one of the following
342
  rules applies.
343
 
344
  - If `E2` is a static data member and the type of `E2` is `T`, then
345
  `E1.E2` is an lvalue; the expression designates the named member of
346
  the class. The type of `E1.E2` is `T`.
347
  - If `E2` is a non-static data member and the type of `E1` is “*cq1 vq1*
348
  `X`”, and the type of `E2` is “*cq2 vq2* `T`”, the expression
349
+ designates the corresponding member subobject of the object designated
350
+ by the first expression. If `E1` is an lvalue, then `E1.E2` is an
351
+ lvalue; otherwise `E1.E2` is an xvalue. Let the notation *vq12* stand
352
+ for the “union” of *vq1* and *vq2*; that is, if *vq1* or *vq2* is
353
+ `volatile`, then *vq12* is `volatile`. Similarly, let the notation
354
+ *cq12* stand for the “union” of *cq1* and *cq2*; that is, if *cq1* or
355
+ *cq2* is `const`, then *cq12* is `const`. If `E2` is declared to be a
356
+ `mutable` member, then the type of `E1.E2` is “*vq12* `T`”. If `E2` is
357
+ not declared to be a `mutable` member, then the type of `E1.E2` is
358
+ “*cq12* *vq12* `T`”.
359
  - If `E2` is a (possibly overloaded) member function, function overload
360
+ resolution [[over.match]] is used to select the function to which `E2`
361
+ refers. The type of `E1.E2` is the type of `E2` and `E1.E2` refers to
362
+ the function referred to by `E2`.
363
+ - If `E2` refers to a static member function, `E1.E2` is an lvalue.
364
+ - Otherwise (when `E2` refers to a non-static member function),
365
+ `E1.E2` is a prvalue. The expression can be used only as the
366
+ left-hand operand of a member function call [[class.mfct]].
367
+ \[*Note 5*: Any redundant set of parentheses surrounding the
368
+ expression is ignored [[expr.prim.paren]]. *end note*]
 
 
 
 
 
 
 
369
  - If `E2` is a nested type, the expression `E1.E2` is ill-formed.
370
  - If `E2` is a member enumerator and the type of `E2` is `T`, the
371
  expression `E1.E2` is a prvalue. The type of `E1.E2` is `T`.
372
 
373
  If `E2` is a non-static data member or a non-static member function, the
374
  program is ill-formed if the class of which `E2` is directly a member is
375
+ an ambiguous base [[class.member.lookup]] of the naming class
376
+ [[class.access.base]] of `E2`.
377
 
378
+ [*Note 6*: The program is also ill-formed if the naming class is an
379
  ambiguous base of the class type of the object expression; see 
380
  [[class.access.base]]. — *end note*]
381
 
382
+ #### Increment and decrement <a id="expr.post.incr">[[expr.post.incr]]</a>
383
 
384
  The value of a postfix `++` expression is the value of its operand.
385
 
386
  [*Note 1*: The value obtained is a copy of the original
387
+ value. — *end note*]
388
 
389
  The operand shall be a modifiable lvalue. The type of the operand shall
390
  be an arithmetic type other than cv `bool`, or a pointer to a complete
391
+ object type. An operand with volatile-qualified type is deprecated; see 
392
+ [[depr.volatile.type]]. The value of the operand object is modified
393
+ [[defns.access]] by adding `1` to it. The value computation of the `++`
394
+ expression is sequenced before the modification of the operand object.
395
+ With respect to an indeterminately-sequenced function call, the
396
+ operation of postfix `++` is a single evaluation.
397
 
398
+ [*Note 2*: Therefore, a function call cannot intervene between the
399
  lvalue-to-rvalue conversion and the side effect associated with any
400
+ single postfix `++` operator. — *end note*]
401
 
402
  The result is a prvalue. The type of the result is the cv-unqualified
403
  version of the type of the operand. If the operand is a bit-field that
404
  cannot represent the incremented value, the resulting value of the
405
  bit-field is *implementation-defined*. See also  [[expr.add]] and 
 
409
  `++` operator.
410
 
411
  [*Note 3*: For prefix increment and decrement, see 
412
  [[expr.pre.incr]]. — *end note*]
413
 
414
+ #### Dynamic cast <a id="expr.dynamic.cast">[[expr.dynamic.cast]]</a>
415
 
416
  The result of the expression `dynamic_cast<T>(v)` is the result of
417
  converting the expression `v` to type `T`. `T` shall be a pointer or
418
+ reference to a complete class type, or “pointer to cv `void`”. The
419
+ `dynamic_cast` operator shall not cast away constness
420
+ [[expr.const.cast]].
421
 
422
  If `T` is a pointer type, `v` shall be a prvalue of a pointer to
423
  complete class type, and the result is a prvalue of type `T`. If `T` is
424
  an lvalue reference type, `v` shall be an lvalue of a complete class
425
  type, and the result is an lvalue of the type referred to by `T`. If `T`
426
  is an rvalue reference type, `v` shall be a glvalue having a complete
427
  class type, and the result is an xvalue of the type referred to by `T`.
428
 
429
+ If the type of `v` is the same as `T` (ignoring cv-qualifications), the
430
+ result is `v` (converted if necessary).
 
 
 
 
431
 
432
  If `T` is “pointer to *cv1* `B`” and `v` has type “pointer to *cv2* `D`”
433
  such that `B` is a base class of `D`, the result is a pointer to the
434
+ unique `B` subobject of the `D` object pointed to by `v`, or a null
435
+ pointer value if `v` is a null pointer value. Similarly, if `T` is
436
+ “reference to *cv1* `B`” and `v` has type *cv2* `D` such that `B` is a
437
+ base class of `D`, the result is the unique `B` subobject of the `D`
438
+ object referred to by `v`.[^14] In both the pointer and reference cases,
439
+ the program is ill-formed if `B` is an inaccessible or ambiguous base
440
+ class of `D`.
441
 
442
  [*Example 1*:
443
 
444
  ``` cpp
445
  struct B { };
 
449
  }
450
  ```
451
 
452
  — *end example*]
453
 
454
+ Otherwise, `v` shall be a pointer to or a glvalue of a polymorphic type
455
+ [[class.virtual]].
456
 
457
+ If `v` is a null pointer value, the result is a null pointer value.
458
+
459
+ If `T` is “pointer to cv `void`”, then the result is a pointer to the
460
  most derived object pointed to by `v`. Otherwise, a runtime check is
461
  applied to see if the object pointed or referred to by `v` can be
462
  converted to the type pointed or referred to by `T`.
463
 
464
  If `C` is the class type to which `T` points or refers, the runtime
465
  check logically executes as follows:
466
 
467
  - If, in the most derived object pointed (referred) to by `v`, `v`
468
+ points (refers) to a public base class subobject of a `C` object, and
469
+ if only one object of type `C` is derived from the subobject pointed
470
+ (referred) to by `v` the result points (refers) to that `C` object.
471
+ - Otherwise, if `v` points (refers) to a public base class subobject of
472
+ the most derived object, and the type of the most derived object has a
473
+ base class, of type `C`, that is unambiguous and public, the result
474
+ points (refers) to the `C` subobject of the most derived object.
 
 
475
  - Otherwise, the runtime check *fails*.
476
 
477
  The value of a failed cast to pointer type is the null pointer value of
478
  the required result type. A failed cast to reference type throws an
479
+ exception [[except.throw]] of a type that would match a handler
480
+ [[except.handle]] of type `std::bad_cast` [[bad.cast]].
481
 
482
  [*Example 2*:
483
 
484
  ``` cpp
485
  class A { virtual void f(); };
 
500
  class F : public E, public D { };
501
  void h() {
502
  F f;
503
  A* ap = &f; // succeeds: finds unique A
504
  D* dp = dynamic_cast<D*>(ap); // fails: yields null; f has two D subobjects
505
+ E* ep = (E*)ap; // error: cast from virtual base
506
  E* ep1 = dynamic_cast<E*>(ap); // succeeds
507
  }
508
  ```
509
 
510
  — *end example*]
511
 
512
+ [*Note 1*: Subclause [[class.cdtor]] describes the behavior of a
513
+ `dynamic_cast` applied to an object under construction or
514
+ destruction. — *end note*]
515
 
516
+ #### Type identification <a id="expr.typeid">[[expr.typeid]]</a>
517
 
518
  The result of a `typeid` expression is an lvalue of static type `const`
519
+ `std::type_info` [[type.info]] and dynamic type `const` `std::type_info`
520
+ or `const` *name* where *name* is an *implementation-defined* class
521
+ publicly derived from `std::type_info` which preserves the behavior
522
+ described in  [[type.info]].[^15] The lifetime of the object referred to
523
+ by the lvalue extends to the end of the program. Whether or not the
524
+ destructor is called for the `std::type_info` object at the end of the
525
+ program is unspecified.
526
 
527
+ When `typeid` is applied to a glvalue whose type is a polymorphic class
528
+ type [[class.virtual]], the result refers to a `std::type_info` object
529
+ representing the type of the most derived object [[intro.object]] (that
530
+ is, the dynamic type) to which the glvalue refers. If the glvalue is
531
+ obtained by applying the unary `*` operator to a pointer[^16] and the
532
+ pointer is a null pointer value [[basic.compound]], the `typeid`
533
+ expression throws an exception [[except.throw]] of a type that would
534
+ match a handler of type `std::bad_typeid` exception [[bad.typeid]].
 
535
 
536
  When `typeid` is applied to an expression other than a glvalue of a
537
  polymorphic class type, the result refers to a `std::type_info` object
538
+ representing the static type of the expression. Lvalue-to-rvalue
539
+ [[conv.lval]], array-to-pointer [[conv.array]], and function-to-pointer
540
+ [[conv.func]] conversions are not applied to the expression. If the
541
+ expression is a prvalue, the temporary materialization conversion
542
+ [[conv.rval]] is applied. The expression is an unevaluated operand
543
+ [[expr.prop]].
544
 
545
  When `typeid` is applied to a *type-id*, the result refers to a
546
  `std::type_info` object representing the type of the *type-id*. If the
547
  type of the *type-id* is a reference to a possibly cv-qualified type,
548
  the result of the `typeid` expression refers to a `std::type_info`
549
  object representing the cv-unqualified referenced type. If the type of
550
  the *type-id* is a class type or a reference to a class type, the class
551
  shall be completely-defined.
552
 
553
+ [*Note 1*: The *type-id* cannot denote a function type with a
554
+ *cv-qualifier-seq* or a *ref-qualifier* [[dcl.fct]]. — *end note*]
555
+
556
  If the type of the expression or *type-id* is a cv-qualified type, the
557
  result of the `typeid` expression refers to a `std::type_info` object
558
  representing the cv-unqualified type.
559
 
560
  [*Example 1*:
 
570
  typeid(D) == typeid(const D&); // yields true
571
  ```
572
 
573
  — *end example*]
574
 
575
+ If the header `<typeinfo>` is not imported or included prior to a use of
576
+ `typeid`, the program is ill-formed.
577
 
578
+ [*Note 2*: Subclause [[class.cdtor]] describes the behavior of `typeid`
579
+ applied to an object under construction or destruction. — *end note*]
580
 
581
+ #### Static cast <a id="expr.static.cast">[[expr.static.cast]]</a>
582
 
583
  The result of the expression `static_cast<T>(v)` is the result of
584
  converting the expression `v` to type `T`. If `T` is an lvalue reference
585
  type or an rvalue reference to function type, the result is an lvalue;
586
  if `T` is an rvalue reference to object type, the result is an xvalue;
587
  otherwise, the result is a prvalue. The `static_cast` operator shall not
588
+ cast away constness [[expr.const.cast]].
589
 
590
  An lvalue of type “*cv1* `B`”, where `B` is a class type, can be cast to
591
+ type “reference to *cv2* `D`”, where `D` is a class derived
592
+ [[class.derived]] from `B`, if *cv2* is the same cv-qualification as, or
593
+ greater cv-qualification than, *cv1*. If `B` is a virtual base class of
594
+ `D` or a base class of a virtual base class of `D`, or if no valid
595
+ standard conversion from “pointer to `D`” to “pointer to `B`” exists
596
+ [[conv.ptr]], the program is ill-formed. An xvalue of type “*cv1* `B`”
597
  can be cast to type “rvalue reference to *cv2* `D`” with the same
598
  constraints as for an lvalue of type “*cv1* `B`”. If the object of type
599
  “*cv1* `B`” is actually a base class subobject of an object of type `D`,
600
  the result refers to the enclosing object of type `D`. Otherwise, the
601
  behavior is undefined.
 
606
  struct B { };
607
  struct D : public B { };
608
  D d;
609
  B &br = d;
610
 
611
+ static_cast<D&>(br); // produces lvalue denoting the original d object
612
  ```
613
 
614
  — *end example*]
615
 
616
  An lvalue of type “*cv1* `T1`” can be cast to type “rvalue reference to
617
+ *cv2* `T2`” if “*cv2* `T2`” is reference-compatible with “*cv1* `T1`”
618
+ [[dcl.init.ref]]. If the value is not a bit-field, the result refers to
619
  the object or the specified base class subobject thereof; otherwise, the
620
+ lvalue-to-rvalue conversion [[conv.lval]] is applied to the bit-field
621
  and the resulting prvalue is used as the *expression* of the
622
+ `static_cast` for the remainder of this subclause. If `T2` is an
623
+ inaccessible [[class.access]] or ambiguous [[class.member.lookup]] base
624
+ class of `T1`, a program that necessitates such a cast is ill-formed.
 
625
 
626
+ An expression E can be explicitly converted to a type `T` if there is an
627
+ implicit conversion sequence [[over.best.ics]] from E to `T`, if
628
+ overload resolution for a direct-initialization [[dcl.init]] of an
629
+ object or reference of type `T` from E would find at least one viable
630
+ function [[over.match.viable]], or if `T` is an aggregate type
631
+ [[dcl.init.aggr]] having a first element `x` and there is an implicit
632
+ conversion sequence from E to the type of `x`. If `T` is a reference
633
+ type, the effect is the same as performing the declaration and
634
+ initialization
635
 
636
  ``` cpp
637
+ T t(E);
638
  ```
639
 
640
+ for some invented temporary variable `t` [[dcl.init]] and then using the
641
+ temporary variable as the result of the conversion. Otherwise, the
642
+ result object is direct-initialized from E.
643
 
644
  [*Note 1*: The conversion is ill-formed when attempting to convert an
645
  expression of class type to an inaccessible or ambiguous base
646
  class. — *end note*]
647
 
648
+ [*Note 2*: If `T` is “array of unknown bound of `U`”, this
649
+ direct-initialization defines the type of the expression as
650
+ `U[1]`. — *end note*]
651
+
652
  Otherwise, the `static_cast` shall perform one of the conversions listed
653
  below. No other conversion shall be performed explicitly using a
654
  `static_cast`.
655
 
656
  Any expression can be explicitly converted to type cv `void`, in which
657
+ case it becomes a discarded-value expression [[expr.prop]].
658
 
659
+ [*Note 3*: However, if the value is in a temporary object
660
+ [[class.temporary]], the destructor for that object is not executed
661
  until the usual time, and the value of the object is preserved for the
662
  purpose of executing the destructor. — *end note*]
663
 
664
+ The inverse of any standard conversion sequence [[conv]] not containing
665
+ an lvalue-to-rvalue [[conv.lval]], array-to-pointer [[conv.array]],
666
+ function-to-pointer [[conv.func]], null pointer [[conv.ptr]], null
667
+ member pointer [[conv.mem]], boolean [[conv.bool]], or function pointer
668
+ [[conv.fctptr]] conversion, can be performed explicitly using
669
+ `static_cast`. A program is ill-formed if it uses `static_cast` to
670
+ perform the inverse of an ill-formed standard conversion sequence.
 
671
 
672
  [*Example 2*:
673
 
674
  ``` cpp
675
  struct B { };
 
680
  }
681
  ```
682
 
683
  — *end example*]
684
 
685
+ The lvalue-to-rvalue [[conv.lval]], array-to-pointer [[conv.array]], and
686
+ function-to-pointer [[conv.func]] conversions are applied to the
687
+ operand. Such a `static_cast` is subject to the restriction that the
688
+ explicit conversion does not cast away constness [[expr.const.cast]],
689
+ and the following additional rules for specific cases:
 
690
 
691
+ A value of a scoped enumeration type [[dcl.enum]] can be explicitly
692
+ converted to an integral type; the result is the same as that of
693
+ converting to the enumeration’s underlying type and then to the
694
+ destination type. A value of a scoped enumeration type can also be
695
+ explicitly converted to a floating-point type; the result is the same as
696
+ that of converting from the original value to the floating-point type.
 
 
 
697
 
698
  A value of integral or enumeration type can be explicitly converted to a
699
+ complete enumeration type. If the enumeration type has a fixed
700
+ underlying type, the value is first converted to that type by integral
701
+ conversion, if necessary, and then to the enumeration type. If the
702
+ enumeration type does not have a fixed underlying type, the value is
703
+ unchanged if the original value is within the range of the enumeration
704
+ values [[dcl.enum]], and otherwise, the behavior is undefined. A value
705
+ of floating-point type can also be explicitly converted to an
706
+ enumeration type. The resulting value is the same as converting the
707
+ original value to the underlying type of the enumeration [[conv.fpint]],
708
+ and subsequently to the enumeration type.
709
 
710
  A prvalue of type “pointer to *cv1* `B`”, where `B` is a class type, can
711
  be converted to a prvalue of type “pointer to *cv2* `D`”, where `D` is a
712
+ complete class derived [[class.derived]] from `B`, if *cv2* is the same
713
  cv-qualification as, or greater cv-qualification than, *cv1*. If `B` is
714
  a virtual base class of `D` or a base class of a virtual base class of
715
  `D`, or if no valid standard conversion from “pointer to `D`” to
716
+ “pointer to `B`” exists [[conv.ptr]], the program is ill-formed. The
717
+ null pointer value [[basic.compound]] is converted to the null pointer
718
  value of the destination type. If the prvalue of type “pointer to *cv1*
719
  `B`” points to a `B` that is actually a subobject of an object of type
720
  `D`, the resulting pointer points to the enclosing object of type `D`.
721
  Otherwise, the behavior is undefined.
722
 
723
  A prvalue of type “pointer to member of `D` of type *cv1* `T`” can be
724
  converted to a prvalue of type “pointer to member of `B` of type *cv2*
725
+ `T`”, where `D` is a complete class type and `B` is a base class
726
+ [[class.derived]] of `D`, if *cv2* is the same cv-qualification as, or
727
+ greater cv-qualification than, *cv1*.
 
 
 
 
 
 
 
728
 
729
+ [*Note 4*: Function types (including those used in
730
+ pointer-to-member-function types) are never cv-qualified
731
+ [[dcl.fct]]. — *end note*]
732
+
733
+ If no valid standard conversion from “pointer to member of `B` of type
734
+ `T`” to “pointer to member of `D` of type `T`” exists [[conv.mem]], the
735
+ program is ill-formed. The null member pointer value [[conv.mem]] is
736
+ converted to the null member pointer value of the destination type. If
737
+ class `B` contains the original member, or is a base or derived class of
738
+ the class containing the original member, the resulting pointer to
739
+ member points to the original member. Otherwise, the behavior is
740
+ undefined.
741
+
742
+ [*Note 5*: Although class `B` need not contain the original member, the
743
  dynamic type of the object with which indirection through the pointer to
744
  member is performed must contain the original member; see 
745
  [[expr.mptr.oper]]. — *end note*]
746
 
747
  A prvalue of type “pointer to *cv1* `void`” can be converted to a
 
750
  *cv1*. If the original pointer value represents the address `A` of a
751
  byte in memory and `A` does not satisfy the alignment requirement of
752
  `T`, then the resulting pointer value is unspecified. Otherwise, if the
753
  original pointer value points to an object *a*, and there is an object
754
  *b* of type `T` (ignoring cv-qualification) that is
755
+ pointer-interconvertible [[basic.compound]] with *a*, the result is a
756
  pointer to *b*. Otherwise, the pointer value is unchanged by the
757
  conversion.
758
 
759
  [*Example 3*:
760
 
 
764
  bool b = p1 == p2; // b will have the value true.
765
  ```
766
 
767
  — *end example*]
768
 
769
+ #### Reinterpret cast <a id="expr.reinterpret.cast">[[expr.reinterpret.cast]]</a>
770
 
771
  The result of the expression `reinterpret_cast<T>(v)` is the result of
772
  converting the expression `v` to type `T`. If `T` is an lvalue reference
773
  type or an rvalue reference to function type, the result is an lvalue;
774
  if `T` is an rvalue reference to object type, the result is an xvalue;
775
+ otherwise, the result is a prvalue and the lvalue-to-rvalue
776
+ [[conv.lval]], array-to-pointer [[conv.array]], and function-to-pointer
777
+ [[conv.func]] standard conversions are performed on the expression `v`.
778
+ Conversions that can be performed explicitly using `reinterpret_cast`
779
+ are listed below. No other conversion can be performed explicitly using
780
+ `reinterpret_cast`.
781
 
782
+ The `reinterpret_cast` operator shall not cast away constness
783
+ [[expr.const.cast]]. An expression of integral, enumeration, pointer, or
784
+ pointer-to-member type can be explicitly converted to its own type; such
785
+ a cast yields the value of its operand.
786
 
787
  [*Note 1*: The mapping performed by `reinterpret_cast` might, or might
788
  not, produce a representation different from the original
789
  value. — *end note*]
790
 
791
  A pointer can be explicitly converted to any integral type large enough
792
+ to hold all values of its type. The mapping function is
793
+ *implementation-defined*.
794
 
795
  [*Note 2*: It is intended to be unsurprising to those who know the
796
  addressing structure of the underlying machine. — *end note*]
797
 
798
  A value of type `std::nullptr_t` can be converted to an integral type;
 
814
 
815
  A function pointer can be explicitly converted to a function pointer of
816
  a different type.
817
 
818
  [*Note 5*: The effect of calling a function through a pointer to a
819
+ function type [[dcl.fct]] that is not the same as the type used in the
820
+ definition of the function is undefined [[expr.call]]. — *end note*]
821
 
822
  Except that converting a prvalue of type “pointer to `T1`” to the type
823
  “pointer to `T2`” (where `T1` and `T2` are function types) and back to
824
  its original type yields the original pointer value, the result of such
825
  a pointer conversion is unspecified.
826
 
827
  [*Note 6*: See also  [[conv.ptr]] for more details of pointer
828
  conversions. — *end note*]
829
 
830
  An object pointer can be explicitly converted to an object pointer of a
831
+ different type.[^17] When a prvalue `v` of object pointer type is
832
  converted to the object pointer type “pointer to cv `T`”, the result is
833
  `static_cast<cv T*>(static_cast<cv~void*>(v))`.
834
 
835
  [*Note 7*: Converting a prvalue of type “pointer to `T1`” to the type
836
  “pointer to `T2`” (where `T1` and `T2` are object types and where the
 
843
  *implementation-defined*, except that if an implementation supports
844
  conversions in both directions, converting a prvalue of one type to the
845
  other type and back, possibly with different cv-qualification, shall
846
  yield the original pointer value.
847
 
848
+ The null pointer value [[basic.compound]] is converted to the null
849
+ pointer value of the destination type.
850
 
851
  [*Note 8*: A null pointer constant of type `std::nullptr_t` cannot be
852
  converted to a pointer type, and a null pointer constant of integral
853
  type is not necessarily converted to a null pointer
854
  value. — *end note*]
855
 
856
  A prvalue of type “pointer to member of `X` of type `T1`” can be
857
  explicitly converted to a prvalue of a different type “pointer to member
858
  of `Y` of type `T2`” if `T1` and `T2` are both function types or both
859
+ object types.[^18] The null member pointer value [[conv.mem]] is
860
  converted to the null member pointer value of the destination type. The
861
  result of this conversion is unspecified, except in the following cases:
862
 
863
+ - Converting a prvalue of type “pointer to member function” to a
864
+ different pointer-to-member-function type and back to its original
865
+ type yields the original pointer-to-member value.
866
+ - Converting a prvalue of type “pointer to data member of `X` of type
867
  `T1`” to the type “pointer to data member of `Y` of type `T2`” (where
868
  the alignment requirements of `T2` are no stricter than those of `T1`)
869
+ and back to its original type yields the original pointer-to-member
870
  value.
871
 
872
+ A glvalue of type `T1`, designating an object *x*, can be cast to the
873
+ type “reference to `T2`” if an expression of type “pointer to `T1`” can
874
+ be explicitly converted to the type “pointer to `T2`” using a
875
+ `reinterpret_cast`. The result is that of `*reinterpret_cast<T2 *>(p)`
876
+ where `p` is a pointer to *x* of type “pointer to `T1`”. No temporary is
877
+ created, no copy is made, and no constructors [[class.ctor]] or
878
+ conversion functions [[class.conv]] are called. [^19]
879
 
880
+ #### Const cast <a id="expr.const.cast">[[expr.const.cast]]</a>
 
 
 
 
 
 
 
 
 
881
 
882
  The result of the expression `const_cast<T>(v)` is of type `T`. If `T`
883
  is an lvalue reference to object type, the result is an lvalue; if `T`
884
  is an rvalue reference to object type, the result is an xvalue;
885
+ otherwise, the result is a prvalue and the lvalue-to-rvalue
886
+ [[conv.lval]], array-to-pointer [[conv.array]], and function-to-pointer
887
+ [[conv.func]] standard conversions are performed on the expression `v`.
888
+ Conversions that can be performed explicitly using `const_cast` are
889
+ listed below. No other conversion shall be performed explicitly using
890
+ `const_cast`.
891
 
892
+ [*Note 1*: Subject to the restrictions in this subclause, an expression
893
  may be cast to its own type using a `const_cast`
894
  operator. — *end note*]
895
 
896
+ For two similar types `T1` and `T2` [[conv.qual]], a prvalue of type
897
+ `T1` may be explicitly converted to the type `T2` using a `const_cast`
898
+ if, considering the cv-decompositions of both types, each P¹ᵢ is the
899
+ same as P²ᵢ for all i. The result of a `const_cast` refers to the
900
+ original entity.
901
 
902
  [*Example 1*:
903
 
904
  ``` cpp
905
  typedef int *A[3]; // array of 3 pointer to int
906
  typedef const int *const CA[3]; // array of 3 const pointer to const int
907
 
908
+ CA &&r = A{}; // OK, reference binds to temporary array object
909
+ // after qualification conversion to type CA
910
  A &&r1 = const_cast<A>(CA{}); // error: temporary array decayed to pointer
911
  A &&r2 = const_cast<A&&>(CA{}); // OK
912
  ```
913
 
914
  — *end example*]
 
924
  - if `T1` is a class type, a prvalue of type `T1` can be explicitly
925
  converted to an xvalue of type `T2` using the cast `const_cast<T2&&>`.
926
 
927
  The result of a reference `const_cast` refers to the original object if
928
  the operand is a glvalue and to the result of applying the temporary
929
+ materialization conversion [[conv.rval]] otherwise.
930
 
931
+ A null pointer value [[basic.compound]] is converted to the null pointer
932
+ value of the destination type. The null member pointer value
933
+ [[conv.mem]] is converted to the null member pointer value of the
934
  destination type.
935
 
936
  [*Note 2*: Depending on the type of the object, a write operation
937
  through the pointer, lvalue or pointer to data member resulting from a
938
+ `const_cast` that casts away a const-qualifier[^20] may produce
939
+ undefined behavior [[dcl.type.cv]]. — *end note*]
940
 
941
  A conversion from a type `T1` to a type `T2` *casts away constness* if
942
+ `T1` and `T2` are different, there is a cv-decomposition [[conv.qual]]
943
+ of `T1` yielding *n* such that `T2` has a cv-decomposition of the form
 
944
 
945
  and there is no qualification conversion that converts `T1` to
946
 
947
  Casting from an lvalue of type `T1` to an lvalue of type `T2` using an
948
  lvalue reference cast or casting from an expression of type `T1` to an