From Jason Turner

[expr.post]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpfygugu0r/{from.md → to.md} +231 -163
tmp/tmpfygugu0r/{from.md → to.md} RENAMED
@@ -1,22 +1,24 @@
1
  ### Postfix expressions <a id="expr.post">[[expr.post]]</a>
2
 
 
 
3
  Postfix expressions group left-to-right.
4
 
5
  ``` bnf
6
  postfix-expression:
7
  primary-expression
8
- postfix-expression '[' expr-or-braced-init-list ']'
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 ')'
@@ -27,38 +29,43 @@ postfix-expression:
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.
@@ -72,72 +79,69 @@ 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*]
@@ -155,14 +159,14 @@ 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
@@ -218,14 +222,14 @@ statically chosen function.
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]].
@@ -275,73 +279,93 @@ A *simple-type-specifier* [[dcl.type.simple]] or *typename-specifier*
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*
@@ -354,33 +378,53 @@ rules applies.
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
@@ -403,11 +447,11 @@ 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 
406
  [[expr.ass]].
407
 
408
- The operand of postfix `\dcr` is decremented analogously to the postfix
409
  `++` operator.
410
 
411
  [*Note 3*: For prefix increment and decrement, see 
412
  [[expr.pre.incr]]. — *end note*]
413
 
@@ -433,13 +477,14 @@ 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 { };
@@ -459,11 +504,11 @@ If `v` is a null pointer value, the result is a null pointer value.
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
@@ -517,40 +562,44 @@ destruction. — *end note*]
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
@@ -570,12 +619,14 @@ typeid(D) == typeid(d2); // yields true
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>
@@ -611,19 +662,19 @@ B &br = d;
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
@@ -652,13 +703,16 @@ direct-initialization defines the type of the expression as
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
@@ -696,39 +750,48 @@ 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
@@ -737,11 +800,11 @@ 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
@@ -749,14 +812,13 @@ prvalue of type “pointer to *cv2* `T`”, where `T` is an object type and
749
  *cv2* is the same cv-qualification as, or greater cv-qualification than,
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
 
761
  ``` cpp
762
  T* p1 = new T;
@@ -806,39 +868,37 @@ A value of integral type or enumeration type can be explicitly converted
806
  to a pointer. A pointer converted to an integer of sufficient size (if
807
  any such exists on the implementation) and back to the same pointer type
808
  will have its original value; mappings between pointers and integers are
809
  otherwise *implementation-defined*.
810
 
811
- [*Note 4*: Except as described in [[basic.stc.dynamic.safety]], the
812
- result of such a conversion will not be a safely-derived pointer
813
- value. — *end note*]
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
837
- alignment requirements of `T2` are no stricter than those of `T1`) and
838
- back to its original type yields the original pointer
839
- value. — *end note*]
840
 
841
  Converting a function pointer to an object pointer type or vice versa is
842
  conditionally-supported. The meaning of such a conversion is
843
  *implementation-defined*, except that if an implementation supports
844
  conversions in both directions, converting a prvalue of one type to the
@@ -846,21 +906,23 @@ 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
@@ -888,17 +950,17 @@ otherwise, the result is a prvalue and the lvalue-to-rvalue
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
@@ -931,29 +993,35 @@ materialization conversion [[conv.rval]] otherwise.
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
949
  xvalue of type `T2` using an rvalue reference cast casts away constness
950
  if a cast from a prvalue of type “pointer to `T1`” to the type “pointer
951
  to `T2`” casts away constness.
952
 
953
  [*Note 3*: Some conversions which involve only changes in
954
- cv-qualification cannot be done using `const_cast.` For instance,
955
  conversions between pointers to functions are not covered because such
956
  conversions lead to values whose use causes undefined behavior. For the
957
  same reasons, conversions between pointers to member functions, and in
958
  particular, the conversion from a pointer to a const member function to
959
  a pointer to a non-const member function, are not
 
1
  ### Postfix expressions <a id="expr.post">[[expr.post]]</a>
2
 
3
+ #### General <a id="expr.post.general">[[expr.post.general]]</a>
4
+
5
  Postfix expressions group left-to-right.
6
 
7
  ``` bnf
8
  postfix-expression:
9
  primary-expression
10
+ postfix-expression '[' expression-listₒₚₜ ']'
11
  postfix-expression '(' expression-listₒₚₜ ')'
12
  simple-type-specifier '(' expression-listₒₚₜ ')'
13
  typename-specifier '(' expression-listₒₚₜ ')'
14
  simple-type-specifier braced-init-list
15
  typename-specifier braced-init-list
16
  postfix-expression '.' 'template'ₒₚₜ id-expression
17
  postfix-expression '->' 'template'ₒₚₜ id-expression
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 ')'
 
29
  expression-list:
30
  initializer-list
31
  ```
32
 
33
  [*Note 1*: The `>` token following the *type-id* in a `dynamic_cast`,
34
+ `static_cast`, `reinterpret_cast`, or `const_cast` can be the product of
35
+ replacing a `>>` token by two consecutive `>` tokens
36
  [[temp.names]]. — *end note*]
37
 
38
  #### Subscripting <a id="expr.sub">[[expr.sub]]</a>
39
 
40
+ A *subscript expression* is a postfix expression followed by square
41
+ brackets containing a possibly empty, comma-separated list of
42
+ *initializer-clause*s that constitute the arguments to the subscript
43
+ operator. The *postfix-expression* and the initialization of the object
44
+ parameter of any applicable subscript operator function is sequenced
45
+ before each expression in the *expression-list* and also before any
46
+ default argument. The initialization of a non-object parameter of a
47
+ subscript operator function `S` [[over.sub]], including every associated
48
+ value computation and side effect, is indeterminately sequenced with
49
+ respect to that of any other non-object parameter of `S`.
50
 
51
+ With the built-in subscript operator, an *expression-list* shall be
52
+ present, consisting of a single *assignment-expression*. One of the
53
+ expressions shall be a glvalue of type “array of `T`” or a prvalue of
54
+ type “pointer to `T`” and the other shall be a prvalue of unscoped
55
+ enumeration or integral type. The result is of type “`T`”. The type
56
+ “`T`” shall be a completely-defined object type.[^11]
57
 
58
+ The expression `E1[E2]` is identical (by definition) to `*((E1)+(E2))`,
59
+ except that in the case of an array operand, the result is an lvalue if
60
+ that operand is an lvalue and an xvalue otherwise.
61
+
62
+ [*Note 1*: Despite its asymmetric appearance, subscripting is a
63
  commutative operation except for sequencing. See  [[expr.unary]] and 
64
  [[expr.add]] for details of `*` and `+` and  [[dcl.array]] for details
65
  of array types. — *end note*]
66
 
 
 
 
67
  #### Function call <a id="expr.call">[[expr.call]]</a>
68
 
69
  A function call is a postfix expression followed by parentheses
70
  containing a possibly empty, comma-separated list of
71
  *initializer-clause*s which constitute the arguments to the function.
 
79
  function, the postfix expression shall either be an lvalue that refers
80
  to a function (in which case the function-to-pointer standard conversion
81
  [[conv.func]] is suppressed on the postfix expression), or have function
82
  pointer type.
83
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  If the selected function is non-virtual, or if the *id-expression* in
85
  the class member access expression is a *qualified-id*, that function is
86
  called. Otherwise, its final overrider [[class.virtual]] in the dynamic
87
  type of the object expression is called; such a call is referred to as a
88
  *virtual function call*.
89
 
90
+ [*Note 2*: The dynamic type is the type of the object referred to by
91
  the current value of the object expression. [[class.cdtor]] describes
92
  the behavior of virtual function calls when the object expression refers
93
  to an object under construction or destruction. — *end note*]
94
 
95
+ [*Note 3*: If a function or member function name is used, and name
96
  lookup [[basic.lookup]] does not find a declaration of that name, the
97
  program is ill-formed. No function is implicitly declared by such a
98
  call. — *end note*]
99
 
100
  If the *postfix-expression* names a destructor or pseudo-destructor
101
  [[expr.prim.id.dtor]], the type of the function call expression is
102
  `void`; otherwise, the type of the function call expression is the
103
  return type of the statically chosen function (i.e., ignoring the
104
  `virtual` keyword), even if the type of the function actually called is
105
+ different. If the *postfix-expression* names a pseudo-destructor (in
 
106
  which case the *postfix-expression* is a possibly-parenthesized class
107
  member access), the function call destroys the object of scalar type
108
+ denoted by the object expression of the class member access
109
+ [[expr.ref]], [[basic.life]].
110
 
111
+ Calling a function through an expression whose function type `E` is
112
+ different from the function type `F` of the called function’s definition
113
+ results in undefined behavior unless the type “pointer to `F`” can be
114
+ converted to the type “pointer to `E`” via a function pointer conversion
115
+ [[conv.fctptr]].
116
 
117
+ [*Note 4*: The exception applies when the expression has the type of a
118
+ potentially-throwing function, but the called function has a
119
+ non-throwing exception specification, and the function types are
120
+ otherwise the same. — *end note*]
121
+
122
+ When a function is called, each parameter [[dcl.fct]] is initialized
123
+ [[dcl.init]], [[class.copy.ctor]] with its corresponding argument. If
124
+ the function is an explicit object member function and there is an
125
+ implied object argument [[over.call.func]], the list of provided
126
+ arguments is preceded by the implied object argument for the purposes of
127
+ this correspondence. If there is no corresponding argument, the default
128
+ argument for the parameter is used.
129
 
130
  [*Example 1*:
131
 
132
  ``` cpp
133
  template<typename ...T> int f(int n = 0, T ...t);
134
  int x = f<int>(); // error: no argument for second function parameter
135
  ```
136
 
137
  — *end example*]
138
 
139
+ If the function is an implicit object member function, the `this`
140
+ parameter of the function [[expr.prim.this]] is initialized with a
141
+ pointer to the object of the call, converted as if by an explicit type
142
+ conversion [[expr.cast]].
143
 
144
  [*Note 5*: There is no access or ambiguity checking on this conversion;
145
  the access checking and disambiguation are done as part of the (possibly
146
  implicit) class member access operator. See  [[class.member.lookup]],
147
  [[class.access.base]], and  [[expr.ref]]. — *end note*]
 
159
  parameter occurs within the context of the calling function.
160
 
161
  [*Example 2*: The access of the constructor, conversion functions or
162
  destructor is checked at the point of call in the calling function. If a
163
  constructor or destructor for a function parameter throws an exception,
164
+ the search for a handler starts in the calling function; in particular,
165
+ if the function called has a *function-try-block* [[except.pre]] with a
166
+ handler that can handle the exception, this handler is not
167
+ considered. — *end example*]
168
 
169
  The *postfix-expression* is sequenced before each *expression* in the
170
  *expression-list* and any default argument. The initialization of a
171
  parameter, including every associated value computation and side effect,
172
  is indeterminately sequenced with respect to that of any other
 
222
  parameters, but these changes cannot affect the values of the arguments
223
  except where a parameter is of a reference type [[dcl.ref]]; if the
224
  reference is to a const-qualified type, `const_cast` is required to be
225
  used to cast away the constness in order to modify the argument’s value.
226
  Where a parameter is of `const` reference type a temporary object is
227
+ introduced if needed
228
+ [[dcl.type]], [[lex.literal]], [[lex.string]], [[dcl.array]], [[class.temporary]].
229
+ In addition, it is possible to modify the values of non-constant objects
230
+ through pointer parameters. — *end note*]
231
 
232
  A function can be declared to accept fewer arguments (by declaring
233
  default arguments [[dcl.fct.default]]) or more arguments (by using the
234
  ellipsis, `...`, or a function parameter pack [[dcl.fct]]) than the
235
  number of parameters in the function definition [[dcl.fct.def]].
 
279
  by a *braced-init-list* (the initializer) constructs a value of the
280
  specified type given the initializer. If the type is a placeholder for a
281
  deduced class type, it is replaced by the return type of the function
282
  selected by overload resolution for class template deduction
283
  [[over.match.class.deduct]] for the remainder of this subclause.
284
+ Otherwise, if the type contains a placeholder type, it is replaced by
285
+ the type determined by placeholder type deduction
286
+ [[dcl.type.auto.deduct]].
287
+
288
+ [*Example 1*:
289
+
290
+ ``` cpp
291
+ struct A {};
292
+ void f(A&); // #1
293
+ void f(A&&); // #2
294
+ A& g();
295
+ void h() {
296
+ f(g()); // calls #1
297
+ f(A(g())); // calls #2 with a temporary object
298
+ f(auto(g())); // calls #2 with a temporary object
299
+ }
300
+ ```
301
+
302
+ — *end example*]
303
 
304
  If the initializer is a parenthesized single expression, the type
305
  conversion expression is equivalent to the corresponding cast expression
306
  [[expr.cast]]. Otherwise, if the type is cv `void` and the initializer
307
  is `()` or `{}` (after pack expansion, if any), the expression is a
308
+ prvalue of type `void` that performs no initialization. Otherwise, the
309
+ expression is a prvalue of the specified type whose result object is
310
+ direct-initialized [[dcl.init]] with the initializer. If the initializer
311
+ is a parenthesized optional *expression-list*, the specified type shall
312
+ not be an array type.
313
 
314
  #### Class member access <a id="expr.ref">[[expr.ref]]</a>
315
 
316
  A postfix expression followed by a dot `.` or an arrow `->`, optionally
317
+ followed by the keyword `template`, and then followed by an
318
+ *id-expression*, is a postfix expression. The postfix expression before
319
+ the dot or arrow is evaluated;[^12]
320
+
321
+ the result of that evaluation, together with the *id-expression*,
322
+ determines the result of the entire postfix expression.
323
+
324
+ [*Note 1*: If the keyword `template` is used, the following unqualified
325
+ name is considered to refer to a template [[temp.names]]. If a
326
+ *simple-template-id* results and is followed by a `::`, the
327
+ *id-expression* is a *qualified-id*. — *end note*]
328
 
329
  For the first option (dot) the first expression shall be a glvalue. For
330
  the second option (arrow) the first expression shall be a prvalue having
331
  pointer type. The expression `E1->E2` is converted to the equivalent
332
  form `(*(E1)).E2`; the remainder of [[expr.ref]] will address only the
333
  first option (dot).[^13]
334
 
335
  Abbreviating *postfix-expression*`.`*id-expression* as `E1.E2`, `E1` is
336
  called the *object expression*. If the object expression is of scalar
337
  type, `E2` shall name the pseudo-destructor of that same type (ignoring
338
+ cv-qualifications) and `E1.E2` is a prvalue of type “function of ()
339
  returning `void`”.
340
 
341
+ [*Note 2*: This value can only be used for a notional function call
342
  [[expr.prim.id.dtor]]. — *end note*]
343
 
344
  Otherwise, the object expression shall be of class type. The class type
345
  shall be complete unless the class member access appears in the
346
  definition of that class.
347
 
348
+ [*Note 3*: The program is ill-formed if the result differs from that
349
+ when the class is complete [[class.member.lookup]]. *end note*]
 
350
 
351
+ [*Note 4*: [[basic.lookup.qual]] describes how names are looked up
 
 
 
 
 
 
 
352
  after the `.` and `->` operators. — *end note*]
353
 
354
  If `E2` is a bit-field, `E1.E2` is a bit-field. The type and value
355
  category of `E1.E2` are determined as follows. In the remainder of 
356
  [[expr.ref]], *cq* represents either `const` or the absence of `const`
357
  and *vq* represents either `volatile` or the absence of `volatile`. *cv*
358
  represents an arbitrary set of cv-qualifiers, as defined in 
359
  [[basic.type.qualifier]].
360
 
361
  If `E2` is declared to have type “reference to `T`”, then `E1.E2` is an
362
+ lvalue of type `T`. If `E2` is a static data member, `E1.E2` designates
363
+ the object or function to which the reference is bound, otherwise
364
+ `E1.E2` designates the object or function to which the corresponding
365
+ reference member of `E1` is bound. Otherwise, one of the following rules
366
+ applies.
367
 
368
  - If `E2` is a static data member and the type of `E2` is `T`, then
369
  `E1.E2` is an lvalue; the expression designates the named member of
370
  the class. The type of `E1.E2` is `T`.
371
  - If `E2` is a non-static data member and the type of `E1` is “*cq1 vq1*
 
378
  *cq12* stand for the “union” of *cq1* and *cq2*; that is, if *cq1* or
379
  *cq2* is `const`, then *cq12* is `const`. If `E2` is declared to be a
380
  `mutable` member, then the type of `E1.E2` is “*vq12* `T`”. If `E2` is
381
  not declared to be a `mutable` member, then the type of `E1.E2` is
382
  “*cq12* *vq12* `T`”.
383
+ - If `E2` is an overload set, function overload resolution
384
+ [[over.match]] is used to select the function to which `E2` refers.
385
+ The type of `E1.E2` is the type of `E2` and `E1.E2` refers to the
386
+ function referred to by `E2`.
387
  - If `E2` refers to a static member function, `E1.E2` is an lvalue.
388
  - Otherwise (when `E2` refers to a non-static member function),
389
  `E1.E2` is a prvalue. The expression can be used only as the
390
  left-hand operand of a member function call [[class.mfct]].
391
  \[*Note 5*: Any redundant set of parentheses surrounding the
392
  expression is ignored [[expr.prim.paren]]. — *end note*]
393
  - If `E2` is a nested type, the expression `E1.E2` is ill-formed.
394
  - If `E2` is a member enumerator and the type of `E2` is `T`, the
395
+ expression `E1.E2` is a prvalue of type `T` whose value is the value
396
+ of the enumerator.
397
 
398
+ If `E2` is a non-static member, the program is ill-formed if the class
399
+ of which `E2` is directly a member is an ambiguous base
400
+ [[class.member.lookup]] of the naming class [[class.access.base]] of
401
+ `E2`.
402
 
403
  [*Note 6*: The program is also ill-formed if the naming class is an
404
  ambiguous base of the class type of the object expression; see 
405
  [[class.access.base]]. — *end note*]
406
 
407
+ If `E2` is a non-static member and the result of `E1` is an object whose
408
+ type is not similar [[conv.qual]] to the type of `E1`, the behavior is
409
+ undefined.
410
+
411
+ [*Example 1*:
412
+
413
+ ``` cpp
414
+ struct A { int i; };
415
+ struct B { int j; };
416
+ struct D : A, B {};
417
+ void f() {
418
+ D d;
419
+ static_cast<B&>(d).j; // OK, object expression designates the B subobject of d
420
+ reinterpret_cast<B&>(d).j; // undefined behavior
421
+ }
422
+ ```
423
+
424
+ — *end example*]
425
+
426
  #### Increment and decrement <a id="expr.post.incr">[[expr.post.incr]]</a>
427
 
428
  The value of a postfix `++` expression is the value of its operand.
429
 
430
  [*Note 1*: The value obtained is a copy of the original
 
447
  version of the type of the operand. If the operand is a bit-field that
448
  cannot represent the incremented value, the resulting value of the
449
  bit-field is *implementation-defined*. See also  [[expr.add]] and 
450
  [[expr.ass]].
451
 
452
+ The operand of postfix `--` is decremented analogously to the postfix
453
  `++` operator.
454
 
455
  [*Note 3*: For prefix increment and decrement, see 
456
  [[expr.pre.incr]]. — *end note*]
457
 
 
477
  such that `B` is a base class of `D`, the result is a pointer to the
478
  unique `B` subobject of the `D` object pointed to by `v`, or a null
479
  pointer value if `v` is a null pointer value. Similarly, if `T` is
480
  “reference to *cv1* `B`” and `v` has type *cv2* `D` such that `B` is a
481
  base class of `D`, the result is the unique `B` subobject of the `D`
482
+ object referred to by `v`.[^14]
483
+
484
+ In both the pointer and reference cases, the program is ill-formed if
485
+ `B` is an inaccessible or ambiguous base class of `D`.
486
 
487
  [*Example 1*:
488
 
489
  ``` cpp
490
  struct B { };
 
504
  If `T` is “pointer to cv `void`”, then the result is a pointer to the
505
  most derived object pointed to by `v`. Otherwise, a runtime check is
506
  applied to see if the object pointed or referred to by `v` can be
507
  converted to the type pointed or referred to by `T`.
508
 
509
+ Let `C` be the class type to which `T` points or refers. The runtime
510
  check logically executes as follows:
511
 
512
  - If, in the most derived object pointed (referred) to by `v`, `v`
513
  points (refers) to a public base class subobject of a `C` object, and
514
  if only one object of type `C` is derived from the subobject pointed
 
562
 
563
  The result of a `typeid` expression is an lvalue of static type `const`
564
  `std::type_info` [[type.info]] and dynamic type `const` `std::type_info`
565
  or `const` *name* where *name* is an *implementation-defined* class
566
  publicly derived from `std::type_info` which preserves the behavior
567
+ described in  [[type.info]].[^15]
568
+
569
+ The lifetime of the object referred to by the lvalue extends to the end
570
+ of the program. Whether or not the destructor is called for the
571
+ `std::type_info` object at the end of the program is unspecified.
572
+
573
+ If the type of the *expression* or *type-id* operand is a (possibly
574
+ cv-qualified) class type or a reference to (possibly cv-qualified) class
575
+ type, that class shall be completely defined.
576
 
577
  When `typeid` is applied to a glvalue whose type is a polymorphic class
578
  type [[class.virtual]], the result refers to a `std::type_info` object
579
  representing the type of the most derived object [[intro.object]] (that
580
  is, the dynamic type) to which the glvalue refers. If the glvalue is
581
+ obtained by applying the unary `*` operator to a pointer[^16]
582
+
583
+ and the pointer is a null pointer value [[basic.compound]], the `typeid`
584
  expression throws an exception [[except.throw]] of a type that would
585
  match a handler of type `std::bad_typeid` exception [[bad.typeid]].
586
 
587
  When `typeid` is applied to an expression other than a glvalue of a
588
  polymorphic class type, the result refers to a `std::type_info` object
589
  representing the static type of the expression. Lvalue-to-rvalue
590
  [[conv.lval]], array-to-pointer [[conv.array]], and function-to-pointer
591
  [[conv.func]] conversions are not applied to the expression. If the
592
  expression is a prvalue, the temporary materialization conversion
593
  [[conv.rval]] is applied. The expression is an unevaluated operand
594
+ [[term.unevaluated.operand]].
595
 
596
  When `typeid` is applied to a *type-id*, the result refers to a
597
  `std::type_info` object representing the type of the *type-id*. If the
598
  type of the *type-id* is a reference to a possibly cv-qualified type,
599
  the result of the `typeid` expression refers to a `std::type_info`
600
+ object representing the cv-unqualified referenced type.
 
 
601
 
602
  [*Note 1*: The *type-id* cannot denote a function type with a
603
  *cv-qualifier-seq* or a *ref-qualifier* [[dcl.fct]]. — *end note*]
604
 
605
  If the type of the expression or *type-id* is a cv-qualified type, the
 
619
  typeid(D) == typeid(const D&); // yields true
620
  ```
621
 
622
  — *end example*]
623
 
624
+ The type `std::type_info` [[type.info]] is not predefined; if a standard
625
+ library declaration [[typeinfo.syn]], [[std.modules]] of
626
+ `std::type_info` does not precede [[basic.lookup.general]] a `typeid`
627
+ expression, the program is ill-formed.
628
 
629
  [*Note 2*: Subclause [[class.cdtor]] describes the behavior of `typeid`
630
  applied to an object under construction or destruction. — *end note*]
631
 
632
  #### Static cast <a id="expr.static.cast">[[expr.static.cast]]</a>
 
662
  static_cast<D&>(br); // produces lvalue denoting the original d object
663
  ```
664
 
665
  — *end example*]
666
 
667
+ An lvalue of type `T1` can be cast to type “rvalue reference to `T2`” if
668
+ `T2` is reference-compatible with `T1` [[dcl.init.ref]]. If the value is
669
+ not a bit-field, the result refers to the object or the specified base
670
+ class subobject thereof; otherwise, the lvalue-to-rvalue conversion
671
+ [[conv.lval]] is applied to the bit-field and the resulting prvalue is
672
+ used as the operand of the `static_cast` for the remainder of this
673
+ subclause. If `T2` is an inaccessible [[class.access]] or ambiguous
674
+ [[class.member.lookup]] base class of `T1`, a program that necessitates
675
+ such a cast is ill-formed.
676
 
677
  An expression E can be explicitly converted to a type `T` if there is an
678
  implicit conversion sequence [[over.best.ics]] from E to `T`, if
679
  overload resolution for a direct-initialization [[dcl.init]] of an
680
  object or reference of type `T` from E would find at least one viable
 
703
  Otherwise, the `static_cast` shall perform one of the conversions listed
704
  below. No other conversion shall be performed explicitly using a
705
  `static_cast`.
706
 
707
  Any expression can be explicitly converted to type cv `void`, in which
708
+ case the operand is a discarded-value expression [[expr.prop]].
709
 
710
+ [*Note 3*: Such a `static_cast` has no result as it is a prvalue of
711
+ type `void`; see  [[basic.lval]]. — *end note*]
712
+
713
+ [*Note 4*: However, if the value is in a temporary object
714
  [[class.temporary]], the destructor for that object is not executed
715
  until the usual time, and the value of the object is preserved for the
716
  purpose of executing the destructor. — *end note*]
717
 
718
  The inverse of any standard conversion sequence [[conv]] not containing
 
750
  that of converting from the original value to the floating-point type.
751
 
752
  A value of integral or enumeration type can be explicitly converted to a
753
  complete enumeration type. If the enumeration type has a fixed
754
  underlying type, the value is first converted to that type by integral
755
+ promotion [[conv.prom]] or integral conversion [[conv.integral]], if
756
+ necessary, and then to the enumeration type. If the enumeration type
757
+ does not have a fixed underlying type, the value is unchanged if the
758
+ original value is within the range of the enumeration values
759
+ [[dcl.enum]], and otherwise, the behavior is undefined. A value of
760
+ floating-point type can also be explicitly converted to an enumeration
761
+ type. The resulting value is the same as converting the original value
762
+ to the underlying type of the enumeration [[conv.fpint]], and
763
+ subsequently to the enumeration type.
764
+
765
+ A prvalue of floating-point type can be explicitly converted to any
766
+ other floating-point type. If the source value can be exactly
767
+ represented in the destination type, the result of the conversion has
768
+ that exact representation. If the source value is between two adjacent
769
+ destination values, the result of the conversion is an
770
+ *implementation-defined* choice of either of those values. Otherwise,
771
+ the behavior is undefined.
772
 
773
  A prvalue of type “pointer to *cv1* `B`”, where `B` is a class type, can
774
  be converted to a prvalue of type “pointer to *cv2* `D`”, where `D` is a
775
  complete class derived [[class.derived]] from `B`, if *cv2* is the same
776
  cv-qualification as, or greater cv-qualification than, *cv1*. If `B` is
777
  a virtual base class of `D` or a base class of a virtual base class of
778
  `D`, or if no valid standard conversion from “pointer to `D`” to
779
  “pointer to `B`” exists [[conv.ptr]], the program is ill-formed. The
780
  null pointer value [[basic.compound]] is converted to the null pointer
781
  value of the destination type. If the prvalue of type “pointer to *cv1*
782
+ `B`” points to a `B` that is actually a base class subobject of an
783
+ object of type `D`, the resulting pointer points to the enclosing object
784
+ of type `D`. Otherwise, the behavior is undefined.
785
 
786
  A prvalue of type “pointer to member of `D` of type *cv1* `T`” can be
787
  converted to a prvalue of type “pointer to member of `B` of type *cv2*
788
  `T`”, where `D` is a complete class type and `B` is a base class
789
  [[class.derived]] of `D`, if *cv2* is the same cv-qualification as, or
790
  greater cv-qualification than, *cv1*.
791
 
792
+ [*Note 5*: Function types (including those used in
793
  pointer-to-member-function types) are never cv-qualified
794
  [[dcl.fct]]. — *end note*]
795
 
796
  If no valid standard conversion from “pointer to member of `B` of type
797
  `T`” to “pointer to member of `D` of type `T`” exists [[conv.mem]], the
 
800
  class `B` contains the original member, or is a base or derived class of
801
  the class containing the original member, the resulting pointer to
802
  member points to the original member. Otherwise, the behavior is
803
  undefined.
804
 
805
+ [*Note 6*: Although class `B` need not contain the original member, the
806
  dynamic type of the object with which indirection through the pointer to
807
  member is performed must contain the original member; see 
808
  [[expr.mptr.oper]]. — *end note*]
809
 
810
  A prvalue of type “pointer to *cv1* `void`” can be converted to a
 
812
  *cv2* is the same cv-qualification as, or greater cv-qualification than,
813
  *cv1*. If the original pointer value represents the address `A` of a
814
  byte in memory and `A` does not satisfy the alignment requirement of
815
  `T`, then the resulting pointer value is unspecified. Otherwise, if the
816
  original pointer value points to an object *a*, and there is an object
817
+ *b* of type similar to `T` that is pointer-interconvertible
818
+ [[basic.compound]] with *a*, the result is a pointer to *b*. Otherwise,
819
+ the pointer value is unchanged by the conversion.
 
820
 
821
  [*Example 3*:
822
 
823
  ``` cpp
824
  T* p1 = new T;
 
868
  to a pointer. A pointer converted to an integer of sufficient size (if
869
  any such exists on the implementation) and back to the same pointer type
870
  will have its original value; mappings between pointers and integers are
871
  otherwise *implementation-defined*.
872
 
 
 
 
 
873
  A function pointer can be explicitly converted to a function pointer of
874
  a different type.
875
 
876
+ [*Note 4*: The effect of calling a function through a pointer to a
877
  function type [[dcl.fct]] that is not the same as the type used in the
878
  definition of the function is undefined [[expr.call]]. — *end note*]
879
 
880
  Except that converting a prvalue of type “pointer to `T1`” to the type
881
  “pointer to `T2`” (where `T1` and `T2` are function types) and back to
882
  its original type yields the original pointer value, the result of such
883
  a pointer conversion is unspecified.
884
 
885
+ [*Note 5*: See also  [[conv.ptr]] for more details of pointer
886
  conversions. — *end note*]
887
 
888
  An object pointer can be explicitly converted to an object pointer of a
889
+ different type.[^17]
890
+
891
+ When a prvalue `v` of object pointer type is converted to the object
892
+ pointer type “pointer to cv `T`”, the result is
893
  `static_cast<cv T*>(static_cast<cv~void*>(v))`.
894
 
895
+ [*Note 6*: Converting a pointer of type “pointer to `T1`” that points
896
+ to an object of type `T1` to the type “pointer to `T2`” (where `T2` is
897
+ an object type and the alignment requirements of `T2` are no stricter
898
+ than those of `T1`) and back to its original type yields the original
899
+ pointer value. — *end note*]
900
 
901
  Converting a function pointer to an object pointer type or vice versa is
902
  conditionally-supported. The meaning of such a conversion is
903
  *implementation-defined*, except that if an implementation supports
904
  conversions in both directions, converting a prvalue of one type to the
 
906
  yield the original pointer value.
907
 
908
  The null pointer value [[basic.compound]] is converted to the null
909
  pointer value of the destination type.
910
 
911
+ [*Note 7*: A null pointer constant of type `std::nullptr_t` cannot be
912
  converted to a pointer type, and a null pointer constant of integral
913
  type is not necessarily converted to a null pointer
914
  value. — *end note*]
915
 
916
  A prvalue of type “pointer to member of `X` of type `T1`” can be
917
  explicitly converted to a prvalue of a different type “pointer to member
918
  of `Y` of type `T2`” if `T1` and `T2` are both function types or both
919
+ object types.[^18]
920
+
921
+ The null member pointer value [[conv.mem]] is converted to the null
922
+ member pointer value of the destination type. The result of this
923
+ conversion is unspecified, except in the following cases:
924
 
925
  - Converting a prvalue of type “pointer to member function” to a
926
  different pointer-to-member-function type and back to its original
927
  type yields the original pointer-to-member value.
928
  - Converting a prvalue of type “pointer to data member of `X` of type
 
950
  Conversions that can be performed explicitly using `const_cast` are
951
  listed below. No other conversion shall be performed explicitly using
952
  `const_cast`.
953
 
954
  [*Note 1*: Subject to the restrictions in this subclause, an expression
955
+ can be cast to its own type using a `const_cast`
956
  operator. — *end note*]
957
 
958
  For two similar types `T1` and `T2` [[conv.qual]], a prvalue of type
959
  `T1` may be explicitly converted to the type `T2` using a `const_cast`
960
+ if, considering the qualification-decompositions of both types, each P¹ᵢ
961
+ is the same as P²ᵢ for all i. The result of a `const_cast` refers to the
962
  original entity.
963
 
964
  [*Example 1*:
965
 
966
  ``` cpp
 
993
  A null pointer value [[basic.compound]] is converted to the null pointer
994
  value of the destination type. The null member pointer value
995
  [[conv.mem]] is converted to the null member pointer value of the
996
  destination type.
997
 
998
+ [*Note 2*:
999
+
1000
+ Depending on the type of the object, a write operation through the
1001
+ pointer, lvalue or pointer to data member resulting from a `const_cast`
1002
+ that casts away a const-qualifier[^20]
1003
+
1004
+ can produce undefined behavior [[dcl.type.cv]].
1005
+
1006
+ — *end note*]
1007
 
1008
  A conversion from a type `T1` to a type `T2` *casts away constness* if
1009
+ `T1` and `T2` are different, there is a qualification-decomposition
1010
+ [[conv.qual]] of `T1` yielding *n* such that `T2` has a
1011
+ qualification-decomposition of the form
1012
 
1013
  and there is no qualification conversion that converts `T1` to
1014
 
1015
  Casting from an lvalue of type `T1` to an lvalue of type `T2` using an
1016
  lvalue reference cast or casting from an expression of type `T1` to an
1017
  xvalue of type `T2` using an rvalue reference cast casts away constness
1018
  if a cast from a prvalue of type “pointer to `T1`” to the type “pointer
1019
  to `T2`” casts away constness.
1020
 
1021
  [*Note 3*: Some conversions which involve only changes in
1022
+ cv-qualification cannot be done using `const_cast`. For instance,
1023
  conversions between pointers to functions are not covered because such
1024
  conversions lead to values whose use causes undefined behavior. For the
1025
  same reasons, conversions between pointers to member functions, and in
1026
  particular, the conversion from a pointer to a const member function to
1027
  a pointer to a non-const member function, are not