From Jason Turner

[expr]

Large diff (255.2 KB) - rendering may be slow on some devices

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpunartgk5/{from.md → to.md} +2085 -994
tmp/tmpunartgk5/{from.md → to.md} RENAMED
@@ -30,12 +30,12 @@ that is, for operators applied to types for which they are defined by
30
  this Standard. However, these built-in operators participate in overload
31
  resolution, and as part of that process user-defined conversions will be
32
  considered where necessary to convert the operands to types appropriate
33
  for the built-in operator. If a built-in operator is selected, such
34
  conversions will be applied to the operands before the operation is
35
- considered further according to the rules in subclause
36
- [[expr.compound]]; see  [[over.match.oper]], [[over.built]].
37
 
38
  If during the evaluation of an expression, the result is not
39
  mathematically defined or not in the range of representable values for
40
  its type, the behavior is undefined.
41
 
@@ -111,22 +111,22 @@ Expressions are categorized according to the taxonomy in Figure
111
  <a id="fig:basic.lval"></a>
112
 
113
  ![Expression category taxonomy \[fig:basic.lval\]](images/valuecategories.svg)
114
 
115
  - A *glvalue* is an expression whose evaluation determines the identity
116
- of an object or function.
117
  - A *prvalue* is an expression whose evaluation initializes an object or
118
  computes the value of an operand of an operator, as specified by the
119
  context in which it appears, or an expression that has type cv `void`.
120
  - An *xvalue* is a glvalue that denotes an object whose resources can be
121
  reused (usually because it is near the end of its lifetime).
122
  - An *lvalue* is a glvalue that is not an xvalue.
123
  - An *rvalue* is a prvalue or an xvalue.
124
 
125
- Every expression belongs to exactly one of the fundamental
126
- classifications in this taxonomy: lvalue, xvalue, or prvalue. This
127
- property of an expression is called its *value category*.
128
 
129
  [*Note 1*: The discussion of each built-in operator in
130
  [[expr.compound]] indicates the category of the value it yields and the
131
  value categories of the operands it expects. For example, the built-in
132
  assignment operators expect that the left operand is an lvalue and that
@@ -137,18 +137,19 @@ types. — *end note*]
137
 
138
  [*Note 2*: Historically, lvalues and rvalues were so-called because
139
  they could appear on the left- and right-hand side of an assignment
140
  (although this is no longer generally true); glvalues are “generalized”
141
  lvalues, prvalues are “pure” rvalues, and xvalues are “eXpiring”
142
- lvalues. Despite their names, these terms classify expressions, not
143
  values. — *end note*]
144
 
145
  [*Note 3*:
146
 
147
  An expression is an xvalue if it is:
148
 
149
- - a move-eligible *id-expression* [[expr.prim.id.unqual]],
 
150
  - the result of calling a function, whether implicitly or explicitly,
151
  whose return type is an rvalue reference to object type [[expr.call]],
152
  - a cast to an rvalue reference to object type
153
  [[expr.type.conv]], [[expr.dynamic.cast]], [[expr.static.cast]], [[expr.reinterpret.cast]], [[expr.const.cast]], [[expr.cast]],
154
  - a subscripting operation with an xvalue array operand [[expr.sub]],
@@ -187,21 +188,18 @@ xvalues. The expression `ar` is an lvalue.
187
  The *result* of a glvalue is the entity denoted by the expression. The
188
  *result* of a prvalue is the value that the expression stores into its
189
  context; a prvalue that has type cv `void` has no result. A prvalue
190
  whose result is the value *V* is sometimes said to have or name the
191
  value *V*. The *result object* of a prvalue is the object initialized by
192
- the prvalue; a non-discarded prvalue that is used to compute the value
193
- of an operand of a built-in operator or a prvalue that has type
194
- cv `void` has no result object.
195
 
196
  [*Note 4*: Except when the prvalue is the operand of a
197
- *decltype-specifier*, a prvalue of class or array type always has a
198
- result object. For a discarded prvalue that has type other than
199
- cv `void`, a temporary object is materialized; see
200
- [[expr.context]]. — *end note*]
201
 
202
- Whenever a glvalue appears as an operand of an operator that expects a
203
  prvalue for that operand, the lvalue-to-rvalue [[conv.lval]],
204
  array-to-pointer [[conv.array]], or function-to-pointer [[conv.func]]
205
  standard conversions are applied to convert the expression to a prvalue.
206
 
207
  [*Note 5*: An attempt to bind an rvalue reference to an lvalue is not
@@ -214,60 +212,69 @@ prvalue of type `int` is required. — *end note*]
214
 
215
  [*Note 7*: There are no prvalue bit-fields; if a bit-field is converted
216
  to a prvalue [[conv.lval]], a prvalue of the type of the bit-field is
217
  created, which might then be promoted [[conv.prom]]. — *end note*]
218
 
219
- Whenever a prvalue appears as an operand of an operator that expects a
220
- glvalue for that operand, the temporary materialization conversion
221
- [[conv.rval]] is applied to convert the expression to an xvalue.
 
 
 
222
 
223
- The discussion of reference initialization in  [[dcl.init.ref]] and of
224
- temporaries in  [[class.temporary]] indicates the behavior of lvalues
225
- and rvalues in other significant contexts.
 
226
 
227
  Unless otherwise indicated [[dcl.type.decltype]], a prvalue shall always
228
  have complete type or the `void` type; if it has a class type or
229
  (possibly multidimensional) array of class type, that class shall not be
230
  an abstract class [[class.abstract]]. A glvalue shall not have type
231
  cv `void`.
232
 
233
- [*Note 8*: A glvalue can have complete or incomplete non-`void` type.
234
  Class and array prvalues can have cv-qualified types; other prvalues
235
  always have cv-unqualified types. See [[expr.type]]. — *end note*]
236
 
237
  An lvalue is *modifiable* unless its type is const-qualified or is a
238
  function type.
239
 
240
- [*Note 9*: A program that attempts to modify an object through a
241
  nonmodifiable lvalue or through an rvalue is ill-formed
242
- [[expr.ass]], [[expr.post.incr]], [[expr.pre.incr]]. — *end note*]
243
 
244
- If a program attempts to access [[defns.access]] the stored value of an
245
- object through a glvalue whose type is not similar [[conv.qual]] to one
246
- of the following types the behavior is undefined:[^4]
247
 
248
- - the dynamic type of the object,
249
- - a type that is the signed or unsigned type corresponding to the
250
- dynamic type of the object, or
251
  - a `char`, `unsigned char`, or `std::byte` type.
252
 
 
 
 
 
253
  If a program invokes a defaulted copy/move constructor or copy/move
254
  assignment operator for a union of type `U` with a glvalue argument that
255
  does not denote an object of type cv `U` within its lifetime, the
256
  behavior is undefined.
257
 
258
- [*Note 10*: In C, an entire object of structure type can be accessed,
259
  e.g., using assignment. By contrast, C++ has no notion of accessing an
260
  object of class type through an lvalue of class type. — *end note*]
261
 
262
  ### Type <a id="expr.type">[[expr.type]]</a>
263
 
264
  If an expression initially has the type “reference to `T`”
265
  [[dcl.ref]], [[dcl.init.ref]], the type is adjusted to `T` prior to any
266
- further analysis. The expression designates the object or function
267
- denoted by the reference, and the expression is an lvalue or an xvalue,
268
- depending on the expression.
 
 
269
 
270
  [*Note 1*: Before the lifetime of the reference has started or after it
271
  has ended, the behavior is undefined (see 
272
  [[basic.life]]). — *end note*]
273
 
@@ -287,15 +294,15 @@ pointer-to-member type or `std::nullptr_t`, is:
287
  “pointer to *cv12* `void`”, where *cv12* is the union of *cv1* and
288
  *cv2*;
289
  - if `T1` or `T2` is “pointer to `noexcept` function” and the other type
290
  is “pointer to function”, where the function types are otherwise the
291
  same, “pointer to function”;
292
- - if `T1` is “pointer to *cv1* `C1`” and `T2` is “pointer to *cv2*
293
- `C2`”, where `C1` is reference-related to `C2` or `C2` is
294
- reference-related to `C1` [[dcl.init.ref]], the qualification-combined
295
- type [[conv.qual]] of `T1` and `T2` or the qualification-combined type
296
- of `T2` and `T1`, respectively;
297
  - if `T1` or `T2` is “pointer to member of `C1` of type function”, the
298
  other type is “pointer to member of `C2` of type `noexcept` function”,
299
  and `C1` is reference-related to `C2` or `C2` is reference-related to
300
  `C1` [[dcl.init.ref]], where the function types are otherwise the
301
  same, “pointer to member of `C2` of type function” or “pointer to
@@ -327,11 +334,11 @@ pointer to `const int`”.
327
  — *end example*]
328
 
329
  ### Context dependence <a id="expr.context">[[expr.context]]</a>
330
 
331
  In some contexts, *unevaluated operands* appear
332
- [[expr.prim.req]], [[expr.typeid]], [[expr.sizeof]], [[expr.unary.noexcept]], [[dcl.type.decltype]], [[temp.pre]], [[temp.concept]].
333
  An unevaluated operand is not evaluated.
334
 
335
  [*Note 1*: In an unevaluated operand, a non-static class member can be
336
  named [[expr.prim.id]] and naming of objects or functions does not, by
337
  itself, require that a definition be provided [[basic.def.odr]]. An
@@ -345,10 +352,11 @@ standard conversions are not applied. The lvalue-to-rvalue conversion
345
  [[conv.lval]] is applied if and only if the expression is a glvalue of
346
  volatile-qualified type and it is one of the following:
347
 
348
  - `(` *expression* `)`, where *expression* is one of these expressions,
349
  - *id-expression* [[expr.prim.id]],
 
350
  - subscripting [[expr.sub]],
351
  - class member access [[expr.ref]],
352
  - indirection [[expr.unary.op]],
353
  - pointer-to-member operation [[expr.mptr.oper]],
354
  - conditional expression [[expr.cond]] where both the second and the
@@ -390,11 +398,12 @@ following order:
390
 
391
  [*Note 1*: A standard conversion sequence can be empty, i.e., it can
392
  consist of no conversions. — *end note*]
393
 
394
  A standard conversion sequence will be applied to an expression if
395
- necessary to convert it to a required destination type.
 
396
 
397
  [*Note 2*:
398
 
399
  Expressions with a given type will be implicitly converted to other
400
  types in several contexts:
@@ -412,12 +421,12 @@ types in several contexts:
412
  [[dcl.init.ref]].
413
 
414
  — *end note*]
415
 
416
  An expression E can be *implicitly converted* to a type `T` if and only
417
- if the declaration `T t=E;` is well-formed, for some invented temporary
418
- variable `t` [[dcl.init]].
419
 
420
  Certain language constructs require that an expression be converted to a
421
  Boolean value. An expression E appearing in such a context is said to be
422
  *contextually converted to `bool`* and is well-formed if and only if the
423
  declaration `bool t(E);` is well-formed, for some invented temporary
@@ -497,15 +506,30 @@ rules:
497
  `T` is volatile-qualified [[intro.execution]], and the glvalue can
498
  refer to an inactive member of a union [[class.union]]. — *end note*]
499
  - Otherwise, if `T` has a class type, the conversion copy-initializes
500
  the result object from the glvalue.
501
  - Otherwise, if the object to which the glvalue refers contains an
502
- invalid pointer value [[basic.stc.dynamic.deallocation]], the behavior
503
- is *implementation-defined*.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
504
  - Otherwise, the object indicated by the glvalue is read
505
- [[defns.access]], and the value contained in the object is the prvalue
506
- result.
 
507
 
508
  [*Note 2*: See also  [[basic.lval]]. — *end note*]
509
 
510
  ### Array-to-pointer conversion <a id="conv.array">[[conv.array]]</a>
511
 
@@ -554,14 +578,10 @@ element type are also taken as the cv-qualifiers cvᵢ of the array.
554
  [*Example 1*: The type denoted by the *type-id* `const int **` has
555
  three qualification-decompositions, taking `U` as “`int`”, as “pointer
556
  to `const int`”, and as “pointer to pointer to
557
  `const int`”. — *end example*]
558
 
559
- The n-tuple of cv-qualifiers after the first one in the longest
560
- qualification-decomposition of `T`, that is, cv₁, cv₂, …, cvₙ, is called
561
- the *cv-qualification signature* of `T`.
562
-
563
  Two types `T1` and `T2` are *similar* if they have
564
  qualification-decompositions with the same n such that corresponding Pᵢ
565
  components are either the same or one is “array of Nᵢ” and the other is
566
  “array of unknown bound of”, and the types denoted by `U` are the same.
567
 
@@ -613,24 +633,20 @@ than “*cv1* `T`”. — *end note*]
613
  pointer-to-member-function types) are never cv-qualified
614
  [[dcl.fct]]. — *end note*]
615
 
616
  ### Integral promotions <a id="conv.prom">[[conv.prom]]</a>
617
 
618
- A prvalue of an integer type other than `bool`, `char8_t`, `char16_t`,
619
- `char32_t`, or `wchar_t` whose integer conversion rank [[conv.rank]] is
620
- less than the rank of `int` can be converted to a prvalue of type `int`
621
- if `int` can represent all the values of the source type; otherwise, the
622
- source prvalue can be converted to a prvalue of type `unsigned int`.
623
 
624
- A prvalue of type `char8_t`, `char16_t`, `char32_t`, or `wchar_t`
625
- [[basic.fundamental]] can be converted to a prvalue of the first of the
626
- following types that can represent all the values of its underlying
627
- type: `int`, `unsigned int`, `long int`, `unsigned long int`,
628
- `long long int`, or `unsigned long long int`. If none of the types in
629
- that list can represent all the values of its underlying type, a prvalue
630
- of type `char8_t`, `char16_t`, `char32_t`, or `wchar_t` can be converted
631
- to a prvalue of its underlying type.
632
 
633
  A prvalue of an unscoped enumeration type whose underlying type is not
634
  fixed can be converted to a prvalue of the first of the following types
635
  that can represent all the values of the enumeration [[dcl.enum]]:
636
  `int`, `unsigned int`, `long int`, `unsigned long int`, `long long int`,
@@ -646,17 +662,25 @@ A prvalue of an unscoped enumeration type whose underlying type is fixed
646
  [[dcl.enum]] can be converted to a prvalue of its underlying type.
647
  Moreover, if integral promotion can be applied to its underlying type, a
648
  prvalue of an unscoped enumeration type whose underlying type is fixed
649
  can also be converted to a prvalue of the promoted underlying type.
650
 
651
- A prvalue for an integral bit-field [[class.bit]] can be converted to a
652
- prvalue of type `int` if `int` can represent all the values of the
653
- bit-field; otherwise, it can be converted to `unsigned int` if
654
- `unsigned int` can represent all the values of the bit-field. If the
655
- bit-field is larger yet, no integral promotion applies to it. If the
656
- bit-field has enumeration type, it is treated as any other value of that
657
- type for promotion purposes.
 
 
 
 
 
 
 
 
658
 
659
  A prvalue of type `bool` can be converted to a prvalue of type `int`,
660
  with `false` becoming zero and `true` becoming one.
661
 
662
  These conversions are called *integral promotions*.
@@ -732,60 +756,64 @@ to one.
732
  A *null pointer constant* is an integer literal [[lex.icon]] with value
733
  zero or a prvalue of type `std::nullptr_t`. A null pointer constant can
734
  be converted to a pointer type; the result is the null pointer value of
735
  that type [[basic.compound]] and is distinguishable from every other
736
  value of object pointer or function pointer type. Such a conversion is
737
- called a *null pointer conversion*. Two null pointer values of the same
738
- type shall compare equal. The conversion of a null pointer constant to a
739
- pointer to cv-qualified type is a single conversion, and not the
740
- sequence of a pointer conversion followed by a qualification conversion
741
- [[conv.qual]]. A null pointer constant of integral type can be converted
742
- to a prvalue of type `std::nullptr_t`.
743
 
744
  [*Note 1*: The resulting prvalue is not a null pointer
745
  value. — *end note*]
746
 
747
  A prvalue of type “pointer to cv `T`”, where `T` is an object type, can
748
  be converted to a prvalue of type “pointer to cv `void`”. The pointer
749
  value [[basic.compound]] is unchanged by this conversion.
750
 
751
- A prvalue of type “pointer to cv `D`”, where `D` is a complete class
752
  type, can be converted to a prvalue of type “pointer to cv `B`”, where
753
  `B` is a base class [[class.derived]] of `D`. If `B` is an inaccessible
754
  [[class.access]] or ambiguous [[class.member.lookup]] base class of `D`,
755
- a program that necessitates this conversion is ill-formed. The result of
756
- the conversion is a pointer to the base class subobject of the derived
757
- class object. The null pointer value is converted to the null pointer
758
- value of the destination type.
 
 
 
759
 
760
  ### Pointer-to-member conversions <a id="conv.mem">[[conv.mem]]</a>
761
 
762
  A null pointer constant [[conv.ptr]] can be converted to a
763
  pointer-to-member type; the result is the *null member pointer value* of
764
  that type and is distinguishable from any pointer to member not created
765
  from a null pointer constant. Such a conversion is called a *null member
766
- pointer conversion*. Two null member pointer values of the same type
767
- shall compare equal. The conversion of a null pointer constant to a
768
  pointer to member of cv-qualified type is a single conversion, and not
769
  the sequence of a pointer-to-member conversion followed by a
770
  qualification conversion [[conv.qual]].
771
 
772
  A prvalue of type “pointer to member of `B` of type cv `T`”, where `B`
773
  is a class type, can be converted to a prvalue of type “pointer to
774
  member of `D` of type cv `T`”, where `D` is a complete class derived
775
  [[class.derived]] from `B`. If `B` is an inaccessible [[class.access]],
776
  ambiguous [[class.member.lookup]], or virtual [[class.mi]] base class of
777
  `D`, or a base class of a virtual base class of `D`, a program that
778
- necessitates this conversion is ill-formed. The result of the conversion
779
- refers to the same member as the pointer to member before the conversion
780
- took place, but it refers to the base class member as if it were a
781
- member of the derived class. The result refers to the member in `D`’s
782
- instance of `B`. Since the result has type “pointer to member of `D` of
783
- type cv `T`”, indirection through it with a `D` object is valid. The
784
- result is the same as if indirecting through the pointer to member of
785
- `B` with the `B` subobject of `D`. The null member pointer value is
786
- converted to the null member pointer value of the destination type.[^8]
 
 
 
787
 
788
  ### Function pointer conversions <a id="conv.fctptr">[[conv.fctptr]]</a>
789
 
790
  A prvalue of type “pointer to `noexcept` function” can be converted to a
791
  prvalue of type “pointer to function”. The result is a pointer to the
@@ -818,17 +846,23 @@ Many binary operators that expect operands of arithmetic or enumeration
818
  type cause conversions and yield result types in a similar way. The
819
  purpose is to yield a common type, which is also the type of the result.
820
  This pattern is called the *usual arithmetic conversions*, which are
821
  defined as follows:
822
 
 
 
 
823
  - If either operand is of scoped enumeration type [[dcl.enum]], no
824
  conversions are performed; if the other operand does not have the same
825
  type, the expression is ill-formed.
 
 
 
826
  - Otherwise, if either operand is of floating-point type, the following
827
  rules are applied:
828
  - If both operands have the same type, no further conversion is
829
- needed.
830
  - Otherwise, if one of the operands is of a non-floating-point type,
831
  that operand is converted to the type of the operand with the
832
  floating-point type.
833
  - Otherwise, if the floating-point conversion ranks [[conv.rank]] of
834
  the types of the operands are ordered but not equal, then the
@@ -852,25 +886,24 @@ defined as follows:
852
  `U`.
853
  - Otherwise, if `S` can represent all of the values of `U`, `C` is
854
  `S`.
855
  - Otherwise, `C` is the unsigned integer type corresponding to `S`.
856
 
857
- If one operand is of enumeration type and the other operand is of a
858
- different enumeration type or a floating-point type, this behavior is
859
- deprecated [[depr.arith.conv.enum]].
860
-
861
  ## Primary expressions <a id="expr.prim">[[expr.prim]]</a>
862
 
 
 
863
  ``` bnf
864
  primary-expression:
865
  literal
866
  this
867
  '(' expression ')'
868
  id-expression
869
  lambda-expression
870
  fold-expression
871
  requires-expression
 
872
  ```
873
 
874
  ### Literals <a id="expr.prim.literal">[[expr.prim.literal]]</a>
875
 
876
  The type of a *literal* is determined based on its form as specified in
@@ -890,19 +923,26 @@ The *current class* at a program point is the class associated with the
890
  innermost class scope containing that point.
891
 
892
  [*Note 1*: A *lambda-expression* does not introduce a class
893
  scope. — *end note*]
894
 
 
 
 
 
 
 
 
895
  If a declaration declares a member function or member function template
896
  of a class `X`, the expression `this` is a prvalue of type “pointer to
897
  *cv-qualifier-seq* `X`” wherever `X` is the current class between the
898
  optional *cv-qualifier-seq* and the end of the *function-definition*,
899
  *member-declarator*, or *declarator*. It shall not appear within the
900
- declaration of either a static member function or an explicit object
901
- member function of the current class (although its type and value
902
- category are defined within such member functions as they are within an
903
- implicit object member function).
904
 
905
  [*Note 2*: This is because declaration matching does not occur until
906
  the complete declarator is known. — *end note*]
907
 
908
  [*Note 3*:
@@ -966,62 +1006,104 @@ otherwise indicated.
966
 
967
  ``` bnf
968
  id-expression:
969
  unqualified-id
970
  qualified-id
 
971
  ```
972
 
973
  An *id-expression* is a restricted form of a *primary-expression*.
974
 
975
  [*Note 1*: An *id-expression* can appear after `.` and `->` operators
976
  [[expr.ref]]. — *end note*]
977
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
978
  If an *id-expression* E denotes a member M of an anonymous union
979
  [[class.union.anon]] U:
980
 
981
  - If U is a non-static data member, E refers to M as a member of the
982
- lookup context of the terminal name of E (after any transformation to
983
- a class member access expression [[class.mfct.non.static]]).
984
- \[*Example 1*: `o.x` is interpreted as `o.u.x`, where u names the
985
  anonymous union member. — *end example*]
986
  - Otherwise, E is interpreted as a class member access [[expr.ref]] that
987
  designates the member subobject M of the anonymous union variable for
988
- U. \[*Note 2*: Under this interpretation, E no longer denotes a
989
- non-static data member. — *end note*] \[*Example 2*: `N::x` is
990
  interpreted as `N::u.x`, where u names the anonymous union
991
  variable. — *end example*]
992
 
993
- An *id-expression* that denotes a non-static data member or implicit
994
- object member function of a class can only be used:
 
995
 
996
- - as part of a class member access [[expr.ref]] in which the object
997
- expression refers to the member’s class[^10] or a class derived from
998
- that class, or
999
  - to form a pointer to member [[expr.unary.op]], or
1000
- - if that *id-expression* denotes a non-static data member and it
1001
- appears in an unevaluated operand.
1002
- \[*Example 3*:
1003
  ``` cpp
1004
  struct S {
1005
  int m;
1006
  };
1007
  int i = sizeof(S::m); // OK
1008
  int j = sizeof(S::m + 42); // OK
 
1009
  ```
1010
 
1011
  — *end example*]
1012
 
1013
  For an *id-expression* that denotes an overload set, overload resolution
1014
  is performed to select a unique function [[over.match]], [[over.over]].
1015
 
1016
- [*Note 3*:
1017
 
1018
  A program cannot refer to a function with a trailing *requires-clause*
1019
  whose *constraint-expression* is not satisfied, because such functions
1020
  are never selected by overload resolution.
1021
 
1022
- [*Example 4*:
1023
 
1024
  ``` cpp
1025
  template<typename T> struct A {
1026
  static void f(int) requires false;
1027
  };
@@ -1032,12 +1114,12 @@ void g() {
1032
  decltype(A<int>::f)* p2 = nullptr; // error: the type decltype(A<int>::f) is invalid
1033
  }
1034
  ```
1035
 
1036
  In each case, the constraints of `f` are not satisfied. In the
1037
- declaration of `p2`, those constraints are required to be satisfied even
1038
- though `f` is an unevaluated operand [[term.unevaluated.operand]].
1039
 
1040
  — *end example*]
1041
 
1042
  — *end note*]
1043
 
@@ -1048,27 +1130,24 @@ unqualified-id:
1048
  identifier
1049
  operator-function-id
1050
  conversion-function-id
1051
  literal-operator-id
1052
  '~' type-name
1053
- '~' decltype-specifier
1054
  template-id
1055
  ```
1056
 
1057
  An *identifier* is only an *id-expression* if it has been suitably
1058
- declared [[dcl.dcl]] or if it appears as part of a *declarator-id*
1059
- [[dcl.decl]]. An *identifier* that names a coroutine parameter refers to
1060
- the copy of the parameter [[dcl.fct.def.coroutine]].
1061
 
1062
  [*Note 1*: For *operator-function-id*s, see  [[over.oper]]; for
1063
  *conversion-function-id*s, see  [[class.conv.fct]]; for
1064
  *literal-operator-id*s, see  [[over.literal]]; for *template-id*s, see 
1065
- [[temp.names]]. A *type-name* or *decltype-specifier* prefixed by `~`
1066
- denotes the destructor of the type so named; see  [[expr.prim.id.dtor]].
1067
- Within the definition of a non-static member function, an *identifier*
1068
- that names a non-static member is transformed to a class member access
1069
- expression [[class.mfct.non.static]]. — *end note*]
1070
 
1071
  A *component name* of an *unqualified-id* U is
1072
 
1073
  - U if it is a name or
1074
  - the component name of the *template-id* or *type-name* of U, if any.
@@ -1079,46 +1158,147 @@ several component names
1079
 
1080
  The *terminal name* of a construct is the component name of that
1081
  construct that appears lexically last.
1082
 
1083
  The result is the entity denoted by the *unqualified-id*
1084
- [[basic.lookup.unqual]]. If the *unqualified-id* appears in a
1085
- *lambda-expression* at program point P and the entity is a local entity
1086
- [[basic.pre]] or a variable declared by an *init-capture*
1087
- [[expr.prim.lambda.capture]], then let S be the *compound-statement* of
1088
- the innermost enclosing *lambda-expression* of P. If naming the entity
1089
- from outside of an unevaluated operand within S would refer to an entity
1090
- captured by copy in some intervening *lambda-expression*, then let E be
1091
- the innermost such *lambda-expression*.
1092
-
1093
- - If there is such a *lambda-expression* and if P is in E’s function
1094
- parameter scope but not its *parameter-declaration-clause*, then the
1095
- type of the expression is the type of a class member access expression
1096
- [[expr.ref]] naming the non-static data member that would be declared
1097
- for such a capture in the object parameter [[dcl.fct]] of the function
1098
- call operator of E. \[*Note 3*: If E is not declared `mutable`, the
1099
- type of such an identifier will typically be `const`
1100
- qualified. *end note*]
1101
- - Otherwise (if there is no such *lambda-expression* or if P either
1102
- precedes E’s function parameter scope or is in E’s
1103
- *parameter-declaration-clause*), the type of the expression is the
1104
- type of the result.
1105
-
1106
- [*Note 4*: If the entity is a template parameter object for a template
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1107
  parameter of type `T` [[temp.param]], the type of the expression is
1108
- `const T`. — *end note*]
1109
 
1110
- [*Note 5*: The type will be adjusted as described in [[expr.type]] if
 
 
 
1111
  it is cv-qualified or is a reference type. — *end note*]
1112
 
1113
  The expression is an xvalue if it is move-eligible (see below); an
1114
  lvalue if the entity is a function, variable, structured binding
1115
- [[dcl.struct.bind]], data member, or template parameter object; and a
1116
- prvalue otherwise [[basic.lval]]; it is a bit-field if the identifier
1117
- designates a bit-field.
1118
 
1119
- [*Example 1*:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1120
 
1121
  ``` cpp
1122
  void f() {
1123
  float x, &r = x;
1124
 
@@ -1145,27 +1325,23 @@ void f() {
1145
  }
1146
  ```
1147
 
1148
  — *end example*]
1149
 
1150
- An *implicitly movable entity* is a variable of automatic storage
1151
  duration that is either a non-volatile object or an rvalue reference to
1152
- a non-volatile object type. In the following contexts, an
1153
- *id-expression* is *move-eligible*:
1154
 
1155
- - If the *id-expression* (possibly parenthesized) is the operand of a
1156
- `return` [[stmt.return]] or `co_return` [[stmt.return.coroutine]]
1157
- statement, and names an implicitly movable entity declared in the body
1158
- or *parameter-declaration-clause* of the innermost enclosing function
1159
- or *lambda-expression*, or
1160
- - if the *id-expression* (possibly parenthesized) is the operand of a
1161
- *throw-expression* [[expr.throw]], and names an implicitly movable
1162
- entity that belongs to a scope that does not contain the
1163
- *compound-statement* of the innermost *lambda-expression*,
1164
- *try-block*, or *function-try-block* (if any) whose
1165
- *compound-statement* or *ctor-initializer* contains the
1166
- *throw-expression*.
1167
 
1168
  #### Qualified names <a id="expr.prim.id.qual">[[expr.prim.id.qual]]</a>
1169
 
1170
  ``` bnf
1171
  qualified-id:
@@ -1175,71 +1351,152 @@ qualified-id:
1175
  ``` bnf
1176
  nested-name-specifier:
1177
  '::'
1178
  type-name '::'
1179
  namespace-name '::'
1180
- decltype-specifier '::'
 
1181
  nested-name-specifier identifier '::'
1182
  nested-name-specifier templateₒₚₜ simple-template-id '::'
1183
  ```
1184
 
 
 
 
 
 
 
1185
  The component names of a *qualified-id* are those of its
1186
  *nested-name-specifier* and *unqualified-id*. The component names of a
1187
  *nested-name-specifier* are its *identifier* (if any) and those of its
1188
  *type-name*, *namespace-name*, *simple-template-id*, and/or
1189
  *nested-name-specifier*.
1190
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1191
  A *nested-name-specifier* is *declarative* if it is part of
1192
 
1193
  - a *class-head-name*,
1194
  - an *enum-head-name*,
1195
  - a *qualified-id* that is the *id-expression* of a *declarator-id*, or
1196
  - a declarative *nested-name-specifier*.
1197
 
1198
  A declarative *nested-name-specifier* shall not have a
1199
- *decltype-specifier*. A declaration that uses a declarative
1200
- *nested-name-specifier* shall be a friend declaration or inhabit a scope
1201
- that contains the entity being redeclared or specialized.
 
1202
 
1203
- The *nested-name-specifier* `::` nominates the global namespace. A
1204
- *nested-name-specifier* with a *decltype-specifier* nominates the type
1205
- denoted by the *decltype-specifier*, which shall be a class or
1206
- enumeration type. If a *nested-name-specifier* N is declarative and has
1207
- a *simple-template-id* with a template argument list A that involves a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1208
  template parameter, let T be the template nominated by N without A. T
1209
  shall be a class template.
1210
-
1211
  - If A is the template argument list [[temp.arg]] of the corresponding
1212
- *template-head* H [[temp.mem]], N nominates the primary template of T;
1213
- H shall be equivalent to the *template-head* of T [[temp.over.link]].
1214
- - Otherwise, N nominates the partial specialization
1215
- [[temp.spec.partial]] of T whose template argument list is equivalent
1216
- to A [[temp.over.link]]; the program is ill-formed if no such partial
1217
- specialization exists.
1218
-
1219
- Any other *nested-name-specifier* nominates the entity denoted by its
1220
- *type-name*, *namespace-name*, *identifier*, or *simple-template-id*. If
1221
- the *nested-name-specifier* is not declarative, the entity shall not be
1222
- a template.
1223
 
1224
  A *qualified-id* shall not be of the form *nested-name-specifier*
1225
- `template`ₒₚₜ `~` *decltype-specifier* nor of the form
1226
- *decltype-specifier* `::` `~` *type-name*.
1227
 
1228
  The result of a *qualified-id* Q is the entity it denotes
1229
- [[basic.lookup.qual]]. The type of the expression is the type of the
1230
- result. The result is an lvalue if the member is
 
 
 
 
 
 
 
 
 
 
 
 
 
1231
 
1232
  - a function other than a non-static member function,
1233
  - a non-static member function if Q is the operand of a unary `&`
1234
  operator,
1235
  - a variable,
1236
  - a structured binding [[dcl.struct.bind]], or
1237
  - a data member,
1238
 
1239
  and a prvalue otherwise.
1240
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1241
  #### Destruction <a id="expr.prim.id.dtor">[[expr.prim.id.dtor]]</a>
1242
 
1243
  An *id-expression* that denotes the destructor of a type `T` names the
1244
  destructor of `T` if `T` is a class type [[class.dtor]], otherwise the
1245
  *id-expression* is said to name a *pseudo-destructor*.
@@ -1286,14 +1543,15 @@ lambda-introducer:
1286
  ```
1287
 
1288
  ``` bnf
1289
  lambda-declarator:
1290
  lambda-specifier-seq noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ trailing-return-typeₒₚₜ
1291
- noexcept-specifier attribute-specifier-seqₒₚₜ trailing-return-typeₒₚₜ
1292
- trailing-return-typeₒₚₜ
 
1293
  '(' parameter-declaration-clause ')' lambda-specifier-seqₒₚₜ noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ
1294
- trailing-return-typeₒₚₜ requires-clauseₒₚₜ
1295
  ```
1296
 
1297
  ``` bnf
1298
  lambda-specifier:
1299
  consteval
@@ -1302,12 +1560,11 @@ lambda-specifier:
1302
  static
1303
  ```
1304
 
1305
  ``` bnf
1306
  lambda-specifier-seq:
1307
- lambda-specifier
1308
- lambda-specifier lambda-specifier-seq
1309
  ```
1310
 
1311
  A *lambda-expression* provides a concise way to create a simple function
1312
  object.
1313
 
@@ -1333,12 +1590,24 @@ An ambiguity can arise because a *requires-clause* can end in an
1333
  *attribute-specifier-seq*, which collides with the
1334
  *attribute-specifier-seq* in *lambda-expression*. In such cases, any
1335
  attributes are treated as *attribute-specifier-seq* in
1336
  *lambda-expression*.
1337
 
1338
- [*Note 2*: Such ambiguous cases cannot have valid semantics because the
1339
- constraint expression would not have type `bool`. — *end note*]
 
 
 
 
 
 
 
 
 
 
 
 
1340
 
1341
  A *lambda-specifier-seq* shall contain at most one of each
1342
  *lambda-specifier* and shall not contain both `constexpr` and
1343
  `consteval`. If the *lambda-declarator* contains an explicit object
1344
  parameter [[dcl.fct]], then no *lambda-specifier* in the
@@ -1348,19 +1617,20 @@ the *lambda-specifier-seq* contains `static`, there shall be no
1348
  *lambda-capture*.
1349
 
1350
  [*Note 3*: The trailing *requires-clause* is described in
1351
  [[dcl.decl]]. — *end note*]
1352
 
1353
- If a *lambda-declarator* does not include a
1354
- *parameter-declaration-clause*, it is as if `()` were inserted at the
1355
- start of the *lambda-declarator*. If the *lambda-declarator* does not
1356
- include a *trailing-return-type*, it is considered to be `-> auto`.
 
1357
 
1358
  [*Note 4*: In that case, the return type is deduced from `return`
1359
  statements as described in [[dcl.spec.auto]]. — *end note*]
1360
 
1361
- [*Example 2*:
1362
 
1363
  ``` cpp
1364
  auto x1 = [](int i) { return i; }; // OK, return type is int
1365
  auto x2 = []{ return { 1, 2 }; }; // error: deducing return type from braced-init-list
1366
  int j;
@@ -1371,53 +1641,62 @@ auto x3 = [&]()->auto&& { return j; }; // OK, return type is int&
1371
 
1372
  A lambda is a *generic lambda* if the *lambda-expression* has any
1373
  generic parameter type placeholders [[dcl.spec.auto]], or if the lambda
1374
  has a *template-parameter-list*.
1375
 
1376
- [*Example 3*:
1377
 
1378
  ``` cpp
1379
- int i = [](int i, auto a) { return i; }(3, 4); // OK, a generic lambda
1380
- int j = []<class T>(T t, int i) { return i; }(3, 4); // OK, a generic lambda
 
1381
  ```
1382
 
1383
  — *end example*]
1384
 
1385
  #### Closure types <a id="expr.prim.lambda.closure">[[expr.prim.lambda.closure]]</a>
1386
 
1387
  The type of a *lambda-expression* (which is also the type of the closure
1388
  object) is a unique, unnamed non-union class type, called the *closure
1389
  type*, whose properties are described below.
1390
 
 
 
 
1391
  The closure type is declared in the smallest block scope, class scope,
1392
  or namespace scope that contains the corresponding *lambda-expression*.
1393
 
1394
  [*Note 1*: This determines the set of namespaces and classes associated
1395
  with the closure type [[basic.lookup.argdep]]. The parameter types of a
1396
  *lambda-declarator* do not affect these associated namespaces and
1397
  classes. — *end note*]
1398
 
1399
- The closure type is not an aggregate type [[dcl.init.aggr]]. An
1400
- implementation may define the closure type differently from what is
1401
- described below provided this does not alter the observable behavior of
1402
- the program other than by changing:
 
1403
 
1404
  - the size and/or alignment of the closure type,
1405
- - whether the closure type is trivially copyable [[class.prop]], or
 
 
1406
  - whether the closure type is a standard-layout class [[class.prop]].
1407
 
1408
  An implementation shall not add members of rvalue reference type to the
1409
  closure type.
1410
 
1411
  The closure type for a *lambda-expression* has a public inline function
1412
  call operator (for a non-generic lambda) or function call operator
1413
  template (for a generic lambda) [[over.call]] whose parameters and
1414
- return type are described by the *lambda-expression*s
1415
  *parameter-declaration-clause* and *trailing-return-type* respectively,
1416
  and whose *template-parameter-list* consists of the specified
1417
- *template-parameter-list*, if any. The *requires-clause* of the function
1418
- call operator template is the *requires-clause* immediately following
 
 
1419
  `<` *template-parameter-list* `>`, if any. The trailing
1420
  *requires-clause* of the function call operator or operator template is
1421
  the *requires-clause* of the *lambda-declarator*, if any.
1422
 
1423
  [*Note 2*: The function call operator template for a generic lambda can
@@ -1454,11 +1733,12 @@ std::cout << fact(5); // OK, outputs 1
1454
  Given a lambda with a *lambda-capture*, the type of the explicit object
1455
  parameter, if any, of the lambda’s function call operator (possibly
1456
  instantiated from a function call operator template) shall be either:
1457
 
1458
  - the closure type,
1459
- - a class type derived from the closure type, or
 
1460
  - a reference to a possibly cv-qualified such type.
1461
 
1462
  [*Example 2*:
1463
 
1464
  ``` cpp
@@ -1482,13 +1762,14 @@ function or static member function template [[class.static.mfct]] if the
1482
  `static`. Otherwise, it is a non-static member function or member
1483
  function template [[class.mfct.non.static]] that is declared `const`
1484
  [[class.mfct.non.static]] if and only if the *lambda-expression*’s
1485
  *parameter-declaration-clause* is not followed by `mutable` and the
1486
  *lambda-declarator* does not contain an explicit object parameter. It is
1487
- neither virtual nor declared `volatile`. Any *noexcept-specifier*
1488
- specified on a *lambda-expression* applies to the corresponding function
1489
- call operator or operator template. An *attribute-specifier-seq* in a
 
1490
  *lambda-declarator* appertains to the type of the corresponding function
1491
  call operator or operator template. An *attribute-specifier-seq* in a
1492
  *lambda-expression* preceding a *lambda-declarator* appertains to the
1493
  corresponding function call operator or operator template. The function
1494
  call operator or any given operator template specialization is a
@@ -1567,35 +1848,80 @@ auto f = []<typename T1, C1 T2> requires C2<sizeof(T1) + sizeof(T2)>
1567
 
1568
  — *end example*]
1569
 
1570
  — *end note*]
1571
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1572
  The closure type for a non-generic *lambda-expression* with no
1573
- *lambda-capture* whose constraints (if any) are satisfied has a
1574
- conversion function to pointer to function with C++ language linkage
1575
- [[dcl.link]] having the same parameter and return types as the closure
1576
- type’s function call operator. The conversion is to “pointer to
1577
- `noexcept` function” if the function call operator has a non-throwing
1578
- exception specification. If the function call operator is a static
1579
- member function, then the value returned by this conversion function is
1580
- the address of the function call operator. Otherwise, the value returned
1581
- by this conversion function is the address of a function `F` that, when
1582
- invoked, has the same effect as invoking the closure type’s function
1583
- call operator on a default-constructed instance of the closure type. `F`
1584
- is a constexpr function if the function call operator is a constexpr
1585
- function and is an immediate function if the function call operator is
1586
- an immediate function.
 
1587
 
1588
- For a generic lambda with no *lambda-capture*, the closure type has a
1589
- conversion function template to pointer to function. The conversion
1590
- function template has the same invented template parameter list, and the
1591
- pointer to function has the same parameter types, as the function call
1592
- operator template. The return type of the pointer to function shall
1593
- behave as if it were a *decltype-specifier* denoting the return type of
1594
- the corresponding function call operator template specialization.
 
1595
 
1596
- [*Note 4*:
1597
 
1598
  If the generic lambda has no *trailing-return-type* or the
1599
  *trailing-return-type* contains a placeholder type, return type
1600
  deduction of the corresponding function call operator template
1601
  specialization has to be done. The corresponding specialization is that
@@ -1627,11 +1953,11 @@ struct Closure {
1627
  };
1628
  ```
1629
 
1630
  — *end note*]
1631
 
1632
- [*Example 6*:
1633
 
1634
  ``` cpp
1635
  void f1(int (*)(int)) { }
1636
  void f2(char (*)(int)) { }
1637
 
@@ -1651,27 +1977,26 @@ int& (*fpi)(int*) = [](auto* a) -> auto& { return *a; }; // OK
1651
 
1652
  — *end example*]
1653
 
1654
  If the function call operator template is a static member function
1655
  template, then the value returned by any given specialization of this
1656
- conversion function template is the address of the corresponding
1657
- function call operator template specialization. Otherwise, the value
1658
- returned by any given specialization of this conversion function
1659
- template is the address of a function `F` that, when invoked, has the
1660
- same effect as invoking the generic lambda’s corresponding function call
1661
- operator template specialization on a default-constructed instance of
1662
- the closure type. `F` is a constexpr function if the corresponding
1663
- specialization is a constexpr function and `F` is an immediate function
1664
- if the function call operator template specialization is an immediate
1665
- function.
1666
 
1667
- [*Note 5*: This will result in the implicit instantiation of the
1668
  generic lambda’s body. The instantiated generic lambda’s return type and
1669
- parameter types are required to match the return type and parameter
1670
- types of the pointer to function. — *end note*]
1671
 
1672
- [*Example 7*:
1673
 
1674
  ``` cpp
1675
  auto GL = [](auto a) { std::cout << a; return a; };
1676
  int (*GL_int)(int) = GL; // OK, through conversion function template
1677
  GL_int(3); // OK, same as GL(3)
@@ -1681,11 +2006,11 @@ GL_int(3); // OK, same as GL(3)
1681
 
1682
  The conversion function or conversion function template is public,
1683
  constexpr, non-virtual, non-explicit, const, and has a non-throwing
1684
  exception specification [[except.spec]].
1685
 
1686
- [*Example 8*:
1687
 
1688
  ``` cpp
1689
  auto Fwd = [](int (*fp)(int), auto a) { return fp(a); };
1690
  auto C = [](auto a) { return a; };
1691
 
@@ -1700,11 +2025,11 @@ static_assert(Fwd(NC,3) == 3); // error
1700
 
1701
  The *lambda-expression*’s *compound-statement* yields the
1702
  *function-body* [[dcl.fct.def]] of the function call operator, but it is
1703
  not within the scope of the closure type.
1704
 
1705
- [*Example 9*:
1706
 
1707
  ``` cpp
1708
  struct S1 {
1709
  int x, y;
1710
  int operator()(int);
@@ -1717,23 +2042,25 @@ struct S1 {
1717
  };
1718
  ```
1719
 
1720
  — *end example*]
1721
 
1722
- Further, a variable `__func__` is implicitly defined at the beginning of
1723
- the *compound-statement* of the *lambda-expression*, with semantics as
1724
- described in  [[dcl.fct.def.general]].
 
 
1725
 
1726
  The closure type associated with a *lambda-expression* has no default
1727
  constructor if the *lambda-expression* has a *lambda-capture* and a
1728
  defaulted default constructor otherwise. It has a defaulted copy
1729
  constructor and a defaulted move constructor [[class.copy.ctor]]. It has
1730
  a deleted copy assignment operator if the *lambda-expression* has a
1731
  *lambda-capture* and defaulted copy and move assignment operators
1732
  otherwise [[class.copy.assign]].
1733
 
1734
- [*Note 6*: These special member functions are implicitly defined as
1735
  usual, which can result in them being defined as deleted. — *end note*]
1736
 
1737
  The closure type associated with a *lambda-expression* has an
1738
  implicitly-declared destructor [[class.dtor]].
1739
 
@@ -1771,30 +2098,30 @@ capture:
1771
  ``` bnf
1772
  simple-capture:
1773
  identifier '...'ₒₚₜ
1774
  '&' identifier '...'ₒₚₜ
1775
  this
1776
- '*' 'this'
1777
  ```
1778
 
1779
  ``` bnf
1780
  init-capture:
1781
  '...'ₒₚₜ identifier initializer
1782
  '&' '...'ₒₚₜ identifier initializer
1783
  ```
1784
 
1785
  The body of a *lambda-expression* may refer to local entities of
1786
- enclosing block scopes by capturing those entities, as described below.
1787
 
1788
  If a *lambda-capture* includes a *capture-default* that is `&`, no
1789
  identifier in a *simple-capture* of that *lambda-capture* shall be
1790
  preceded by `&`. If a *lambda-capture* includes a *capture-default* that
1791
  is `=`, each *simple-capture* of that *lambda-capture* shall be of the
1792
  form “`&` *identifier* `...`ₒₚₜ ”, “`this`”, or “`* this`”.
1793
 
1794
  [*Note 1*: The form `[&,this]` is redundant but accepted for
1795
- compatibility with ISO C++14. — *end note*]
1796
 
1797
  Ignoring appearances in *initializer*s of *init-capture*s, an identifier
1798
  or `this` shall not appear more than once in a *lambda-capture*.
1799
 
1800
  [*Example 1*:
@@ -1813,14 +2140,19 @@ void S2::f(int i) {
1813
  ```
1814
 
1815
  — *end example*]
1816
 
1817
  A *lambda-expression* shall not have a *capture-default* or
1818
- *simple-capture* in its *lambda-introducer* unless its innermost
1819
- enclosing scope is a block scope [[basic.scope.block]] or it appears
1820
- within a default member initializer and its innermost enclosing scope is
1821
- the corresponding class scope [[basic.scope.class]].
 
 
 
 
 
1822
 
1823
  The *identifier* in a *simple-capture* shall denote a local entity
1824
  [[basic.lookup.unqual]], [[basic.pre]]. The *simple-capture*s `this` and
1825
  `* this` denote the local entity `*this`. An entity that is designated
1826
  by a *simple-capture* is said to be *explicitly captured*.
@@ -2038,11 +2370,12 @@ void f2() {
2038
  An entity is *captured by copy* if
2039
 
2040
  - it is implicitly captured, the *capture-default* is `=`, and the
2041
  captured entity is not `*this`, or
2042
  - it is explicitly captured with a capture that is not of the form
2043
- `this`, `&` *identifier*, or `&` *identifier* *initializer*.
 
2044
 
2045
  For each entity captured by copy, an unnamed non-static data member is
2046
  declared in the closure type. The declaration order of these members is
2047
  unspecified. The type of such a data member is the referenced type if
2048
  the entity is a reference to an object, an lvalue reference to the
@@ -2069,11 +2402,11 @@ the closure type.
2069
  ``` cpp
2070
  void f(const int*);
2071
  void g() {
2072
  const int N = 10;
2073
  [=] {
2074
- int arr[N]; // OK, not an odr-use, refers to automatic variable
2075
  f(&N); // OK, causes N to be captured; &N points to
2076
  // the corresponding member of the closure type
2077
  };
2078
  }
2079
  ```
@@ -2240,10 +2573,12 @@ bool f(Args ...args) {
2240
  }
2241
  ```
2242
 
2243
  — *end example*]
2244
 
 
 
2245
  ### Requires expressions <a id="expr.prim.req">[[expr.prim.req]]</a>
2246
 
2247
  #### General <a id="expr.prim.req.general">[[expr.prim.req.general]]</a>
2248
 
2249
  A *requires-expression* provides a concise way to express requirements
@@ -2265,12 +2600,11 @@ requirement-body:
2265
  '{' requirement-seq '}'
2266
  ```
2267
 
2268
  ``` bnf
2269
  requirement-seq:
2270
- requirement
2271
- requirement requirement-seq
2272
  ```
2273
 
2274
  ``` bnf
2275
  requirement:
2276
  simple-requirement
@@ -2278,12 +2612,11 @@ requirement:
2278
  compound-requirement
2279
  nested-requirement
2280
  ```
2281
 
2282
  A *requires-expression* is a prvalue of type `bool` whose value is
2283
- described below. Expressions appearing within a *requirement-body* are
2284
- unevaluated operands [[term.unevaluated.operand]].
2285
 
2286
  [*Example 1*:
2287
 
2288
  A common use of *requires-expression*s is to define requirements in
2289
  concepts such as the one below:
@@ -2310,38 +2643,43 @@ The first `requires` introduces the *requires-clause*, and the second
2310
  introduces the *requires-expression*.
2311
 
2312
  — *end example*]
2313
 
2314
  A *requires-expression* may introduce local parameters using a
2315
- *parameter-declaration-clause* [[dcl.fct]]. A local parameter of a
2316
- *requires-expression* shall not have a default argument. These
2317
- parameters have no linkage, storage, or lifetime; they are only used as
2318
- notation for the purpose of defining *requirement*s. The
2319
- *parameter-declaration-clause* of a *requirement-parameter-list* shall
2320
- not terminate with an ellipsis.
 
2321
 
2322
  [*Example 2*:
2323
 
2324
  ``` cpp
2325
  template<typename T>
2326
  concept C = requires(T t, ...) { // error: terminates with an ellipsis
2327
  t;
2328
  };
 
 
 
 
2329
  ```
2330
 
2331
  — *end example*]
2332
 
2333
- The substitution of template arguments into a *requires-expression* may
2334
- result in the formation of invalid types or expressions in its
2335
- *requirement*s or the violation of the semantic constraints of those
2336
- *requirement*s. In such cases, the *requires-expression* evaluates to
2337
- `false`; it does not cause the program to be ill-formed. The
2338
- substitution and semantic constraint checking proceeds in lexical order
2339
- and stops when a condition that determines the result of the
2340
- *requires-expression* is encountered. If substitution (if any) and
2341
- semantic constraint checking succeed, the *requires-expression*
2342
- evaluates to `true`.
2343
 
2344
  [*Note 1*: If a *requires-expression* contains invalid types or
2345
  expressions in its *requirement*s, and it does not appear within the
2346
  declaration of a templated entity, then the program is
2347
  ill-formed. — *end note*]
@@ -2353,11 +2691,11 @@ diagnostic required.
2353
  [*Example 3*:
2354
 
2355
  ``` cpp
2356
  template<typename T> concept C =
2357
  requires {
2358
- new int[-(int)sizeof(T)]; // ill-formed, no diagnostic required
2359
  };
2360
  ```
2361
 
2362
  — *end example*]
2363
 
@@ -2366,16 +2704,16 @@ requires {
2366
  ``` bnf
2367
  simple-requirement:
2368
  expression ';'
2369
  ```
2370
 
2371
- A *simple-requirement* asserts the validity of an *expression*.
 
2372
 
2373
  [*Note 1*: The enclosing *requires-expression* will evaluate to `false`
2374
- if substitution of template arguments into the *expression* fails. The
2375
- *expression* is an unevaluated operand
2376
- [[term.unevaluated.operand]]. — *end note*]
2377
 
2378
  [*Example 1*:
2379
 
2380
  ``` cpp
2381
  template<typename T> concept C =
@@ -2395,13 +2733,17 @@ as a *simple-requirement*.
2395
  #### Type requirements <a id="expr.prim.req.type">[[expr.prim.req.type]]</a>
2396
 
2397
  ``` bnf
2398
  type-requirement:
2399
  typename nested-name-specifierₒₚₜ type-name ';'
 
 
2400
  ```
2401
 
2402
- A *type-requirement* asserts the validity of a type.
 
 
2403
 
2404
  [*Note 1*: The enclosing *requires-expression* will evaluate to `false`
2405
  if substitution of template arguments fails. — *end note*]
2406
 
2407
  [*Example 1*:
@@ -2410,13 +2752,15 @@ if substitution of template arguments fails. — *end note*]
2410
  template<typename T, typename T::type = 0> struct S;
2411
  template<typename T> using Ref = T&;
2412
 
2413
  template<typename T> concept C = requires {
2414
  typename T::inner; // required nested member name
2415
- typename S<T>; // required valid[temp.names] template-id;
2416
- // fails if T::type does not exist as a type to which 0 can be implicitly converted
2417
  typename Ref<T>; // required alias template substitution, fails if T is void
 
 
2418
  };
2419
  ```
2420
 
2421
  — *end example*]
2422
 
@@ -2433,13 +2777,14 @@ compound-requirement:
2433
  ``` bnf
2434
  return-type-requirement:
2435
  '->' type-constraint
2436
  ```
2437
 
2438
- A *compound-requirement* asserts properties of the *expression* E.
2439
- Substitution of template arguments (if any) and verification of semantic
2440
- properties proceed in the following order:
 
2441
 
2442
  - Substitution of template arguments (if any) into the *expression* is
2443
  performed.
2444
  - If the `noexcept` specifier is present, E shall not be a
2445
  potentially-throwing expression [[except.spec]].
@@ -2529,10 +2874,115 @@ template<typename T> concept D = requires (T t) {
2529
  `D<T>` is satisfied if `sizeof(decltype (+t)) == 1`
2530
  [[temp.constr.atomic]].
2531
 
2532
  — *end example*]
2533
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2534
  ## Compound expressions <a id="expr.compound">[[expr.compound]]</a>
2535
 
2536
  ### Postfix expressions <a id="expr.post">[[expr.post]]</a>
2537
 
2538
  #### General <a id="expr.post.general">[[expr.post.general]]</a>
@@ -2546,12 +2996,14 @@ postfix-expression:
2546
  postfix-expression '(' expression-listₒₚₜ ')'
2547
  simple-type-specifier '(' expression-listₒₚₜ ')'
2548
  typename-specifier '(' expression-listₒₚₜ ')'
2549
  simple-type-specifier braced-init-list
2550
  typename-specifier braced-init-list
2551
- postfix-expression '.' 'template'ₒₚₜ id-expression
2552
- postfix-expression '->' 'template'ₒₚₜ id-expression
 
 
2553
  postfix-expression '++'
2554
  postfix-expression '--'
2555
  dynamic_cast '<' type-id '>' '(' expression ')'
2556
  static_cast '<' type-id '>' '(' expression ')'
2557
  reinterpret_cast '<' type-id '>' '(' expression ')'
@@ -2574,23 +3026,24 @@ replacing a `>>` token by two consecutive `>` tokens
2574
 
2575
  A *subscript expression* is a postfix expression followed by square
2576
  brackets containing a possibly empty, comma-separated list of
2577
  *initializer-clause*s that constitute the arguments to the subscript
2578
  operator. The *postfix-expression* and the initialization of the object
2579
- parameter of any applicable subscript operator function is sequenced
2580
- before each expression in the *expression-list* and also before any
2581
- default argument. The initialization of a non-object parameter of a
2582
- subscript operator function `S` [[over.sub]], including every associated
2583
- value computation and side effect, is indeterminately sequenced with
2584
- respect to that of any other non-object parameter of `S`.
 
2585
 
2586
  With the built-in subscript operator, an *expression-list* shall be
2587
  present, consisting of a single *assignment-expression*. One of the
2588
  expressions shall be a glvalue of type “array of `T`” or a prvalue of
2589
  type “pointer to `T`” and the other shall be a prvalue of unscoped
2590
  enumeration or integral type. The result is of type “`T`”. The type
2591
- “`T`” shall be a completely-defined object type.[^11]
2592
 
2593
  The expression `E1[E2]` is identical (by definition) to `*((E1)+(E2))`,
2594
  except that in the case of an array operand, the result is an lvalue if
2595
  that operand is an lvalue and an xvalue otherwise.
2596
 
@@ -2603,20 +3056,20 @@ of array types. — *end note*]
2603
 
2604
  A function call is a postfix expression followed by parentheses
2605
  containing a possibly empty, comma-separated list of
2606
  *initializer-clause*s which constitute the arguments to the function.
2607
 
2608
- [*Note 1*: If the postfix expression is a function or member function
2609
- name, the appropriate function and the validity of the call are
2610
- determined according to the rules in  [[over.match]]. — *end note*]
2611
 
2612
  The postfix expression shall have function type or function pointer
2613
  type. For a call to a non-member function or to a static member
2614
- function, the postfix expression shall either be an lvalue that refers
2615
  to a function (in which case the function-to-pointer standard conversion
2616
- [[conv.func]] is suppressed on the postfix expression), or have function
2617
- pointer type.
2618
 
2619
  If the selected function is non-virtual, or if the *id-expression* in
2620
  the class member access expression is a *qualified-id*, that function is
2621
  called. Otherwise, its final overrider [[class.virtual]] in the dynamic
2622
  type of the object expression is called; such a call is referred to as a
@@ -2625,14 +3078,13 @@ type of the object expression is called; such a call is referred to as a
2625
  [*Note 2*: The dynamic type is the type of the object referred to by
2626
  the current value of the object expression. [[class.cdtor]] describes
2627
  the behavior of virtual function calls when the object expression refers
2628
  to an object under construction or destruction. — *end note*]
2629
 
2630
- [*Note 3*: If a function or member function name is used, and name
2631
- lookup [[basic.lookup]] does not find a declaration of that name, the
2632
- program is ill-formed. No function is implicitly declared by such a
2633
- call. — *end note*]
2634
 
2635
  If the *postfix-expression* names a destructor or pseudo-destructor
2636
  [[expr.prim.id.dtor]], the type of the function call expression is
2637
  `void`; otherwise, the type of the function call expression is the
2638
  return type of the statically chosen function (i.e., ignoring the
@@ -2641,41 +3093,44 @@ different. If the *postfix-expression* names a pseudo-destructor (in
2641
  which case the *postfix-expression* is a possibly-parenthesized class
2642
  member access), the function call destroys the object of scalar type
2643
  denoted by the object expression of the class member access
2644
  [[expr.ref]], [[basic.life]].
2645
 
2646
- Calling a function through an expression whose function type `E` is
2647
- different from the function type `F` of the called function’s definition
2648
- results in undefined behavior unless the type “pointer to `F`” can be
2649
- converted to the type “pointer to `E`” via a function pointer conversion
2650
- [[conv.fctptr]].
 
2651
 
2652
- [*Note 4*: The exception applies when the expression has the type of a
2653
- potentially-throwing function, but the called function has a
2654
  non-throwing exception specification, and the function types are
2655
  otherwise the same. — *end note*]
2656
 
2657
  When a function is called, each parameter [[dcl.fct]] is initialized
2658
- [[dcl.init]], [[class.copy.ctor]] with its corresponding argument. If
2659
- the function is an explicit object member function and there is an
2660
- implied object argument [[over.call.func]], the list of provided
2661
- arguments is preceded by the implied object argument for the purposes of
2662
- this correspondence. If there is no corresponding argument, the default
2663
- argument for the parameter is used.
 
2664
 
2665
  [*Example 1*:
2666
 
2667
  ``` cpp
2668
  template<typename ...T> int f(int n = 0, T ...t);
2669
  int x = f<int>(); // error: no argument for second function parameter
2670
  ```
2671
 
2672
  — *end example*]
2673
 
2674
- If the function is an implicit object member function, the `this`
2675
- parameter of the function [[expr.prim.this]] is initialized with a
2676
- pointer to the object of the call, converted as if by an explicit type
 
2677
  conversion [[expr.cast]].
2678
 
2679
  [*Note 5*: There is no access or ambiguity checking on this conversion;
2680
  the access checking and disambiguation are done as part of the (possibly
2681
  implicit) class member access operator. See  [[class.member.lookup]],
@@ -2686,28 +3141,37 @@ class type that is either incomplete or abstract.
2686
 
2687
  [*Note 6*: This still allows a parameter to be a pointer or reference
2688
  to such a type. However, it prevents a passed-by-value parameter to have
2689
  an incomplete or abstract class type. — *end note*]
2690
 
2691
- It is *implementation-defined* whether the lifetime of a parameter ends
2692
- when the function in which it is defined returns or at the end of the
2693
- enclosing full-expression. The initialization and destruction of each
2694
- parameter occurs within the context of the calling function.
 
 
 
2695
 
2696
- [*Example 2*: The access of the constructor, conversion functions or
2697
- destructor is checked at the point of call in the calling function. If a
2698
- constructor or destructor for a function parameter throws an exception,
2699
- the search for a handler starts in the calling function; in particular,
2700
- if the function called has a *function-try-block* [[except.pre]] with a
2701
- handler that can handle the exception, this handler is not
2702
  considered. — *end example*]
2703
 
2704
  The *postfix-expression* is sequenced before each *expression* in the
2705
  *expression-list* and any default argument. The initialization of a
2706
- parameter, including every associated value computation and side effect,
2707
- is indeterminately sequenced with respect to that of any other
2708
- parameter.
 
 
 
 
 
 
 
2709
 
2710
  [*Note 7*: All side effects of argument evaluations are sequenced
2711
  before the function is entered (see 
2712
  [[intro.execution]]). — *end note*]
2713
 
@@ -2751,17 +3215,26 @@ control out of the called function (if any), except in a virtual
2751
  function call if the return type of the final overrider is different
2752
  from the return type of the statically chosen function, the value
2753
  returned from the final overrider is converted to the return type of the
2754
  statically chosen function.
2755
 
 
 
 
 
 
 
 
 
 
2756
  [*Note 9*: A function can change the values of its non-const
2757
  parameters, but these changes cannot affect the values of the arguments
2758
  except where a parameter is of a reference type [[dcl.ref]]; if the
2759
- reference is to a const-qualified type, `const_cast` is required to be
2760
- used to cast away the constness in order to modify the argument’s value.
2761
- Where a parameter is of `const` reference type a temporary object is
2762
- introduced if needed
2763
  [[dcl.type]], [[lex.literal]], [[lex.string]], [[dcl.array]], [[class.temporary]].
2764
  In addition, it is possible to modify the values of non-constant objects
2765
  through pointer parameters. — *end note*]
2766
 
2767
  A function can be declared to accept fewer arguments (by declaring
@@ -2787,15 +3260,16 @@ The lvalue-to-rvalue [[conv.lval]], array-to-pointer [[conv.array]], and
2787
  function-to-pointer [[conv.func]] standard conversions are performed on
2788
  the argument expression. An argument that has type cv `std::nullptr_t`
2789
  is converted to type `void*` [[conv.ptr]]. After these conversions, if
2790
  the argument does not have arithmetic, enumeration, pointer,
2791
  pointer-to-member, or class type, the program is ill-formed. Passing a
2792
- potentially-evaluated argument of a scoped enumeration type or of a
2793
- class type [[class]] having an eligible non-trivial copy constructor, an
2794
- eligible non-trivial move constructor, or a non-trivial destructor
2795
- [[special]], with no corresponding parameter, is conditionally-supported
2796
- with *implementation-defined* semantics. If the argument has integral or
 
2797
  enumeration type that is subject to the integral promotions
2798
  [[conv.prom]], or a floating-point type that is subject to the
2799
  floating-point promotion [[conv.fpprom]], the value of the argument is
2800
  converted to the promoted type before the call. These promotions are
2801
  referred to as the *default argument promotions*.
@@ -2803,11 +3277,13 @@ referred to as the *default argument promotions*.
2803
  Recursive calls are permitted, except to the `main` function
2804
  [[basic.start.main]].
2805
 
2806
  A function call is an lvalue if the result type is an lvalue reference
2807
  type or an rvalue reference to function type, an xvalue if the result
2808
- type is an rvalue reference to object type, and a prvalue otherwise.
 
 
2809
 
2810
  #### Explicit type conversion (functional notation) <a id="expr.type.conv">[[expr.type.conv]]</a>
2811
 
2812
  A *simple-type-specifier* [[dcl.type.simple]] or *typename-specifier*
2813
  [[temp.res]] followed by a parenthesized optional *expression-list* or
@@ -2816,11 +3292,28 @@ specified type given the initializer. If the type is a placeholder for a
2816
  deduced class type, it is replaced by the return type of the function
2817
  selected by overload resolution for class template deduction
2818
  [[over.match.class.deduct]] for the remainder of this subclause.
2819
  Otherwise, if the type contains a placeholder type, it is replaced by
2820
  the type determined by placeholder type deduction
2821
- [[dcl.type.auto.deduct]].
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2822
 
2823
  [*Example 1*:
2824
 
2825
  ``` cpp
2826
  struct A {};
@@ -2834,44 +3327,41 @@ void h() {
2834
  }
2835
  ```
2836
 
2837
  — *end example*]
2838
 
2839
- If the initializer is a parenthesized single expression, the type
2840
- conversion expression is equivalent to the corresponding cast expression
2841
- [[expr.cast]]. Otherwise, if the type is cv `void` and the initializer
2842
- is `()` or `{}` (after pack expansion, if any), the expression is a
2843
- prvalue of type `void` that performs no initialization. Otherwise, the
2844
- expression is a prvalue of the specified type whose result object is
2845
- direct-initialized [[dcl.init]] with the initializer. If the initializer
2846
- is a parenthesized optional *expression-list*, the specified type shall
2847
- not be an array type.
2848
-
2849
  #### Class member access <a id="expr.ref">[[expr.ref]]</a>
2850
 
2851
  A postfix expression followed by a dot `.` or an arrow `->`, optionally
2852
  followed by the keyword `template`, and then followed by an
2853
- *id-expression*, is a postfix expression. The postfix expression before
2854
- the dot or arrow is evaluated;[^12]
2855
 
2856
- the result of that evaluation, together with the *id-expression*,
2857
- determines the result of the entire postfix expression.
 
 
 
2858
 
2859
- [*Note 1*: If the keyword `template` is used, the following unqualified
2860
- name is considered to refer to a template [[temp.names]]. If a
2861
- *simple-template-id* results and is followed by a `::`, the
2862
- *id-expression* is a *qualified-id*. — *end note*]
 
 
 
 
2863
 
2864
- For the first option (dot) the first expression shall be a glvalue. For
2865
- the second option (arrow) the first expression shall be a prvalue having
2866
- pointer type. The expression `E1->E2` is converted to the equivalent
2867
- form `(*(E1)).E2`; the remainder of [[expr.ref]] will address only the
2868
- first option (dot).[^13]
2869
 
2870
- Abbreviating *postfix-expression*`.`*id-expression* as `E1.E2`, `E1` is
2871
- called the *object expression*. If the object expression is of scalar
2872
- type, `E2` shall name the pseudo-destructor of that same type (ignoring
 
 
 
 
 
2873
  cv-qualifications) and `E1.E2` is a prvalue of type “function of ()
2874
  returning `void`”.
2875
 
2876
  [*Note 2*: This value can only be used for a notional function call
2877
  [[expr.prim.id.dtor]]. — *end note*]
@@ -2884,68 +3374,105 @@ definition of that class.
2884
  when the class is complete [[class.member.lookup]]. — *end note*]
2885
 
2886
  [*Note 4*: [[basic.lookup.qual]] describes how names are looked up
2887
  after the `.` and `->` operators. — *end note*]
2888
 
2889
- If `E2` is a bit-field, `E1.E2` is a bit-field. The type and value
2890
- category of `E1.E2` are determined as follows. In the remainder of 
2891
- [[expr.ref]], *cq* represents either `const` or the absence of `const`
2892
- and *vq* represents either `volatile` or the absence of `volatile`. *cv*
2893
- represents an arbitrary set of cv-qualifiers, as defined in 
2894
- [[basic.type.qualifier]].
2895
 
2896
- If `E2` is declared to have type “reference to `T`”, then `E1.E2` is an
2897
- lvalue of type `T`. If `E2` is a static data member, `E1.E2` designates
2898
- the object or function to which the reference is bound, otherwise
2899
- `E1.E2` designates the object or function to which the corresponding
2900
- reference member of `E1` is bound. Otherwise, one of the following rules
2901
- applies.
2902
 
2903
- - If `E2` is a static data member and the type of `E2` is `T`, then
2904
- `E1.E2` is an lvalue; the expression designates the named member of
2905
- the class. The type of `E1.E2` is `T`.
2906
- - If `E2` is a non-static data member and the type of `E1` is “*cq1 vq1*
2907
- `X`”, and the type of `E2` is “*cq2 vq2* `T`”, the expression
2908
- designates the corresponding member subobject of the object designated
2909
- by the first expression. If `E1` is an lvalue, then `E1.E2` is an
2910
- lvalue; otherwise `E1.E2` is an xvalue. Let the notation *vq12* stand
2911
- for the “union” of *vq1* and *vq2*; that is, if *vq1* or *vq2* is
2912
- `volatile`, then *vq12* is `volatile`. Similarly, let the notation
2913
- *cq12* stand for the “union” of *cq1* and *cq2*; that is, if *cq1* or
2914
- *cq2* is `const`, then *cq12* is `const`. If `E2` is declared to be a
2915
- `mutable` member, then the type of `E1.E2` is “*vq12* `T`”. If `E2` is
2916
- not declared to be a `mutable` member, then the type of `E1.E2` is
2917
- “*cq12* *vq12* `T`”.
2918
- - If `E2` is an overload set, function overload resolution
2919
- [[over.match]] is used to select the function to which `E2` refers.
2920
- The type of `E1.E2` is the type of `E2` and `E1.E2` refers to the
2921
- function referred to by `E2`.
 
 
 
 
 
 
 
 
 
2922
  - If `E2` refers to a static member function, `E1.E2` is an lvalue.
2923
  - Otherwise (when `E2` refers to a non-static member function),
2924
- `E1.E2` is a prvalue. The expression can be used only as the
2925
- left-hand operand of a member function call [[class.mfct]].
2926
- \[*Note 5*: Any redundant set of parentheses surrounding the
2927
- expression is ignored [[expr.prim.paren]]. *end note*]
2928
- - If `E2` is a nested type, the expression `E1.E2` is ill-formed.
2929
- - If `E2` is a member enumerator and the type of `E2` is `T`, the
2930
- expression `E1.E2` is a prvalue of type `T` whose value is the value
2931
- of the enumerator.
2932
-
2933
- If `E2` is a non-static member, the program is ill-formed if the class
2934
- of which `E2` is directly a member is an ambiguous base
2935
- [[class.member.lookup]] of the naming class [[class.access.base]] of
2936
- `E2`.
2937
-
2938
- [*Note 6*: The program is also ill-formed if the naming class is an
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2939
  ambiguous base of the class type of the object expression; see 
2940
  [[class.access.base]]. — *end note*]
2941
 
2942
- If `E2` is a non-static member and the result of `E1` is an object whose
2943
- type is not similar [[conv.qual]] to the type of `E1`, the behavior is
2944
- undefined.
2945
 
2946
- [*Example 1*:
2947
 
2948
  ``` cpp
2949
  struct A { int i; };
2950
  struct B { int j; };
2951
  struct D : A, B {};
@@ -2958,33 +3485,32 @@ void f() {
2958
 
2959
  — *end example*]
2960
 
2961
  #### Increment and decrement <a id="expr.post.incr">[[expr.post.incr]]</a>
2962
 
2963
- The value of a postfix `++` expression is the value of its operand.
 
2964
 
2965
  [*Note 1*: The value obtained is a copy of the original
2966
  value. — *end note*]
2967
 
2968
  The operand shall be a modifiable lvalue. The type of the operand shall
2969
  be an arithmetic type other than cv `bool`, or a pointer to a complete
2970
  object type. An operand with volatile-qualified type is deprecated; see 
2971
  [[depr.volatile.type]]. The value of the operand object is modified
2972
- [[defns.access]] by adding `1` to it. The value computation of the `++`
2973
- expression is sequenced before the modification of the operand object.
2974
- With respect to an indeterminately-sequenced function call, the
2975
- operation of postfix `++` is a single evaluation.
 
2976
 
2977
  [*Note 2*: Therefore, a function call cannot intervene between the
2978
  lvalue-to-rvalue conversion and the side effect associated with any
2979
  single postfix `++` operator. — *end note*]
2980
 
2981
  The result is a prvalue. The type of the result is the cv-unqualified
2982
- version of the type of the operand. If the operand is a bit-field that
2983
- cannot represent the incremented value, the resulting value of the
2984
- bit-field is *implementation-defined*. See also  [[expr.add]] and 
2985
- [[expr.ass]].
2986
 
2987
  The operand of postfix `--` is decremented analogously to the postfix
2988
  `++` operator.
2989
 
2990
  [*Note 3*: For prefix increment and decrement, see 
@@ -3012,11 +3538,11 @@ If `T` is “pointer to *cv1* `B`” and `v` has type “pointer to *cv2* `D`”
3012
  such that `B` is a base class of `D`, the result is a pointer to the
3013
  unique `B` subobject of the `D` object pointed to by `v`, or a null
3014
  pointer value if `v` is a null pointer value. Similarly, if `T` is
3015
  “reference to *cv1* `B`” and `v` has type *cv2* `D` such that `B` is a
3016
  base class of `D`, the result is the unique `B` subobject of the `D`
3017
- object referred to by `v`.[^14]
3018
 
3019
  In both the pointer and reference cases, the program is ill-formed if
3020
  `B` is an inaccessible or ambiguous base class of `D`.
3021
 
3022
  [*Example 1*:
@@ -3034,10 +3560,18 @@ void foo(D* dp) {
3034
  Otherwise, `v` shall be a pointer to or a glvalue of a polymorphic type
3035
  [[class.virtual]].
3036
 
3037
  If `v` is a null pointer value, the result is a null pointer value.
3038
 
 
 
 
 
 
 
 
 
3039
  If `T` is “pointer to cv `void`”, then the result is a pointer to the
3040
  most derived object pointed to by `v`. Otherwise, a runtime check is
3041
  applied to see if the object pointed or referred to by `v` can be
3042
  converted to the type pointed or referred to by `T`.
3043
 
@@ -3045,11 +3579,11 @@ Let `C` be the class type to which `T` points or refers. The runtime
3045
  check logically executes as follows:
3046
 
3047
  - If, in the most derived object pointed (referred) to by `v`, `v`
3048
  points (refers) to a public base class subobject of a `C` object, and
3049
  if only one object of type `C` is derived from the subobject pointed
3050
- (referred) to by `v` the result points (refers) to that `C` object.
3051
  - Otherwise, if `v` points (refers) to a public base class subobject of
3052
  the most derived object, and the type of the most derived object has a
3053
  base class, of type `C`, that is unambiguous and public, the result
3054
  points (refers) to the `C` subobject of the most derived object.
3055
  - Otherwise, the runtime check *fails*.
@@ -3095,31 +3629,35 @@ destruction. — *end note*]
3095
 
3096
  #### Type identification <a id="expr.typeid">[[expr.typeid]]</a>
3097
 
3098
  The result of a `typeid` expression is an lvalue of static type `const`
3099
  `std::type_info` [[type.info]] and dynamic type `const` `std::type_info`
3100
- or `const` *name* where *name* is an *implementation-defined* class
3101
  publicly derived from `std::type_info` which preserves the behavior
3102
- described in  [[type.info]].[^15]
3103
 
3104
  The lifetime of the object referred to by the lvalue extends to the end
3105
  of the program. Whether or not the destructor is called for the
3106
  `std::type_info` object at the end of the program is unspecified.
3107
 
3108
  If the type of the *expression* or *type-id* operand is a (possibly
3109
  cv-qualified) class type or a reference to (possibly cv-qualified) class
3110
  type, that class shall be completely defined.
3111
 
 
 
 
 
 
 
 
 
 
3112
  When `typeid` is applied to a glvalue whose type is a polymorphic class
3113
  type [[class.virtual]], the result refers to a `std::type_info` object
3114
  representing the type of the most derived object [[intro.object]] (that
3115
- is, the dynamic type) to which the glvalue refers. If the glvalue is
3116
- obtained by applying the unary `*` operator to a pointer[^16]
3117
-
3118
- and the pointer is a null pointer value [[basic.compound]], the `typeid`
3119
- expression throws an exception [[except.throw]] of a type that would
3120
- match a handler of type `std::bad_typeid` exception [[bad.typeid]].
3121
 
3122
  When `typeid` is applied to an expression other than a glvalue of a
3123
  polymorphic class type, the result refers to a `std::type_info` object
3124
  representing the static type of the expression. Lvalue-to-rvalue
3125
  [[conv.lval]], array-to-pointer [[conv.array]], and function-to-pointer
@@ -3132,11 +3670,11 @@ When `typeid` is applied to a *type-id*, the result refers to a
3132
  `std::type_info` object representing the type of the *type-id*. If the
3133
  type of the *type-id* is a reference to a possibly cv-qualified type,
3134
  the result of the `typeid` expression refers to a `std::type_info`
3135
  object representing the cv-unqualified referenced type.
3136
 
3137
- [*Note 1*: The *type-id* cannot denote a function type with a
3138
  *cv-qualifier-seq* or a *ref-qualifier* [[dcl.fct]]. — *end note*]
3139
 
3140
  If the type of the expression or *type-id* is a cv-qualified type, the
3141
  result of the `typeid` expression refers to a `std::type_info` object
3142
  representing the cv-unqualified type.
@@ -3159,24 +3697,23 @@ typeid(D) == typeid(const D&); // yields true
3159
  The type `std::type_info` [[type.info]] is not predefined; if a standard
3160
  library declaration [[typeinfo.syn]], [[std.modules]] of
3161
  `std::type_info` does not precede [[basic.lookup.general]] a `typeid`
3162
  expression, the program is ill-formed.
3163
 
3164
- [*Note 2*: Subclause [[class.cdtor]] describes the behavior of `typeid`
3165
  applied to an object under construction or destruction. — *end note*]
3166
 
3167
  #### Static cast <a id="expr.static.cast">[[expr.static.cast]]</a>
3168
 
3169
  The result of the expression `static_cast<T>(v)` is the result of
3170
  converting the expression `v` to type `T`. If `T` is an lvalue reference
3171
  type or an rvalue reference to function type, the result is an lvalue;
3172
  if `T` is an rvalue reference to object type, the result is an xvalue;
3173
- otherwise, the result is a prvalue. The `static_cast` operator shall not
3174
- cast away constness [[expr.const.cast]].
3175
 
3176
  An lvalue of type “*cv1* `B`”, where `B` is a class type, can be cast to
3177
- type “reference to *cv2* `D`”, where `D` is a class derived
3178
  [[class.derived]] from `B`, if *cv2* is the same cv-qualification as, or
3179
  greater cv-qualification than, *cv1*. If `B` is a virtual base class of
3180
  `D` or a base class of a virtual base class of `D`, or if no valid
3181
  standard conversion from “pointer to `D`” to “pointer to `B`” exists
3182
  [[conv.ptr]], the program is ill-formed. An xvalue of type “*cv1* `B`”
@@ -3207,14 +3744,25 @@ class subobject thereof; otherwise, the lvalue-to-rvalue conversion
3207
  used as the operand of the `static_cast` for the remainder of this
3208
  subclause. If `T2` is an inaccessible [[class.access]] or ambiguous
3209
  [[class.member.lookup]] base class of `T1`, a program that necessitates
3210
  such a cast is ill-formed.
3211
 
3212
- An expression E can be explicitly converted to a type `T` if there is an
3213
- implicit conversion sequence [[over.best.ics]] from E to `T`, if
3214
- overload resolution for a direct-initialization [[dcl.init]] of an
3215
- object or reference of type `T` from E would find at least one viable
 
 
 
 
 
 
 
 
 
 
 
3216
  function [[over.match.viable]], or if `T` is an aggregate type
3217
  [[dcl.init.aggr]] having a first element `x` and there is an implicit
3218
  conversion sequence from E to the type of `x`. If `T` is a reference
3219
  type, the effect is the same as performing the declaration and
3220
  initialization
@@ -3225,59 +3773,23 @@ T t(E);
3225
 
3226
  for some invented temporary variable `t` [[dcl.init]] and then using the
3227
  temporary variable as the result of the conversion. Otherwise, the
3228
  result object is direct-initialized from E.
3229
 
3230
- [*Note 1*: The conversion is ill-formed when attempting to convert an
3231
  expression of class type to an inaccessible or ambiguous base
3232
  class. — *end note*]
3233
 
3234
- [*Note 2*: If `T` is “array of unknown bound of `U`”, this
3235
  direct-initialization defines the type of the expression as
3236
  `U[1]`. — *end note*]
3237
 
3238
- Otherwise, the `static_cast` shall perform one of the conversions listed
3239
- below. No other conversion shall be performed explicitly using a
3240
- `static_cast`.
3241
-
3242
- Any expression can be explicitly converted to type cv `void`, in which
3243
- case the operand is a discarded-value expression [[expr.prop]].
3244
-
3245
- [*Note 3*: Such a `static_cast` has no result as it is a prvalue of
3246
- type `void`; see  [[basic.lval]]. — *end note*]
3247
-
3248
- [*Note 4*: However, if the value is in a temporary object
3249
- [[class.temporary]], the destructor for that object is not executed
3250
- until the usual time, and the value of the object is preserved for the
3251
- purpose of executing the destructor. — *end note*]
3252
-
3253
- The inverse of any standard conversion sequence [[conv]] not containing
3254
- an lvalue-to-rvalue [[conv.lval]], array-to-pointer [[conv.array]],
3255
- function-to-pointer [[conv.func]], null pointer [[conv.ptr]], null
3256
- member pointer [[conv.mem]], boolean [[conv.bool]], or function pointer
3257
- [[conv.fctptr]] conversion, can be performed explicitly using
3258
- `static_cast`. A program is ill-formed if it uses `static_cast` to
3259
- perform the inverse of an ill-formed standard conversion sequence.
3260
-
3261
- [*Example 2*:
3262
-
3263
- ``` cpp
3264
- struct B { };
3265
- struct D : private B { };
3266
- void f() {
3267
- static_cast<D*>((B*)0); // error: B is a private base of D
3268
- static_cast<int B::*>((int D::*)0); // error: B is a private base of D
3269
- }
3270
- ```
3271
-
3272
- — *end example*]
3273
-
3274
- The lvalue-to-rvalue [[conv.lval]], array-to-pointer [[conv.array]], and
3275
- function-to-pointer [[conv.func]] conversions are applied to the
3276
- operand. Such a `static_cast` is subject to the restriction that the
3277
- explicit conversion does not cast away constness [[expr.const.cast]],
3278
- and the following additional rules for specific cases:
3279
 
3280
  A value of a scoped enumeration type [[dcl.enum]] can be explicitly
3281
  converted to an integral type; the result is the same as that of
3282
  converting to the enumeration’s underlying type and then to the
3283
  destination type. A value of a scoped enumeration type can also be
@@ -3330,14 +3842,13 @@ pointer-to-member-function types) are never cv-qualified
3330
 
3331
  If no valid standard conversion from “pointer to member of `B` of type
3332
  `T`” to “pointer to member of `D` of type `T`” exists [[conv.mem]], the
3333
  program is ill-formed. The null member pointer value [[conv.mem]] is
3334
  converted to the null member pointer value of the destination type. If
3335
- class `B` contains the original member, or is a base or derived class of
3336
- the class containing the original member, the resulting pointer to
3337
- member points to the original member. Otherwise, the behavior is
3338
- undefined.
3339
 
3340
  [*Note 6*: Although class `B` need not contain the original member, the
3341
  dynamic type of the object with which indirection through the pointer to
3342
  member is performed must contain the original member; see 
3343
  [[expr.mptr.oper]]. — *end note*]
@@ -3345,17 +3856,18 @@ member is performed must contain the original member; see 
3345
  A prvalue of type “pointer to *cv1* `void`” can be converted to a
3346
  prvalue of type “pointer to *cv2* `T`”, where `T` is an object type and
3347
  *cv2* is the same cv-qualification as, or greater cv-qualification than,
3348
  *cv1*. If the original pointer value represents the address `A` of a
3349
  byte in memory and `A` does not satisfy the alignment requirement of
3350
- `T`, then the resulting pointer value is unspecified. Otherwise, if the
3351
- original pointer value points to an object *a*, and there is an object
3352
- *b* of type similar to `T` that is pointer-interconvertible
3353
- [[basic.compound]] with *a*, the result is a pointer to *b*. Otherwise,
3354
- the pointer value is unchanged by the conversion.
 
3355
 
3356
- [*Example 3*:
3357
 
3358
  ``` cpp
3359
  T* p1 = new T;
3360
  const T* p2 = static_cast<const T*>(static_cast<void*>(p1));
3361
  bool b = p1 == p2; // b will have the value true.
@@ -3400,12 +3912,12 @@ the conversion has the same meaning and validity as a conversion of
3400
  any type to the type `std::nullptr_t`. — *end note*]
3401
 
3402
  A value of integral type or enumeration type can be explicitly converted
3403
  to a pointer. A pointer converted to an integer of sufficient size (if
3404
  any such exists on the implementation) and back to the same pointer type
3405
- will have its original value; mappings between pointers and integers are
3406
- otherwise *implementation-defined*.
3407
 
3408
  A function pointer can be explicitly converted to a function pointer of
3409
  a different type.
3410
 
3411
  [*Note 4*: The effect of calling a function through a pointer to a
@@ -3415,21 +3927,18 @@ definition of the function is undefined [[expr.call]]. — *end note*]
3415
  Except that converting a prvalue of type “pointer to `T1`” to the type
3416
  “pointer to `T2`” (where `T1` and `T2` are function types) and back to
3417
  its original type yields the original pointer value, the result of such
3418
  a pointer conversion is unspecified.
3419
 
3420
- [*Note 5*: See also  [[conv.ptr]] for more details of pointer
3421
- conversions. — *end note*]
3422
-
3423
  An object pointer can be explicitly converted to an object pointer of a
3424
- different type.[^17]
3425
 
3426
  When a prvalue `v` of object pointer type is converted to the object
3427
  pointer type “pointer to cv `T`”, the result is
3428
  `static_cast<cv T*>(static_cast<cv~void*>(v))`.
3429
 
3430
- [*Note 6*: Converting a pointer of type “pointer to `T1`” that points
3431
  to an object of type `T1` to the type “pointer to `T2`” (where `T2` is
3432
  an object type and the alignment requirements of `T2` are no stricter
3433
  than those of `T1`) and back to its original type yields the original
3434
  pointer value. — *end note*]
3435
 
@@ -3441,19 +3950,19 @@ other type and back, possibly with different cv-qualification, shall
3441
  yield the original pointer value.
3442
 
3443
  The null pointer value [[basic.compound]] is converted to the null
3444
  pointer value of the destination type.
3445
 
3446
- [*Note 7*: A null pointer constant of type `std::nullptr_t` cannot be
3447
  converted to a pointer type, and a null pointer constant of integral
3448
  type is not necessarily converted to a null pointer
3449
  value. — *end note*]
3450
 
3451
  A prvalue of type “pointer to member of `X` of type `T1`” can be
3452
  explicitly converted to a prvalue of a different type “pointer to member
3453
  of `Y` of type `T2`” if `T1` and `T2` are both function types or both
3454
- object types.[^18]
3455
 
3456
  The null member pointer value [[conv.mem]] is converted to the null
3457
  member pointer value of the destination type. The result of this
3458
  conversion is unspecified, except in the following cases:
3459
 
@@ -3464,79 +3973,83 @@ conversion is unspecified, except in the following cases:
3464
  `T1`” to the type “pointer to data member of `Y` of type `T2`” (where
3465
  the alignment requirements of `T2` are no stricter than those of `T1`)
3466
  and back to its original type yields the original pointer-to-member
3467
  value.
3468
 
3469
- A glvalue of type `T1`, designating an object *x*, can be cast to the
3470
- type “reference to `T2`” if an expression of type “pointer to `T1`” can
3471
- be explicitly converted to the type “pointer to `T2`” using a
3472
- `reinterpret_cast`. The result is that of `*reinterpret_cast<T2 *>(p)`
3473
- where `p` is a pointer to *x* of type “pointer to `T1`”. No temporary is
3474
- created, no copy is made, and no constructors [[class.ctor]] or
3475
- conversion functions [[class.conv]] are called.[^19]
 
 
 
 
 
 
 
3476
 
3477
  #### Const cast <a id="expr.const.cast">[[expr.const.cast]]</a>
3478
 
3479
  The result of the expression `const_cast<T>(v)` is of type `T`. If `T`
3480
  is an lvalue reference to object type, the result is an lvalue; if `T`
3481
  is an rvalue reference to object type, the result is an xvalue;
3482
  otherwise, the result is a prvalue and the lvalue-to-rvalue
3483
  [[conv.lval]], array-to-pointer [[conv.array]], and function-to-pointer
3484
  [[conv.func]] standard conversions are performed on the expression `v`.
3485
- Conversions that can be performed explicitly using `const_cast` are
3486
- listed below. No other conversion shall be performed explicitly using
3487
- `const_cast`.
 
3488
 
3489
  [*Note 1*: Subject to the restrictions in this subclause, an expression
3490
  can be cast to its own type using a `const_cast`
3491
  operator. — *end note*]
3492
 
3493
- For two similar types `T1` and `T2` [[conv.qual]], a prvalue of type
3494
- `T1` may be explicitly converted to the type `T2` using a `const_cast`
3495
- if, considering the qualification-decompositions of both types, each P¹ᵢ
3496
- is the same as P²for all i. The result of a `const_cast` refers to the
3497
- original entity.
3498
-
3499
- [*Example 1*:
3500
-
3501
- ``` cpp
3502
- typedef int *A[3]; // array of 3 pointer to int
3503
- typedef const int *const CA[3]; // array of 3 const pointer to const int
3504
-
3505
- CA &&r = A{}; // OK, reference binds to temporary array object
3506
- // after qualification conversion to type CA
3507
- A &&r1 = const_cast<A>(CA{}); // error: temporary array decayed to pointer
3508
- A &&r2 = const_cast<A&&>(CA{}); // OK
3509
- ```
3510
-
3511
- — *end example*]
3512
 
3513
  For two object types `T1` and `T2`, if a pointer to `T1` can be
3514
  explicitly converted to the type “pointer to `T2`” using a `const_cast`,
3515
  then the following conversions can also be made:
3516
 
3517
  - an lvalue of type `T1` can be explicitly converted to an lvalue of
3518
  type `T2` using the cast `const_cast<T2&>`;
3519
  - a glvalue of type `T1` can be explicitly converted to an xvalue of
3520
  type `T2` using the cast `const_cast<T2&&>`; and
3521
- - if `T1` is a class type, a prvalue of type `T1` can be explicitly
3522
- converted to an xvalue of type `T2` using the cast `const_cast<T2&&>`.
 
 
3523
 
3524
- The result of a reference `const_cast` refers to the original object if
3525
- the operand is a glvalue and to the result of applying the temporary
3526
- materialization conversion [[conv.rval]] otherwise.
3527
 
3528
- A null pointer value [[basic.compound]] is converted to the null pointer
3529
- value of the destination type. The null member pointer value
3530
- [[conv.mem]] is converted to the null member pointer value of the
3531
- destination type.
 
 
 
 
 
 
3532
 
3533
  [*Note 2*:
3534
 
3535
  Depending on the type of the object, a write operation through the
3536
  pointer, lvalue or pointer to data member resulting from a `const_cast`
3537
- that casts away a const-qualifier[^20]
3538
 
3539
  can produce undefined behavior [[dcl.type.cv]].
3540
 
3541
  — *end note*]
3542
 
@@ -3582,10 +4095,11 @@ unary-expression:
3582
  sizeof '...' '(' identifier ')'
3583
  alignof '(' type-id ')'
3584
  noexcept-expression
3585
  new-expression
3586
  delete-expression
 
3587
  ```
3588
 
3589
  ``` bnf
3590
  %% Ed. note: character protrusion would misalign operators.
3591
 
@@ -3595,33 +4109,42 @@ unary-operator: one of
3595
 
3596
  #### Unary operators <a id="expr.unary.op">[[expr.unary.op]]</a>
3597
 
3598
  The unary `*` operator performs *indirection*. Its operand shall be a
3599
  prvalue of type “pointer to `T`”, where `T` is an object or function
3600
- type. The operator yields an lvalue of type `T` denoting the object or
3601
- function to which the operand points.
 
 
3602
 
3603
- [*Note 1*: Indirection through a pointer to an incomplete type (other
 
 
 
3604
  than cv `void`) is valid. The lvalue thus obtained can be used in
3605
  limited ways (to initialize a reference, for example); this lvalue must
3606
  not be converted to a prvalue, see  [[conv.lval]]. — *end note*]
3607
 
3608
  Each of the following unary operators yields a prvalue.
3609
 
3610
  The operand of the unary `&` operator shall be an lvalue of some type
3611
- `T`. The result is a prvalue.
3612
 
3613
- - If the operand is a *qualified-id* naming a non-static or variant
3614
- member `m` of some class `C`, other than an explicit object member
3615
- function, the result has type “pointer to member of class `C` of type
3616
- `T`” and designates `C::m`.
 
 
 
 
3617
  - Otherwise, the result has type “pointer to `T`” and points to the
3618
  designated object [[intro.memory]] or function [[basic.compound]]. If
3619
- the operand names an explicit object member function [[dcl.fct]], the
3620
- operand shall be a *qualified-id*. \[*Note 2*: In particular, taking
3621
- the address of a variable of type “cv `T`” yields a pointer of type
3622
- “pointer to cv `T`”. — *end note*]
3623
 
3624
  [*Example 1*:
3625
 
3626
  ``` cpp
3627
  struct A { int i; };
@@ -3633,18 +4156,19 @@ int* p2 = p1 + 1; // defined behavior
3633
  bool b = p2 > p1; // defined behavior, with value true
3634
  ```
3635
 
3636
  — *end example*]
3637
 
3638
- [*Note 3*: A pointer to member formed from a `mutable` non-static data
3639
  member [[dcl.stc]] does not reflect the `mutable` specifier associated
3640
  with the non-static data member. — *end note*]
3641
 
3642
  A pointer to member is only formed when an explicit `&` is used and its
3643
- operand is a *qualified-id* not enclosed in parentheses.
 
3644
 
3645
- [*Note 4*: That is, the expression `&(qualified-id)`, where the
3646
  *qualified-id* is enclosed in parentheses, does not form an expression
3647
  of type “pointer to member”. Neither does `qualified-id`, because there
3648
  is no implicit conversion from a *qualified-id* for a non-static member
3649
  function to the type “pointer to member function” as there is from an
3650
  lvalue of function type to the type “pointer to function” [[conv.func]].
@@ -3654,99 +4178,96 @@ the *unqualified-id*’s class. — *end note*]
3654
  If `&` is applied to an lvalue of incomplete class type and the complete
3655
  type declares `operator&()`, it is unspecified whether the operator has
3656
  the built-in meaning or the operator function is called. The operand of
3657
  `&` shall not be a bit-field.
3658
 
3659
- [*Note 5*: The address of an overload set [[over]] can be taken only in
3660
  a context that uniquely determines which function is referred to (see 
3661
  [[over.over]]). Since the context can affect whether the operand is a
3662
  static or non-static member function, the context can also affect
3663
  whether the expression has type “pointer to function” or “pointer to
3664
  member function”. — *end note*]
3665
 
3666
- The operand of the unary `+` operator shall have arithmetic, unscoped
3667
- enumeration, or pointer type and the result is the value of the
3668
  argument. Integral promotion is performed on integral or enumeration
3669
  operands. The type of the result is the type of the promoted operand.
3670
 
3671
- The operand of the unary `-` operator shall have arithmetic or unscoped
3672
- enumeration type and the result is the negative of its operand. Integral
3673
- promotion is performed on integral or enumeration operands. The negative
3674
- of an unsigned quantity is computed by subtracting its value from 2ⁿ,
3675
- where n is the number of bits in the promoted operand. The type of the
3676
- result is the type of the promoted operand.
 
3677
 
3678
- [*Note 6*: The result is the two’s complement of the operand (where
3679
  operand and result are considered as unsigned). — *end note*]
3680
 
3681
  The operand of the logical negation operator `!` is contextually
3682
  converted to `bool` [[conv]]; its value is `true` if the converted
3683
  operand is `false` and `false` otherwise. The type of the result is
3684
  `bool`.
3685
 
3686
- The operand of the `~` operator shall have integral or unscoped
3687
- enumeration type. Integral promotions are performed. The type of the
3688
- result is the type of the promoted operand. Given the coefficients `xᵢ`
3689
- of the base-2 representation [[basic.fundamental]] of the promoted
3690
- operand `x`, the coefficient `rᵢ` of the base-2 representation of the
3691
- result `r` is 1 if `xᵢ` is 0, and 0 otherwise.
3692
 
3693
- [*Note 7*: The result is the ones’ complement of the operand (where
3694
  operand and result are considered as unsigned). — *end note*]
3695
 
3696
  There is an ambiguity in the grammar when `~` is followed by a
3697
- *type-name* or *decltype-specifier*. The ambiguity is resolved by
3698
  treating `~` as the operator rather than as the start of an
3699
  *unqualified-id* naming a destructor.
3700
 
3701
- [*Note 8*: Because the grammar does not permit an operator to follow
3702
  the `.`, `->`, or `::` tokens, a `~` followed by a *type-name* or
3703
- *decltype-specifier* in a member access expression or *qualified-id* is
3704
- unambiguously parsed as a destructor name. — *end note*]
 
3705
 
3706
  #### Increment and decrement <a id="expr.pre.incr">[[expr.pre.incr]]</a>
3707
 
3708
- The operand of prefix `++` is modified [[defns.access]] by adding `1`.
3709
- The operand shall be a modifiable lvalue. The type of the operand shall
3710
- be an arithmetic type other than cv `bool`, or a pointer to a
3711
- completely-defined object type. An operand with volatile-qualified type
3712
- is deprecated; see  [[depr.volatile.type]]. The result is the updated
3713
- operand; it is an lvalue, and it is a bit-field if the operand is a
3714
- bit-field. The expression `++x` is equivalent to `x+=1`.
3715
 
3716
- [*Note 1*: See the discussions of addition [[expr.add]] and assignment
3717
- operators [[expr.ass]] for information on conversions. — *end note*]
3718
-
3719
- The operand of prefix `--` is modified [[defns.access]] by subtracting
3720
- `1`. The requirements on the operand of prefix `--` and the properties
3721
- of its result are otherwise the same as those of prefix `++`.
3722
-
3723
- [*Note 2*: For postfix increment and decrement, see 
3724
  [[expr.post.incr]]. — *end note*]
3725
 
3726
  #### Await <a id="expr.await">[[expr.await]]</a>
3727
 
3728
  The `co_await` expression is used to suspend evaluation of a coroutine
3729
  [[dcl.fct.def.coroutine]] while awaiting completion of the computation
3730
- represented by the operand expression.
 
3731
 
3732
  ``` bnf
3733
  await-expression:
3734
- 'co_await' cast-expression
3735
  ```
3736
 
3737
- An *await-expression* shall appear only in a potentially-evaluated
3738
- expression within the *compound-statement* of a *function-body* outside
3739
- of a *handler* [[except.pre]]. In a *declaration-statement* or in the
 
3740
  *simple-declaration* (if any) of an *init-statement*, an
3741
  *await-expression* shall appear only in an *initializer* of that
3742
  *declaration-statement* or *simple-declaration*. An *await-expression*
3743
  shall not appear in a default argument [[dcl.fct.default]]. An
3744
  *await-expression* shall not appear in the initializer of a block
3745
- variable with static or thread storage duration. A context within a
3746
- function where an *await-expression* can appear is called a *suspension
3747
- context* of the function.
 
 
3748
 
3749
  Evaluation of an *await-expression* involves the following auxiliary
3750
  types, expressions, and objects:
3751
 
3752
  - *p* is an lvalue naming the promise object [[dcl.fct.def.coroutine]]
@@ -3866,11 +4387,11 @@ to any other fundamental type [[basic.fundamental]] is
3866
 
3867
  [*Note 1*:
3868
 
3869
  In particular, the values of `sizeof(bool)`, `sizeof(char16_t)`,
3870
  `sizeof(char32_t)`, and `sizeof(wchar_t)` are
3871
- implementation-defined.[^21]
3872
 
3873
  — *end note*]
3874
 
3875
  [*Note 2*: See  [[intro.memory]] for the definition of byte and 
3876
  [[term.object.representation]] for the definition of object
@@ -3879,83 +4400,84 @@ representation. — *end note*]
3879
  When applied to a reference type, the result is the size of the
3880
  referenced type. When applied to a class, the result is the number of
3881
  bytes in an object of that class including any padding required for
3882
  placing objects of that type in an array. The result of applying
3883
  `sizeof` to a potentially-overlapping subobject is the size of the type,
3884
- not the size of the subobject.[^22]
3885
 
3886
  When applied to an array, the result is the total number of bytes in the
3887
  array. This implies that the size of an array of n elements is n times
3888
  the size of an element.
3889
 
3890
  The lvalue-to-rvalue [[conv.lval]], array-to-pointer [[conv.array]], and
3891
  function-to-pointer [[conv.func]] standard conversions are not applied
3892
  to the operand of `sizeof`. If the operand is a prvalue, the temporary
3893
  materialization conversion [[conv.rval]] is applied.
3894
 
3895
- The identifier in a `sizeof...` expression shall name a pack. The
3896
  `sizeof...` operator yields the number of elements in the pack
3897
  [[temp.variadic]]. A `sizeof...` expression is a pack expansion
3898
  [[temp.variadic]].
3899
 
3900
  [*Example 1*:
3901
 
3902
  ``` cpp
3903
  template<class... Types>
3904
  struct count {
3905
- static const std::size_t value = sizeof...(Types);
3906
  };
3907
  ```
3908
 
3909
  — *end example*]
3910
 
3911
  The result of `sizeof` and `sizeof...` is a prvalue of type
3912
  `std::size_t`.
3913
 
3914
  [*Note 3*: A `sizeof` expression is an integral constant expression
3915
- [[expr.const]]. The type `std::size_t` is defined in the standard header
3916
- `<cstddef>` [[cstddef.syn]], [[support.types.layout]]. — *end note*]
 
3917
 
3918
  #### Alignof <a id="expr.alignof">[[expr.alignof]]</a>
3919
 
3920
  An `alignof` expression yields the alignment requirement of its operand
3921
  type. The operand shall be a *type-id* representing a complete object
3922
  type, or an array thereof, or a reference to one of those types.
3923
 
3924
  The result is a prvalue of type `std::size_t`.
3925
 
3926
  [*Note 1*: An `alignof` expression is an integral constant expression
3927
- [[expr.const]]. The type `std::size_t` is defined in the standard header
3928
- `<cstddef>` [[cstddef.syn]], [[support.types.layout]]. — *end note*]
 
3929
 
3930
  When `alignof` is applied to a reference type, the result is the
3931
  alignment of the referenced type. When `alignof` is applied to an array
3932
  type, the result is the alignment of the element type.
3933
 
3934
  #### `noexcept` operator <a id="expr.unary.noexcept">[[expr.unary.noexcept]]</a>
3935
 
3936
- The `noexcept` operator determines whether the evaluation of its
3937
- operand, which is an unevaluated operand [[term.unevaluated.operand]],
3938
- can throw an exception [[except.throw]].
3939
-
3940
  ``` bnf
3941
  noexcept-expression:
3942
  noexcept '(' expression ')'
3943
  ```
3944
 
3945
- The result of the `noexcept` operator is a prvalue of type `bool`.
 
 
 
 
 
 
3946
 
3947
  [*Note 1*: A *noexcept-expression* is an integral constant expression
3948
  [[expr.const]]. — *end note*]
3949
 
3950
- The result of the `noexcept` operator is `true` unless the *expression*
3951
- is potentially-throwing [[except.spec]].
3952
-
3953
  #### New <a id="expr.new">[[expr.new]]</a>
3954
 
3955
- The *new-expression* attempts to create an object of the *type-id*
3956
- [[dcl.name]] or *new-type-id* to which it is applied. The type of that
3957
  object is the *allocated type*. This type shall be a complete object
3958
  type [[term.incomplete.type]], but not an abstract class type
3959
  [[class.abstract]] or array thereof [[intro.object]].
3960
 
3961
  [*Note 1*: Because references are not objects, references cannot be
@@ -3997,17 +4519,17 @@ noptr-new-declarator:
3997
  new-initializer:
3998
  '(' expression-listₒₚₜ ')'
3999
  braced-init-list
4000
  ```
4001
 
4002
- If a placeholder type [[dcl.spec.auto]] appears in the
4003
- *type-specifier-seq* of a *new-type-id* or *type-id* of a
4004
- *new-expression*, the allocated type is deduced as follows: Let *init*
4005
- be the *new-initializer*, if any, and `T` be the *new-type-id* or
4006
- *type-id* of the *new-expression*, then the allocated type is the type
4007
- deduced for the variable `x` in the invented declaration
4008
- [[dcl.spec.auto]]:
4009
 
4010
  ``` cpp
4011
  T x init ;
4012
  ```
4013
 
@@ -4079,34 +4601,41 @@ converted constant expression [[expr.const]] of type `std::size_t` and
4079
  its value shall be greater than zero.
4080
 
4081
  [*Example 4*: Given the definition `int n = 42`, `new float[n][5]` is
4082
  well-formed (because `n` is the *expression* of a
4083
  *noptr-new-declarator*), but `new float[5][n]` is ill-formed (because
4084
- `n` is not a constant expression). *end example*]
 
 
 
 
 
4085
 
4086
  If the *type-id* or *new-type-id* denotes an array type of unknown bound
4087
  [[dcl.array]], the *new-initializer* shall not be omitted; the allocated
4088
  object is an array with `n` elements, where `n` is determined from the
4089
  number of initial elements supplied in the *new-initializer*
4090
  [[dcl.init.aggr]], [[dcl.init.string]].
4091
 
4092
  If the *expression* in a *noptr-new-declarator* is present, it is
4093
- implicitly converted to `std::size_t`. The *expression* is erroneous if:
 
4094
 
4095
  - the expression is of non-class type and its value before converting to
4096
  `std::size_t` is less than zero;
4097
  - the expression is of class type and its value before application of
4098
- the second standard conversion [[over.ics.user]][^23] is less than
4099
  zero;
4100
  - its value is such that the size of the allocated object would exceed
4101
  the *implementation-defined* limit [[implimits]]; or
4102
  - the *new-initializer* is a *braced-init-list* and the number of array
4103
  elements for which initializers are provided (including the
4104
  terminating `'\0'` in a *string-literal* [[lex.string]]) exceeds the
4105
  number of elements to initialize.
4106
 
4107
- If the *expression* is erroneous after converting to `std::size_t`:
 
4108
 
4109
  - if the *expression* is a potentially-evaluated core constant
4110
  expression, the program is ill-formed;
4111
  - otherwise, an allocation function is not called; instead
4112
  - if the allocation function that would have been called has a
@@ -4118,24 +4647,34 @@ If the *expression* is erroneous after converting to `std::size_t`:
4118
  `std::bad_array_new_length` [[new.badlength]].
4119
 
4120
  When the value of the *expression* is zero, the allocation function is
4121
  called to allocate an array with no elements.
4122
 
 
 
 
 
 
 
 
 
 
 
4123
  Objects created by a *new-expression* have dynamic storage duration
4124
  [[basic.stc.dynamic]].
4125
 
4126
- [*Note 5*: The lifetime of such an object is not necessarily
4127
  restricted to the scope in which it is created. — *end note*]
4128
 
4129
  When the allocated type is “array of `N` `T`” (that is, the
4130
  *noptr-new-declarator* syntax is used or the *new-type-id* or *type-id*
4131
  denotes an array type), the *new-expression* yields a prvalue of type
4132
  “pointer to `T`” that points to the initial element (if any) of the
4133
  array. Otherwise, let `T` be the allocated type; the *new-expression* is
4134
  a prvalue of type “pointer to T” that points to the object created.
4135
 
4136
- [*Note 6*: Both `new int` and `new int[10]` have type `int*` and the
4137
  type of `new int[i][10]` is `int (*)[10]`. — *end note*]
4138
 
4139
  A *new-expression* may obtain storage for the object by calling an
4140
  allocation function [[basic.stc.dynamic.allocation]]. If the
4141
  *new-expression* terminates by throwing an exception, it may release
@@ -4144,11 +4683,11 @@ storage by calling a deallocation function
4144
  type, the allocation function’s name is `operator new` and the
4145
  deallocation function’s name is `operator delete`. If the allocated type
4146
  is an array type, the allocation function’s name is `operator new[]` and
4147
  the deallocation function’s name is `operator delete[]`.
4148
 
4149
- [*Note 7*: An implementation is required to provide default definitions
4150
  for the global allocation functions
4151
  [[basic.stc.dynamic]], [[new.delete.single]], [[new.delete.array]]. A
4152
  C++ program can provide alternative definitions of these functions
4153
  [[replacement.functions]] and/or class-specific versions [[class.free]].
4154
  The set of allocation and deallocation functions that can be called by a
@@ -4165,16 +4704,12 @@ global scope.
4165
  An implementation is allowed to omit a call to a replaceable global
4166
  allocation function [[new.delete.single]], [[new.delete.array]]. When it
4167
  does so, the storage is instead provided by the implementation or
4168
  provided by extending the allocation of another *new-expression*.
4169
 
4170
- During an evaluation of a constant expression, a call to an allocation
4171
- function is always omitted.
4172
-
4173
- [*Note 8*: Only *new-expression*s that would otherwise result in a call
4174
- to a replaceable global allocation function can be evaluated in constant
4175
- expressions [[expr.const]]. — *end note*]
4176
 
4177
  The implementation may extend the allocation of a *new-expression* `e1`
4178
  to provide storage for a *new-expression* `e2` if the following would be
4179
  true were the allocation not extended:
4180
 
@@ -4313,13 +4848,13 @@ not be done, the deallocation function shall not be called, and the
4313
  value of the *new-expression* shall be null.
4314
 
4315
  [*Note 11*: When the allocation function returns a value other than
4316
  null, it must be a pointer to a block of storage in which space for the
4317
  object has been reserved. The block of storage is assumed to be
4318
- appropriately aligned and of the requested size. The address of the
4319
- created object will not necessarily be the same as that of the block if
4320
- the object is an array. — *end note*]
4321
 
4322
  A *new-expression* that creates an object of type `T` initializes that
4323
  object as follows:
4324
 
4325
  - If the *new-initializer* is omitted, the object is default-initialized
@@ -4331,18 +4866,14 @@ object as follows:
4331
  The invocation of the allocation function is sequenced before the
4332
  evaluations of expressions in the *new-initializer*. Initialization of
4333
  the allocated object is sequenced before the value computation of the
4334
  *new-expression*.
4335
 
4336
- If the *new-expression* creates an object or an array of objects of
4337
- class type, access and ambiguity control are done for the allocation
4338
- function, the deallocation function [[basic.stc.dynamic.deallocation]],
4339
- and the constructor [[class.ctor]] selected for the initialization (if
4340
- any). If the *new-expression* creates an array of objects of class type,
4341
- the destructor is potentially invoked [[class.dtor]].
4342
 
4343
- If any part of the object initialization described above[^24]
4344
 
4345
  terminates by throwing an exception and a suitable deallocation function
4346
  can be found, the deallocation function is called to free the memory in
4347
  which the object was being constructed, after which the exception
4348
  continues to propagate in the context of the *new-expression*. If no
@@ -4367,11 +4898,13 @@ single matching deallocation function, that function will be called;
4367
  otherwise, no deallocation function will be called. If the lookup finds
4368
  a usual deallocation function and that function, considered as a
4369
  placement deallocation function, would have been selected as a match for
4370
  the allocation function, the program is ill-formed. For a non-placement
4371
  allocation function, the normal deallocation function lookup is used to
4372
- find the matching deallocation function [[expr.delete]].
 
 
4373
 
4374
  [*Example 7*:
4375
 
4376
  ``` cpp
4377
  struct S {
@@ -4410,30 +4943,26 @@ delete-expression:
4410
  ```
4411
 
4412
  The first alternative is a *single-object delete expression*, and the
4413
  second is an *array delete expression*. Whenever the `delete` keyword is
4414
  immediately followed by empty square brackets, it shall be interpreted
4415
- as the second alternative.[^25]
4416
 
4417
- The operand shall be of pointer to object type or of class type. If of
4418
- class type, the operand is contextually implicitly converted [[conv]] to
4419
- a pointer to object type.[^26]
 
 
4420
 
4421
- The *delete-expression* has type `void`.
4422
-
4423
- If the operand has a class type, the operand is converted to a pointer
4424
- type by calling the above-mentioned conversion function, and the
4425
- converted operand is used in place of the original operand for the
4426
- remainder of this subclause. In a single-object delete expression, the
4427
- value of the operand of `delete` may be a null pointer value, a pointer
4428
- value that resulted from a previous non-array *new-expression*, or a
4429
- pointer to a base class subobject of an object created by such a
4430
- *new-expression*. If not, the behavior is undefined. In an array delete
4431
- expression, the value of the operand of `delete` may be a null pointer
4432
- value or a pointer value that resulted from a previous array
4433
- *new-expression* whose allocation function was not a non-allocating form
4434
- [[new.delete.placement]].[^27]
4435
 
4436
  If not, the behavior is undefined.
4437
 
4438
  [*Note 1*: This means that the syntax of the *delete-expression* must
4439
  match the type of the object allocated by `new`, not the syntax of the
@@ -4451,24 +4980,21 @@ delete, the static type shall be a base class of the dynamic type of the
4451
  object to be deleted and the static type shall have a virtual destructor
4452
  or the behavior is undefined. In an array delete expression, if the
4453
  dynamic type of the object to be deleted is not similar to its static
4454
  type, the behavior is undefined.
4455
 
4456
- The *cast-expression* in a *delete-expression* shall be evaluated
4457
- exactly once.
4458
-
4459
  If the object being deleted has incomplete class type at the point of
4460
- deletion and the complete class has a non-trivial destructor or a
4461
- deallocation function, the behavior is undefined.
4462
 
4463
  If the value of the operand of the *delete-expression* is not a null
4464
  pointer value and the selected deallocation function (see below) is not
4465
- a destroying operator delete, the *delete-expression* will invoke the
4466
- destructor (if any) for the object or the elements of the array being
4467
- deleted. In the case of an array, the elements will be destroyed in
4468
- order of decreasing address (that is, in reverse order of the completion
4469
- of their constructor; see  [[class.base.init]]).
 
4470
 
4471
  If the value of the operand of the *delete-expression* is not a null
4472
  pointer value, then:
4473
 
4474
  - If the allocation call for the *new-expression* for the object to be
@@ -4525,12 +5051,11 @@ declarations other than of usual deallocation functions
4525
 
4526
  [*Note 5*: If only a placement deallocation function is found in a
4527
  class, the program is ill-formed because the lookup set is empty
4528
  [[basic.lookup]]. — *end note*]
4529
 
4530
- If more than one deallocation function is found, the function to be
4531
- called is selected as follows:
4532
 
4533
  - If any of the deallocation functions is a destroying operator delete,
4534
  all deallocation functions that are not destroying operator deletes
4535
  are eliminated from further consideration.
4536
  - If the type has new-extended alignment, a function with a parameter of
@@ -4546,10 +5071,15 @@ called is selected as follows:
4546
  or a (possibly multidimensional) array thereof, the function with a
4547
  parameter of type `std::size_t` is selected.
4548
  - Otherwise, it is unspecified whether a deallocation function with a
4549
  parameter of type `std::size_t` is selected.
4550
 
 
 
 
 
 
4551
  For a single-object delete expression, the deleted object is the object
4552
  A pointed to by the operand if the static type of A does not have a
4553
  virtual destructor, and the most-derived object of A otherwise.
4554
 
4555
  [*Note 6*: If the deallocation function is not a destroying operator
@@ -4580,12 +5110,181 @@ passed as the corresponding argument.
4580
  function, and either the first argument was not the result of a prior
4581
  call to a replaceable allocation function or the second or third
4582
  argument was not the corresponding argument in said call, the behavior
4583
  is undefined [[new.delete.single]], [[new.delete.array]]. — *end note*]
4584
 
4585
- Access and ambiguity control are done for both the deallocation function
4586
- and the destructor [[class.dtor]], [[class.free]].
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4587
 
4588
  ### Explicit type conversion (cast notation) <a id="expr.cast">[[expr.cast]]</a>
4589
 
4590
  The result of the expression `(T)` *cast-expression* is of type `T`. The
4591
  result is an lvalue if `T` is an lvalue reference type or an rvalue
@@ -4635,12 +5334,13 @@ conversion is valid even if the base class is inaccessible:
4635
  of a derived class type, respectively.
4636
 
4637
  If a conversion can be interpreted in more than one of the ways listed
4638
  above, the interpretation that appears first in the list is used, even
4639
  if a cast resulting from that interpretation is ill-formed. If a
4640
- conversion can be interpreted in more than one way as a `static_cast`
4641
- followed by a `const_cast`, the conversion is ill-formed.
 
4642
 
4643
  [*Example 1*:
4644
 
4645
  ``` cpp
4646
  struct A { };
@@ -4648,10 +5348,19 @@ struct I1 : A { };
4648
  struct I2 : A { };
4649
  struct D : I1, I2 { };
4650
  A* foo( D* p ) {
4651
  return (A*)( p ); // ill-formed static_cast interpretation
4652
  }
 
 
 
 
 
 
 
 
 
4653
  ```
4654
 
4655
  — *end example*]
4656
 
4657
  The operand of a cast using the cast notation can be a prvalue of type
@@ -4661,13 +5370,13 @@ operand and destination types are class types and one or both are
4661
  incomplete, it is unspecified whether the `static_cast` or the
4662
  `reinterpret_cast` interpretation is used, even if there is an
4663
  inheritance relationship between the two classes.
4664
 
4665
  [*Note 2*: For example, if the classes were defined later in the
4666
- translation unit, a multi-pass compiler would be permitted to interpret
4667
- a cast between pointers to the classes as if the class types were
4668
- complete at the point of the cast. — *end note*]
4669
 
4670
  ### Pointer-to-member operators <a id="expr.mptr.oper">[[expr.mptr.oper]]</a>
4671
 
4672
  The pointer-to-member operators `->*` and `.*` group left-to-right.
4673
 
@@ -4676,21 +5385,21 @@ pm-expression:
4676
  cast-expression
4677
  pm-expression '.*' cast-expression
4678
  pm-expression '->*' cast-expression
4679
  ```
4680
 
4681
- The binary operator `.*` binds its second operand, which shall be of
4682
- type “pointer to member of `T`” to its first operand, which shall be a
4683
- glvalue of class `T` or of a class of which `T` is an unambiguous and
4684
- accessible base class. The result is an object or a function of the type
4685
- specified by the second operand.
4686
 
4687
- The binary operator `->*` binds its second operand, which shall be of
4688
- type “pointer to member of `T`” to its first operand, which shall be of
4689
- type “pointer to `U`” where `U` is either `T` or a class of which `T` is
4690
- an unambiguous and accessible base class. The expression `E1->*E2` is
4691
- converted into the equivalent form `(*(E1)).*E2`.
4692
 
4693
  Abbreviating *pm-expression*`.*`*cast-expression* as `E1.*E2`, `E1` is
4694
  called the *object expression*. If the result of `E1` is an object whose
4695
  type is not similar to the type of `E1`, or whose most derived object
4696
  does not contain the member to which `E2` refers, the behavior is
@@ -4766,77 +5475,80 @@ are performed on the operands and determine the type of the result.
4766
 
4767
  The binary `*` operator indicates multiplication.
4768
 
4769
  The binary `/` operator yields the quotient, and the binary `%` operator
4770
  yields the remainder from the division of the first expression by the
4771
- second. If the second operand of `/` or `%` is zero the behavior is
4772
- undefined. For integral operands the `/` operator yields the algebraic
4773
- quotient with any fractional part discarded;[^28]
4774
 
4775
  if the quotient `a/b` is representable in the type of the result,
4776
  `(a/b)*b + a%b` is equal to `a`; otherwise, the behavior of both `a/b`
4777
  and `a%b` is undefined.
4778
 
4779
  ### Additive operators <a id="expr.add">[[expr.add]]</a>
4780
 
4781
- The additive operators `+` and `-` group left-to-right. The usual
4782
- arithmetic conversions [[expr.arith.conv]] are performed for operands of
4783
- arithmetic or enumeration type.
 
 
 
 
4784
 
4785
  ``` bnf
4786
  additive-expression:
4787
  multiplicative-expression
4788
  additive-expression '+' multiplicative-expression
4789
  additive-expression '-' multiplicative-expression
4790
  ```
4791
 
4792
- For addition, either both operands shall have arithmetic or unscoped
4793
- enumeration type, or one operand shall be a pointer to a
4794
- completely-defined object type and the other shall have integral or
4795
- unscoped enumeration type.
4796
 
4797
  For subtraction, one of the following shall hold:
4798
 
4799
- - both operands have arithmetic or unscoped enumeration type; or
4800
  - both operands are pointers to cv-qualified or cv-unqualified versions
4801
  of the same completely-defined object type; or
4802
  - the left operand is a pointer to a completely-defined object type and
4803
- the right operand has integral or unscoped enumeration type.
4804
 
4805
  The result of the binary `+` operator is the sum of the operands. The
4806
  result of the binary `-` operator is the difference resulting from the
4807
  subtraction of the second operand from the first.
4808
 
4809
  When an expression `J` that has integral type is added to or subtracted
4810
  from an expression `P` of pointer type, the result has the type of `P`.
4811
 
4812
  - If `P` evaluates to a null pointer value and `J` evaluates to 0, the
4813
  result is a null pointer value.
4814
- - Otherwise, if `P` points to an array element i of an array object `x`
4815
- with n elements [[dcl.array]],[^29] the expressions `P + J` and
4816
- `J + P` (where `J` has the value j) point to the
4817
- (possibly-hypothetical) array element i + j of `x` if 0 ≤ i + j ≤ n
4818
- and the expression `P - J` points to the (possibly-hypothetical) array
4819
- element i - j of `x` if 0 ≤ i - j ≤ n.
4820
  - Otherwise, the behavior is undefined.
4821
 
4822
  [*Note 1*: Adding a value other than 0 or 1 to a pointer to a base
4823
  class subobject, a member subobject, or a complete object results in
4824
  undefined behavior. — *end note*]
4825
 
4826
  When two pointer expressions `P` and `Q` are subtracted, the type of the
4827
  result is an *implementation-defined* signed integral type; this type
4828
- shall be the same type that is defined as `std::ptrdiff_t` in the
4829
  `<cstddef>` header [[support.types.layout]].
4830
 
4831
  - If `P` and `Q` both evaluate to null pointer values, the result is 0.
4832
  - Otherwise, if `P` and `Q` point to, respectively, array elements i and
4833
  j of the same array object `x`, the expression `P - Q` has the value
4834
- i - j.
4835
- - Otherwise, the behavior is undefined. \[*Note 2*: If the value i - j
4836
- is not in the range of representable values of type `std::ptrdiff_t`,
4837
- the behavior is undefined. — *end note*]
4838
 
4839
  For addition or subtraction, if the expressions `P` or `Q` have type
4840
  “pointer to cv `T`”, where `T` and the array element type are not
4841
  similar [[conv.qual]], the behavior is undefined.
4842
 
@@ -4860,23 +5572,24 @@ shift-expression:
4860
  additive-expression
4861
  shift-expression '<<' additive-expression
4862
  shift-expression '>>' additive-expression
4863
  ```
4864
 
4865
- The operands shall be of integral or unscoped enumeration type and
4866
- integral promotions are performed. The type of the result is that of the
4867
- promoted left operand. The behavior is undefined if the right operand is
4868
- negative, or greater than or equal to the width of the promoted left
4869
- operand.
4870
 
4871
  The value of `E1 << E2` is the unique value congruent to `E1` × 2^`E2`
4872
  modulo 2ᴺ, where N is the width of the type of the result.
4873
 
4874
  [*Note 1*: `E1` is left-shifted `E2` bit positions; vacated bits are
4875
  zero-filled. — *end note*]
4876
 
4877
- The value of `E1 >> E2` is `E1` / 2^`E2`, rounded down.
 
4878
 
4879
  [*Note 2*: `E1` is right-shifted `E2` bit positions. Right-shift on
4880
  signed integral types is an arithmetic right shift, which performs
4881
  sign-extension. — *end note*]
4882
 
@@ -4969,28 +5682,28 @@ relational-expression:
4969
  relational-expression '>' compare-expression
4970
  relational-expression '<=' compare-expression
4971
  relational-expression '>=' compare-expression
4972
  ```
4973
 
4974
- The lvalue-to-rvalue [[conv.lval]], array-to-pointer [[conv.array]], and
4975
- function-to-pointer [[conv.func]] standard conversions are performed on
4976
- the operands. The comparison is deprecated if both operands were of
4977
- array type prior to these conversions [[depr.array.comp]].
4978
 
4979
  The converted operands shall have arithmetic, enumeration, or pointer
4980
  type. The operators `<` (less than), `>` (greater than), `<=` (less than
4981
  or equal to), and `>=` (greater than or equal to) all yield `false` or
4982
  `true`. The type of the result is `bool`.
4983
 
4984
  The usual arithmetic conversions [[expr.arith.conv]] are performed on
4985
- operands of arithmetic or enumeration type. If both operands are
4986
- pointers, pointer conversions [[conv.ptr]] and qualification conversions
4987
- [[conv.qual]] are performed to bring them to their composite pointer
4988
- type [[expr.type]]. After conversions, the operands shall have the same
4989
- type.
4990
 
4991
- The result of comparing unequal pointers to objects[^30]
4992
 
4993
  is defined in terms of a partial order consistent with the following
4994
  rules:
4995
 
4996
  - If two pointers point to different elements of the same array, or to
@@ -5010,12 +5723,12 @@ a pointer to object `p` compares greater than a pointer `q`, `p>=q`,
5010
  `p>q`, `q<=p`, and `q<p` all yield `true` and `p<=q`, `p<q`, `q>=p`, and
5011
  `q>p` all yield `false`. Otherwise, the result of each of the operators
5012
  is unspecified.
5013
 
5014
  [*Note 1*: A relational operator applied to unequal function pointers
5015
- or to unequal pointers to `void` yields an unspecified
5016
- result. — *end note*]
5017
 
5018
  If both operands (after conversions) are of arithmetic or enumeration
5019
  type, each of the operators shall yield `true` if the specified
5020
  relationship is true and `false` if it is false.
5021
 
@@ -5027,31 +5740,30 @@ equality-expression:
5027
  equality-expression '==' relational-expression
5028
  equality-expression '!=' relational-expression
5029
  ```
5030
 
5031
  The `==` (equal to) and the `!=` (not equal to) operators group
5032
- left-to-right. The lvalue-to-rvalue [[conv.lval]], array-to-pointer
5033
- [[conv.array]], and function-to-pointer [[conv.func]] standard
5034
- conversions are performed on the operands. The comparison is deprecated
5035
- if both operands were of array type prior to these conversions
5036
- [[depr.array.comp]].
5037
 
5038
- The converted operands shall have arithmetic, enumeration, pointer, or
5039
- pointer-to-member type, or type `std::nullptr_t`. The operators `==` and
5040
  `!=` both yield `true` or `false`, i.e., a result of type `bool`. In
5041
  each case below, the operands shall have the same type after the
5042
  specified conversions have been applied.
5043
 
5044
- If at least one of the operands is a pointer, pointer conversions
5045
- [[conv.ptr]], function pointer conversions [[conv.fctptr]], and
5046
- qualification conversions [[conv.qual]] are performed on both operands
5047
- to bring them to their composite pointer type [[expr.type]]. Comparing
5048
- pointers is defined as follows:
5049
 
5050
  - If one pointer represents the address of a complete object, and
5051
  another pointer represents the address one past the last element of a
5052
- different complete object,[^31] the result of the comparison is
5053
  unspecified.
5054
  - Otherwise, if the pointers are both null, both point to the same
5055
  function, or both represent the same address [[basic.compound]], they
5056
  compare equal.
5057
  - Otherwise, the pointers compare unequal.
@@ -5111,10 +5823,23 @@ performed on both operands to bring them to their composite pointer type
5111
  — *end example*]
5112
 
5113
  Two operands of type `std::nullptr_t` or one operand of type
5114
  `std::nullptr_t` and the other a null pointer constant compare equal.
5115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5116
  If two operands compare equal, the result is `true` for the `==`
5117
  operator and `false` for the `!=` operator. If two operands compare
5118
  unequal, the result is `false` for the `==` operator and `true` for the
5119
  `!=` operator. Otherwise, the result of each of the operators is
5120
  unspecified.
@@ -5269,33 +5994,36 @@ type `T2` of the operand expression `E2` as follows:
5269
  but an implicit conversion sequence can only be formed if the
5270
  reference would bind directly.
5271
  - If `E2` is a prvalue or if neither of the conversion sequences above
5272
  can be formed and at least one of the operands has (possibly
5273
  cv-qualified) class type:
5274
- - if `T1` and `T2` are the same class type (ignoring cv-qualification)
5275
- and `T2` is at least as cv-qualified as `T1`, the target type is
 
5276
  `T2`,
 
5277
  - otherwise, if `T2` is a base class of `T1`, the target type is *cv1*
5278
- `T2`, where *cv1* denotes the cv-qualifiers of `T1`,
5279
  - otherwise, the target type is the type that `E2` would have after
5280
  applying the lvalue-to-rvalue [[conv.lval]], array-to-pointer
5281
  [[conv.array]], and function-to-pointer [[conv.func]] standard
5282
  conversions.
5283
 
5284
  Using this process, it is determined whether an implicit conversion
5285
  sequence can be formed from the second operand to the target type
5286
- determined for the third operand, and vice versa. If both sequences can
5287
- be formed, or one can be formed but it is the ambiguous conversion
5288
- sequence, the program is ill-formed. If no conversion sequence can be
5289
- formed, the operands are left unchanged and further checking is
5290
- performed as described below. Otherwise, if exactly one conversion
5291
- sequence can be formed, that conversion is applied to the chosen operand
5292
- and the converted operand is used in place of the original operand for
5293
- the remainder of this subclause.
5294
 
5295
- [*Note 3*: The conversion might be ill-formed even if an implicit
5296
- conversion sequence could be formed. — *end note*]
 
 
 
 
 
 
 
5297
 
5298
  If the second and third operands are glvalues of the same value category
5299
  and have the same type, the result is of that type and value category
5300
  and it is a bit-field if the second or the third operand is a bit-field,
5301
  or if both are bit-fields.
@@ -5307,41 +6035,40 @@ to be applied to the operands [[over.match.oper]], [[over.built]]. If
5307
  the overload resolution fails, the program is ill-formed. Otherwise, the
5308
  conversions thus determined are applied, and the converted operands are
5309
  used in place of the original operands for the remainder of this
5310
  subclause.
5311
 
5312
- Lvalue-to-rvalue [[conv.lval]], array-to-pointer [[conv.array]], and
5313
- function-to-pointer [[conv.func]] standard conversions are performed on
5314
- the second and third operands. After those conversions, one of the
5315
- following shall hold:
5316
 
5317
  - The second and third operands have the same type; the result is of
5318
- that type and the result object is initialized using the selected
5319
  operand.
5320
  - The second and third operands have arithmetic or enumeration type; the
5321
  usual arithmetic conversions [[expr.arith.conv]] are performed to
5322
  bring them to a common type, and the result is of that type.
5323
  - One or both of the second and third operands have pointer type;
5324
- pointer conversions [[conv.ptr]], function pointer conversions
5325
  [[conv.fctptr]], and qualification conversions [[conv.qual]] are
5326
  performed to bring them to their composite pointer type [[expr.type]].
5327
  The result is of the composite pointer type.
5328
  - One or both of the second and third operands have pointer-to-member
5329
- type; pointer to member conversions [[conv.mem]], function pointer
5330
- conversions [[conv.fctptr]], and qualification conversions
5331
  [[conv.qual]] are performed to bring them to their composite pointer
5332
  type [[expr.type]]. The result is of the composite pointer type.
5333
  - Both the second and third operands have type `std::nullptr_t` or one
5334
  has that type and the other is a null pointer constant. The result is
5335
  of type `std::nullptr_t`.
5336
 
5337
  ### Yielding a value <a id="expr.yield">[[expr.yield]]</a>
5338
 
5339
  ``` bnf
5340
  yield-expression:
5341
- 'co_yield' assignment-expression
5342
- 'co_yield' braced-init-list
5343
  ```
5344
 
5345
  A *yield-expression* shall appear only within a suspension context of a
5346
  function [[expr.await]]. Let *e* be the operand of the
5347
  *yield-expression* and *p* be an lvalue naming the promise object of the
@@ -5393,20 +6120,24 @@ throw-expression:
5393
  throw assignment-expressionₒₚₜ
5394
  ```
5395
 
5396
  A *throw-expression* is of type `void`.
5397
 
5398
- Evaluating a *throw-expression* with an operand throws an exception
5399
- [[except.throw]]; the type of the exception object is determined by
5400
- removing any top-level *cv-qualifier*s from the static type of the
5401
- operand and adjusting the type from “array of `T`” or function type `T`
5402
- to “pointer to `T`”.
 
 
5403
 
5404
  A *throw-expression* with no operand rethrows the currently handled
5405
- exception [[except.handle]]. The exception is reactivated with the
5406
- existing exception object; no new exception object is created. The
5407
- exception is no longer considered to be caught.
 
 
5408
 
5409
  [*Example 1*:
5410
 
5411
  An exception handler that cannot completely handle the exception itself
5412
  can be written like this:
@@ -5420,15 +6151,11 @@ try {
5420
  }
5421
  ```
5422
 
5423
  — *end example*]
5424
 
5425
- If no exception is presently being handled, evaluating a
5426
- *throw-expression* with no operand calls `std::{}terminate()`
5427
- [[except.terminate]].
5428
-
5429
- ### Assignment and compound assignment operators <a id="expr.ass">[[expr.ass]]</a>
5430
 
5431
  The assignment operator (`=`) and the compound assignment operators all
5432
  group right-to-left. All require a modifiable lvalue as their left
5433
  operand; their result is an lvalue of the type of the left operand,
5434
  referring to the left operand. The result in all cases is a bit-field if
@@ -5454,13 +6181,14 @@ assignment-expression:
5454
  ``` bnf
5455
  assignment-operator: one of
5456
  '= *= /= %= += -= >>= <<= &= ^= |='
5457
  ```
5458
 
5459
- In simple assignment (`=`), the object referred to by the left operand
5460
- is modified [[defns.access]] by replacing its value with the result of
5461
- the right operand.
 
5462
 
5463
  If the right operand is an expression, it is implicitly converted
5464
  [[conv]] to the cv-unqualified type of the left operand.
5465
 
5466
  When the left operand of an assignment operator is a bit-field that
@@ -5490,19 +6218,18 @@ the behavior is undefined.
5490
  [*Note 3*: This restriction applies to the relationship between the
5491
  left and right sides of the assignment operation; it is not a statement
5492
  about how the target of the assignment can be aliased in general. See 
5493
  [[basic.lval]]. — *end note*]
5494
 
5495
- A *braced-init-list* may appear on the right-hand side of
5496
 
5497
- - an assignment to a scalar, in which case the initializer list shall
5498
- have at most a single element. The meaning of `x = {v}`, where `T` is
5499
- the scalar type of the expression `x`, is that of `x = T{v}`. The
5500
- meaning of `x = {}` is `x = T{}`.
5501
- - an assignment to an object of class type, in which case the
5502
- initializer list is passed as the argument to the assignment operator
5503
- function selected by overload resolution [[over.ass]], [[over.match]].
5504
 
5505
  [*Example 1*:
5506
 
5507
  ``` cpp
5508
  complex<double> z;
@@ -5558,31 +6285,130 @@ has three arguments, the second of which has the value `5`.
5558
  Certain contexts require expressions that satisfy additional
5559
  requirements as detailed in this subclause; other contexts have
5560
  different semantics depending on whether or not an expression satisfies
5561
  these requirements. Expressions that satisfy these requirements,
5562
  assuming that copy elision [[class.copy.elision]] is not performed, are
5563
- called *constant expressions*.
5564
 
5565
  [*Note 1*: Constant expressions can be evaluated during
5566
  translation. — *end note*]
5567
 
5568
  ``` bnf
5569
  constant-expression:
5570
  conditional-expression
5571
  ```
5572
 
5573
- A variable or temporary object `o` is *constant-initialized* if
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5574
 
5575
- - either it has an initializer or its default-initialization results in
5576
- some initialization being performed, and
5577
  - the full-expression of its initialization is a constant expression
5578
- when interpreted as a *constant-expression*, except that if `o` is an
5579
- object, that full-expression may also invoke constexpr constructors
5580
- for `o` and its subobjects even if those objects are of non-literal
5581
- class types. \[*Note 2*: Such a class can have a non-trivial
5582
- destructor. Within this evaluation, `std::is_constant_evaluated()`
5583
- [[meta.const.eval]] returns `true`. *end note*]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5584
 
5585
  A variable is *potentially-constant* if it is constexpr or it has
5586
  reference or non-volatile const-qualified integral or enumeration type.
5587
 
5588
  A constant-initialized potentially-constant variable V is *usable in
@@ -5591,54 +6417,80 @@ reachable from P and
5591
 
5592
  - V is constexpr,
5593
  - V is not initialized to a TU-local value, or
5594
  - P is in the same translation unit as D.
5595
 
5596
- An object or reference is *usable in constant expressions* if it is
 
5597
 
5598
- - a variable that is usable in constant expressions, or
5599
- - a template parameter object [[temp.param]], or
5600
- - a string literal object [[lex.string]], or
5601
  - a temporary object of non-volatile const-qualified literal type whose
5602
  lifetime is extended [[class.temporary]] to that of a variable that is
5603
- usable in constant expressions, or
5604
- - a non-mutable subobject or reference member of any of the above.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5605
 
5606
  An expression E is a *core constant expression* unless the evaluation of
5607
  E, following the rules of the abstract machine [[intro.execution]],
5608
  would evaluate one of the following:
5609
 
5610
  - `this` [[expr.prim.this]], except
5611
  - in a constexpr function [[dcl.constexpr]] that is being evaluated as
5612
  part of E or
5613
  - when appearing as the *postfix-expression* of an implicit or
5614
  explicit class member access expression [[expr.ref]];
5615
- - a control flow that passes through a declaration of a variable with
5616
- static [[basic.stc.static]] or thread [[basic.stc.thread]] storage
5617
- duration, unless that variable is usable in constant expressions;
5618
- \[*Example 1*:
 
5619
  ``` cpp
5620
  constexpr char test() {
5621
  static const int x = 5;
5622
  static constexpr char c[] = "Hello World";
5623
  return *(c + x);
5624
  }
5625
  static_assert(' ' == test());
5626
  ```
5627
 
5628
  — *end example*]
5629
- - an invocation of a non-constexpr function;[^32]
5630
  - an invocation of an undefined constexpr function;
5631
  - an invocation of an instantiated constexpr function that is not
5632
  constexpr-suitable;
5633
  - an invocation of a virtual function [[class.virtual]] for an object
5634
  whose dynamic type is constexpr-unknown;
5635
  - an expression that would exceed the implementation-defined limits (see
5636
  [[implimits]]);
5637
- - an operation that would have undefined behavior as specified in
5638
- [[intro]] through [[cpp]], excluding [[dcl.attr.assume]];[^33]
5639
  - an lvalue-to-rvalue conversion [[conv.lval]] unless it is applied to
 
5640
  - a non-volatile glvalue that refers to an object that is usable in
5641
  constant expressions, or
5642
  - a non-volatile glvalue of literal type that refers to a non-volatile
5643
  object whose lifetime began within the evaluation of E;
5644
  - an lvalue-to-rvalue conversion that is applied to a glvalue that
@@ -5651,11 +6503,11 @@ would evaluate one of the following:
5651
  evaluation of E;
5652
  - in a *lambda-expression*, a reference to `this` or to a variable with
5653
  automatic storage duration defined outside that *lambda-expression*,
5654
  where the reference would be an odr-use
5655
  [[term.odr.use]], [[expr.prim.lambda]];
5656
- \[*Example 2*:
5657
  ``` cpp
5658
  void g() {
5659
  const int n = 0;
5660
  [=] {
5661
  constexpr int i = n; // OK, n is not odr-used here
@@ -5663,17 +6515,17 @@ would evaluate one of the following:
5663
  };
5664
  }
5665
  ```
5666
 
5667
  — *end example*]
5668
- \[*Note 3*:
5669
  If the odr-use occurs in an invocation of a function call operator of
5670
  a closure type, it no longer refers to `this` or to an enclosing
5671
- automatic variable due to the transformation
5672
  [[expr.prim.lambda.capture]] of the *id-expression* into an access of
5673
  the corresponding data member.
5674
- \[*Example 3*:
5675
  ``` cpp
5676
  auto monad = [](auto v) { return [=] { return v; }; };
5677
  auto bind = [](auto m) {
5678
  return [=](auto fvm) { return fvm(m()); };
5679
  };
@@ -5682,61 +6534,82 @@ would evaluate one of the following:
5682
  static_assert(bind(monad(2))(monad)() == monad(2)());
5683
  ```
5684
 
5685
  — *end example*]
5686
  — *end note*]
5687
- - a conversion from type cv `void*` to a pointer-to-object type;
 
 
 
5688
  - a `reinterpret_cast` [[expr.reinterpret.cast]];
5689
  - a modification of an object
5690
- [[expr.ass]], [[expr.post.incr]], [[expr.pre.incr]] unless it is
5691
  applied to a non-volatile lvalue of literal type that refers to a
5692
  non-volatile object whose lifetime began within the evaluation of E;
5693
  - an invocation of a destructor [[class.dtor]] or a function call whose
5694
  *postfix-expression* names a pseudo-destructor [[expr.call]], in
5695
  either case for an object whose lifetime did not begin within the
5696
  evaluation of E;
5697
- - a *new-expression* [[expr.new]], unless the selected allocation
5698
- function is a replaceable global allocation function
5699
- [[new.delete.single]], [[new.delete.array]] and the allocated storage
5700
- is deallocated within the evaluation of E;
 
 
 
 
 
 
 
 
5701
  - a *delete-expression* [[expr.delete]], unless it deallocates a region
5702
  of storage allocated within the evaluation of E;
5703
  - a call to an instance of `std::allocator<T>::allocate`
5704
  [[allocator.members]], unless the allocated storage is deallocated
5705
  within the evaluation of E;
5706
  - a call to an instance of `std::allocator<T>::deallocate`
5707
  [[allocator.members]], unless it deallocates a region of storage
5708
  allocated within the evaluation of E;
 
 
 
 
5709
  - an *await-expression* [[expr.await]];
5710
  - a *yield-expression* [[expr.yield]];
5711
  - a three-way comparison [[expr.spaceship]], relational [[expr.rel]], or
5712
  equality [[expr.eq]] operator where the result is unspecified;
5713
- - a *throw-expression* [[expr.throw]];
5714
  - a `dynamic_cast` [[expr.dynamic.cast]] or `typeid` [[expr.typeid]]
5715
  expression on a glvalue that refers to an object whose dynamic type is
5716
- constexpr-unknown or that would throw an exception;
 
 
 
 
 
 
 
5717
  - an *asm-declaration* [[dcl.asm]];
5718
  - an invocation of the `va_arg` macro [[cstdarg.syn]];
5719
  - a non-constant library call [[defns.nonconst.libcall]]; or
5720
- - a `goto` statement [[stmt.goto]].
 
 
 
 
 
 
 
5721
 
5722
  It is unspecified whether E is a core constant expression if E satisfies
5723
  the constraints of a core constant expression, but evaluation of E would
5724
  evaluate
5725
 
5726
  - an operation that has undefined behavior as specified in [[library]]
5727
- through [[thread]],
5728
- - an invocation of the `va_start` macro [[cstdarg.syn]], or
5729
- - a statement with an assumption [[dcl.attr.assume]] whose converted
5730
- *conditional-expression*, if evaluated where the assumption appears,
5731
- would not disqualify E from being a core constant expression and would
5732
- not evaluate to `true`. \[*Note 4*: E is not disqualified from being a
5733
- core constant expression if the hypothetical evaluation of the
5734
- converted *conditional-expression* would disqualify E from being a
5735
- core constant expression. — *end note*]
5736
 
5737
- [*Example 4*:
5738
 
5739
  ``` cpp
5740
  int x; // not constant
5741
  struct A {
5742
  constexpr A(bool b) : m(b?42:x) { }
@@ -5777,38 +6650,70 @@ constexpr int y = h(1); // OK, initializes y with the value 2
5777
  — *end example*]
5778
 
5779
  For the purposes of determining whether an expression E is a core
5780
  constant expression, the evaluation of the body of a member function of
5781
  `std::allocator<T>` as defined in [[allocator.members]], where `T` is a
5782
- literal type, is ignored. Similarly, the evaluation of the body of
5783
- `std::construct_at` or `std::ranges::construct_at` is considered to
5784
- include only the underlying constructor call if the first argument (of
5785
- type `T*`) points to storage allocated with `std::allocator<T>` or to an
5786
- object whose lifetime began within the evaluation of E.
5787
 
5788
  For the purposes of determining whether E is a core constant expression,
5789
  the evaluation of a call to a trivial copy/move constructor or copy/move
5790
  assignment operator of a union is considered to copy/move the active
5791
  member of the union, if any.
5792
 
5793
- [*Note 5*: The copy/move of the active member is
5794
  trivial. — *end note*]
5795
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5796
  During the evaluation of an expression E as a core constant expression,
5797
- all *id-expression*s and uses of `*this` that refer to an object or
5798
- reference whose lifetime did not begin with the evaluation of E are
5799
- treated as referring to a specific instance of that object or reference
5800
- whose lifetime and that of all subobjects (including all union members)
5801
- includes the entire constant evaluation. For such an object that is not
5802
- usable in constant expressions, the dynamic type of the object is
5803
- *constexpr-unknown*. For such a reference that is not usable in constant
5804
- expressions, the reference is treated as binding to an unspecified
5805
- object of the referenced type whose lifetime and that of all subobjects
5806
- includes the entire constant evaluation and whose dynamic type is
5807
- constexpr-unknown.
5808
 
5809
- [*Example 5*:
5810
 
5811
  ``` cpp
5812
  template <typename T, size_t N>
5813
  constexpr size_t array_size(T (&)[N]) {
5814
  return N;
@@ -5860,36 +6765,36 @@ constexpr auto& sandeno = typeid(dc); // OK, can only be typeid(Swim)
5860
  constexpr auto& gallagher = typeid(trident); // error: constexpr-unknown dynamic type
5861
  ```
5862
 
5863
  — *end example*]
5864
 
5865
- An object `a` is said to have *constant destruction* if:
5866
 
5867
  - it is not of class type nor (possibly multidimensional) array thereof,
5868
  or
5869
  - it is of class type or (possibly multidimensional) array thereof, that
5870
- class type has a constexpr destructor, and for a hypothetical
5871
- expression E whose only effect is to destroy `a`, E would be a core
5872
- constant expression if the lifetime of `a` and its non-mutable
5873
- subobjects (but not its mutable subobjects) were considered to start
5874
- within E.
5875
 
5876
  An *integral constant expression* is an expression of integral or
5877
  unscoped enumeration type, implicitly converted to a prvalue, where the
5878
  converted expression is a core constant expression.
5879
 
5880
- [*Note 6*: Such expressions can be used as bit-field lengths
5881
  [[class.bit]], as enumerator initializers if the underlying type is not
5882
  fixed [[dcl.enum]], and as alignments [[dcl.align]]. — *end note*]
5883
 
5884
  If an expression of literal class type is used in a context where an
5885
  integral constant expression is required, then that expression is
5886
  contextually implicitly converted [[conv]] to an integral or unscoped
5887
  enumeration type and the selected conversion function shall be
5888
  `constexpr`.
5889
 
5890
- [*Example 6*:
5891
 
5892
  ``` cpp
5893
  struct A {
5894
  constexpr A(int i) : val(i) { }
5895
  constexpr operator int() const { return val; }
@@ -5914,82 +6819,110 @@ constant expression and the implicit conversion sequence contains only
5914
  - function-to-pointer conversions [[conv.func]],
5915
  - qualification conversions [[conv.qual]],
5916
  - integral promotions [[conv.prom]],
5917
  - integral conversions [[conv.integral]] other than narrowing
5918
  conversions [[dcl.init.list]],
 
 
 
5919
  - null pointer conversions [[conv.ptr]] from `std::nullptr_t`,
5920
  - null member pointer conversions [[conv.mem]] from `std::nullptr_t`,
5921
  and
5922
  - function pointer conversions [[conv.fctptr]],
5923
 
5924
  and where the reference binding (if any) binds directly.
5925
 
5926
- [*Note 7*: Such expressions can be used in `new` expressions
5927
  [[expr.new]], as case expressions [[stmt.switch]], as enumerator
5928
  initializers if the underlying type is fixed [[dcl.enum]], as array
5929
- bounds [[dcl.array]], and as non-type template arguments
5930
- [[temp.arg]]. *end note*]
 
5931
 
5932
  A *contextually converted constant expression of type `bool`* is an
5933
  expression, contextually converted to `bool` [[conv]], where the
5934
  converted expression is a constant expression and the conversion
5935
  sequence contains only the conversions above.
5936
 
5937
- A *constant expression* is either a glvalue core constant expression
5938
- that refers to an entity that is a permitted result of a constant
5939
- expression (as defined below), or a prvalue core constant expression
5940
- whose value satisfies the following constraints:
5941
 
5942
- - if the value is an object of class type, each non-static data member
5943
- of reference type refers to an entity that is a permitted result of a
5944
- constant expression,
5945
- - if the value is an object of scalar type, it does not have an
5946
- indeterminate value [[basic.indet]],
5947
- - if the value is of pointer type, it contains the address of an object
5948
- with static storage duration, the address past the end of such an
5949
- object [[expr.add]], the address of a non-immediate function, or a
5950
- null pointer value,
5951
- - if the value is of pointer-to-member-function type, it does not
5952
- designate an immediate function, and
5953
- - if the value is an object of class or array type, each subobject
5954
- satisfies these constraints for the value.
5955
 
5956
- An entity is a *permitted result of a constant expression* if it is an
5957
- object with static storage duration that either is not a temporary
5958
- object or is a temporary object whose value satisfies the above
5959
- constraints, or if it is a non-immediate function.
5960
 
5961
- [*Note 8*: A glvalue core constant expression that either refers to or
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5962
  points to an unspecified object is not a constant
5963
  expression. — *end note*]
5964
 
5965
- [*Example 7*:
5966
 
5967
  ``` cpp
5968
  consteval int f() { return 42; }
5969
  consteval auto g() { return f; }
5970
  consteval int h(int (*p)() = g()) { return p(); }
5971
  constexpr int r = h(); // OK
5972
  constexpr auto e = g(); // error: a pointer to an immediate function is
5973
  // not a permitted result of a constant expression
 
 
 
 
 
 
 
 
5974
  ```
5975
 
5976
  — *end example*]
5977
 
5978
  *Recommended practice:* Implementations should provide consistent
5979
  results of floating-point evaluations, irrespective of whether the
5980
  evaluation is performed during translation or during program execution.
5981
 
5982
- [*Note 9*:
5983
 
5984
  Since this document imposes no restrictions on the accuracy of
5985
  floating-point operations, it is unspecified whether the evaluation of a
5986
  floating-point expression during translation yields the same result as
5987
  the evaluation of the same expression (or the same operations on the
5988
  same values) during program execution.
5989
 
5990
- [*Example 8*:
5991
 
5992
  ``` cpp
5993
  bool f() {
5994
  char array[1 + int(1 + 0.2 - 0.1 - 0.1)]; // Must be evaluated during translation
5995
  int size = 1 + int(1 + 0.2 - 0.1 - 0.1); // May be evaluated at runtime
@@ -6018,17 +6951,18 @@ potentially-evaluated explicit or implicit invocation of an immediate
6018
  function and is not in an immediate function context. An aggregate
6019
  initialization is an immediate invocation if it evaluates a default
6020
  member initializer that has a subexpression that is an
6021
  immediate-escalating expression.
6022
 
6023
- An expression or conversion is *immediate-escalating* if it is not
6024
- initially in an immediate function context and it is either
 
6025
 
6026
- - a potentially-evaluated *id-expression* that denotes an immediate
6027
- function that is not a subexpression of an immediate invocation, or
6028
- - an immediate invocation that is not a constant expression and is not a
6029
- subexpression of an immediate invocation.
6030
 
6031
  An *immediate-escalating* function is
6032
 
6033
  - the call operator of a lambda that is not declared with the
6034
  `consteval` specifier,
@@ -6038,18 +6972,22 @@ An *immediate-escalating* function is
6038
  defined with the `constexpr` specifier.
6039
 
6040
  An immediate-escalating expression shall appear only in an
6041
  immediate-escalating function.
6042
 
6043
- An *immediate function* is a function or constructor that is
6044
 
6045
  - declared with the `consteval` specifier, or
6046
- - an immediate-escalating function `F` whose function body contains an
6047
- immediate-escalating expression `E` such that `E`’s innermost
6048
- enclosing non-block scope is `F`’s function parameter scope.
 
6049
 
6050
- [*Example 9*:
 
 
 
6051
 
6052
  ``` cpp
6053
  consteval int id(int i) { return i; }
6054
  constexpr char id(char c) { return c; }
6055
 
@@ -6079,16 +7017,17 @@ static_assert(is_not(5, is_even)); // OK
6079
 
6080
  int x = 0;
6081
 
6082
  template<class T>
6083
  constexpr T h(T t = id(x)) { // h<int> is not an immediate function
 
6084
  return t;
6085
  }
6086
 
6087
  template<class T>
6088
- constexpr T hh() { // hh<int> is an immediate function
6089
- return h<T>();
6090
  }
6091
 
6092
  int i = hh<int>(); // error: hh<int>() is an immediate-escalating expression
6093
  // outside of an immediate-escalating function
6094
 
@@ -6099,10 +7038,19 @@ struct A {
6099
 
6100
  template<class T>
6101
  constexpr int k(int) { // k<int> is not an immediate function because A(42) is a
6102
  return A(42).y; // constant expression and thus not immediate-escalating
6103
  }
 
 
 
 
 
 
 
 
 
6104
  ```
6105
 
6106
  — *end example*]
6107
 
6108
  An expression or conversion is *manifestly constant-evaluated* if it is:
@@ -6111,12 +7059,12 @@ An expression or conversion is *manifestly constant-evaluated* if it is:
6111
  - the condition of a constexpr if statement [[stmt.if]], or
6112
  - an immediate invocation, or
6113
  - the result of substitution into an atomic constraint expression to
6114
  determine whether it is satisfied [[temp.constr.atomic]], or
6115
  - the initializer of a variable that is usable in constant expressions
6116
- or has constant initialization [[basic.start.static]].[^34]
6117
- \[*Example 10*:
6118
  ``` cpp
6119
  template<bool> struct X {};
6120
  X<std::is_constant_evaluated()> x; // type X<true>
6121
  int y;
6122
  const int a = std::is_constant_evaluated() ? y : 1; // dynamic initialization to 1
@@ -6135,22 +7083,140 @@ An expression or conversion is *manifestly constant-evaluated* if it is:
6135
  int q = p + f(); // m is 17 for this call; initialized to 56
6136
  ```
6137
 
6138
  — *end example*]
6139
 
6140
- [*Note 10*: A manifestly constant-evaluated expression is evaluated
6141
- even in an unevaluated operand
6142
- [[term.unevaluated.operand]]. — *end note*]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6143
 
6144
  An expression or conversion is *potentially constant evaluated* if it
6145
  is:
6146
 
6147
  - a manifestly constant-evaluated expression,
6148
  - a potentially-evaluated expression [[basic.def.odr]],
6149
- - an immediate subexpression of a *braced-init-list*,[^35]
6150
  - an expression of the form `&` *cast-expression* that occurs within a
6151
- templated entity,[^36] or
6152
  - a potentially-evaluated subexpression [[intro.execution]] of one of
6153
  the above.
6154
 
6155
  A function or variable is *needed for constant evaluation* if it is:
6156
 
@@ -6158,42 +7224,51 @@ A function or variable is *needed for constant evaluation* if it is:
6158
  that is potentially constant evaluated, or
6159
  - a potentially-constant variable named by a potentially constant
6160
  evaluated expression.
6161
 
6162
  <!-- Link reference definitions -->
 
6163
  [allocator.members]: mem.md#allocator.members
6164
  [bad.alloc]: support.md#bad.alloc
6165
  [bad.cast]: support.md#bad.cast
6166
  [bad.typeid]: support.md#bad.typeid
6167
  [basic.align]: basic.md#basic.align
6168
  [basic.compound]: basic.md#basic.compound
 
 
 
6169
  [basic.def.odr]: basic.md#basic.def.odr
6170
  [basic.fundamental]: basic.md#basic.fundamental
6171
  [basic.indet]: basic.md#basic.indet
6172
  [basic.life]: basic.md#basic.life
6173
  [basic.lookup]: basic.md#basic.lookup
6174
  [basic.lookup.argdep]: basic.md#basic.lookup.argdep
6175
  [basic.lookup.general]: basic.md#basic.lookup.general
6176
  [basic.lookup.qual]: basic.md#basic.lookup.qual
6177
  [basic.lookup.unqual]: basic.md#basic.lookup.unqual
6178
  [basic.lval]: #basic.lval
 
6179
  [basic.pre]: basic.md#basic.pre
6180
  [basic.scope.block]: basic.md#basic.scope.block
6181
  [basic.scope.class]: basic.md#basic.scope.class
 
6182
  [basic.scope.lambda]: basic.md#basic.scope.lambda
 
6183
  [basic.start.main]: basic.md#basic.start.main
6184
  [basic.start.static]: basic.md#basic.start.static
6185
  [basic.stc.dynamic]: basic.md#basic.stc.dynamic
6186
  [basic.stc.dynamic.allocation]: basic.md#basic.stc.dynamic.allocation
6187
  [basic.stc.dynamic.deallocation]: basic.md#basic.stc.dynamic.deallocation
6188
  [basic.stc.static]: basic.md#basic.stc.static
6189
  [basic.stc.thread]: basic.md#basic.stc.thread
6190
  [basic.type.qualifier]: basic.md#basic.type.qualifier
 
6191
  [class]: class.md#class
6192
  [class.abstract]: class.md#class.abstract
6193
  [class.access]: class.md#class.access
6194
  [class.access.base]: class.md#class.access.base
 
6195
  [class.base.init]: class.md#class.base.init
6196
  [class.bit]: class.md#class.bit
6197
  [class.cdtor]: class.md#class.cdtor
6198
  [class.conv]: class.md#class.conv
6199
  [class.conv.fct]: class.md#class.conv.fct
@@ -6204,14 +7279,15 @@ A function or variable is *needed for constant evaluation* if it is:
6204
  [class.derived]: class.md#class.derived
6205
  [class.dtor]: class.md#class.dtor
6206
  [class.free]: class.md#class.free
6207
  [class.friend]: class.md#class.friend
6208
  [class.mem]: class.md#class.mem
 
6209
  [class.member.lookup]: basic.md#class.member.lookup
6210
- [class.mfct]: class.md#class.mfct
6211
  [class.mfct.non.static]: class.md#class.mfct.non.static
6212
  [class.mi]: class.md#class.mi
 
6213
  [class.prop]: class.md#class.prop
6214
  [class.spaceship]: class.md#class.spaceship
6215
  [class.static.mfct]: class.md#class.static.mfct
6216
  [class.temporary]: basic.md#class.temporary
6217
  [class.union]: class.md#class.union
@@ -6234,62 +7310,67 @@ A function or variable is *needed for constant evaluation* if it is:
6234
  [conv.prom]: #conv.prom
6235
  [conv.ptr]: #conv.ptr
6236
  [conv.qual]: #conv.qual
6237
  [conv.rank]: basic.md#conv.rank
6238
  [conv.rval]: #conv.rval
6239
- [cpp]: cpp.md#cpp
6240
  [cstdarg.syn]: support.md#cstdarg.syn
6241
  [cstddef.syn]: support.md#cstddef.syn
 
6242
  [dcl.align]: dcl.md#dcl.align
6243
  [dcl.array]: dcl.md#dcl.array
6244
  [dcl.asm]: dcl.md#dcl.asm
6245
- [dcl.attr.assume]: dcl.md#dcl.attr.assume
6246
  [dcl.constexpr]: dcl.md#dcl.constexpr
6247
- [dcl.dcl]: dcl.md#dcl.dcl
 
6248
  [dcl.decl]: dcl.md#dcl.decl
6249
  [dcl.enum]: dcl.md#dcl.enum
6250
  [dcl.fct]: dcl.md#dcl.fct
6251
  [dcl.fct.def]: dcl.md#dcl.fct.def
6252
  [dcl.fct.def.coroutine]: dcl.md#dcl.fct.def.coroutine
6253
  [dcl.fct.def.general]: dcl.md#dcl.fct.def.general
6254
  [dcl.fct.default]: dcl.md#dcl.fct.default
6255
  [dcl.init]: dcl.md#dcl.init
6256
  [dcl.init.aggr]: dcl.md#dcl.init.aggr
 
6257
  [dcl.init.list]: dcl.md#dcl.init.list
6258
  [dcl.init.ref]: dcl.md#dcl.init.ref
6259
  [dcl.init.string]: dcl.md#dcl.init.string
6260
  [dcl.link]: dcl.md#dcl.link
6261
  [dcl.mptr]: dcl.md#dcl.mptr
6262
  [dcl.name]: dcl.md#dcl.name
 
6263
  [dcl.ptr]: dcl.md#dcl.ptr
6264
  [dcl.ref]: dcl.md#dcl.ref
6265
  [dcl.spec.auto]: dcl.md#dcl.spec.auto
 
6266
  [dcl.stc]: dcl.md#dcl.stc
6267
  [dcl.struct.bind]: dcl.md#dcl.struct.bind
6268
  [dcl.type]: dcl.md#dcl.type
6269
  [dcl.type.auto.deduct]: dcl.md#dcl.type.auto.deduct
 
6270
  [dcl.type.cv]: dcl.md#dcl.type.cv
6271
  [dcl.type.decltype]: dcl.md#dcl.type.decltype
6272
  [dcl.type.elab]: dcl.md#dcl.type.elab
6273
  [dcl.type.simple]: dcl.md#dcl.type.simple
6274
  [defns.access]: intro.md#defns.access
6275
  [defns.nonconst.libcall]: intro.md#defns.nonconst.libcall
6276
- [depr.arith.conv.enum]: future.md#depr.arith.conv.enum
6277
- [depr.array.comp]: future.md#depr.array.comp
6278
  [depr.capture.this]: future.md#depr.capture.this
6279
  [depr.volatile.type]: future.md#depr.volatile.type
6280
  [except]: except.md#except
 
6281
  [except.handle]: except.md#except.handle
6282
  [except.pre]: except.md#except.pre
6283
  [except.spec]: except.md#except.spec
6284
  [except.terminate]: except.md#except.terminate
6285
  [except.throw]: except.md#except.throw
 
6286
  [expr]: #expr
6287
  [expr.add]: #expr.add
6288
  [expr.alignof]: #expr.alignof
6289
  [expr.arith.conv]: #expr.arith.conv
6290
- [expr.ass]: #expr.ass
6291
  [expr.await]: #expr.await
6292
  [expr.bit.and]: #expr.bit.and
6293
  [expr.call]: #expr.call
6294
  [expr.cast]: #expr.cast
6295
  [expr.comma]: #expr.comma
@@ -6312,30 +7393,34 @@ A function or variable is *needed for constant evaluation* if it is:
6312
  [expr.post.incr]: #expr.post.incr
6313
  [expr.pre]: #expr.pre
6314
  [expr.pre.incr]: #expr.pre.incr
6315
  [expr.prim]: #expr.prim
6316
  [expr.prim.fold]: #expr.prim.fold
 
6317
  [expr.prim.id]: #expr.prim.id
6318
  [expr.prim.id.dtor]: #expr.prim.id.dtor
6319
  [expr.prim.id.general]: #expr.prim.id.general
6320
  [expr.prim.id.qual]: #expr.prim.id.qual
6321
  [expr.prim.id.unqual]: #expr.prim.id.unqual
6322
  [expr.prim.lambda]: #expr.prim.lambda
6323
  [expr.prim.lambda.capture]: #expr.prim.lambda.capture
6324
  [expr.prim.lambda.closure]: #expr.prim.lambda.closure
6325
  [expr.prim.lambda.general]: #expr.prim.lambda.general
6326
  [expr.prim.literal]: #expr.prim.literal
 
6327
  [expr.prim.paren]: #expr.prim.paren
6328
  [expr.prim.req]: #expr.prim.req
6329
  [expr.prim.req.compound]: #expr.prim.req.compound
6330
  [expr.prim.req.general]: #expr.prim.req.general
6331
  [expr.prim.req.nested]: #expr.prim.req.nested
6332
  [expr.prim.req.simple]: #expr.prim.req.simple
6333
  [expr.prim.req.type]: #expr.prim.req.type
 
6334
  [expr.prim.this]: #expr.prim.this
6335
  [expr.prop]: #expr.prop
6336
  [expr.ref]: #expr.ref
 
6337
  [expr.reinterpret.cast]: #expr.reinterpret.cast
6338
  [expr.rel]: #expr.rel
6339
  [expr.shift]: #expr.shift
6340
  [expr.sizeof]: #expr.sizeof
6341
  [expr.spaceship]: #expr.spaceship
@@ -6358,67 +7443,81 @@ A function or variable is *needed for constant evaluation* if it is:
6358
  [intro.memory]: basic.md#intro.memory
6359
  [intro.object]: basic.md#intro.object
6360
  [lex.ext]: lex.md#lex.ext
6361
  [lex.icon]: lex.md#lex.icon
6362
  [lex.literal]: lex.md#lex.literal
 
6363
  [lex.string]: lex.md#lex.string
6364
  [library]: library.md#library
6365
  [meta.const.eval]: meta.md#meta.const.eval
 
 
 
 
6366
  [namespace.udecl]: dcl.md#namespace.udecl
6367
  [new.badlength]: support.md#new.badlength
6368
  [new.delete.array]: support.md#new.delete.array
6369
  [new.delete.placement]: support.md#new.delete.placement
6370
  [new.delete.single]: support.md#new.delete.single
6371
  [over]: over.md#over
6372
- [over.ass]: over.md#over.ass
6373
  [over.best.ics]: over.md#over.best.ics
6374
  [over.built]: over.md#over.built
6375
  [over.call]: over.md#over.call
6376
  [over.call.func]: over.md#over.call.func
6377
  [over.ics.user]: over.md#over.ics.user
6378
  [over.literal]: over.md#over.literal
6379
  [over.match]: over.md#over.match
6380
  [over.match.class.deduct]: over.md#over.match.class.deduct
 
6381
  [over.match.oper]: over.md#over.match.oper
6382
  [over.match.viable]: over.md#over.match.viable
6383
  [over.oper]: over.md#over.oper
6384
  [over.over]: over.md#over.over
6385
  [over.sub]: over.md#over.sub
 
6386
  [replacement.functions]: library.md#replacement.functions
6387
  [special]: class.md#special
6388
  [std.modules]: library.md#std.modules
 
 
6389
  [stmt.goto]: stmt.md#stmt.goto
6390
  [stmt.if]: stmt.md#stmt.if
6391
  [stmt.iter]: stmt.md#stmt.iter
6392
  [stmt.jump]: stmt.md#stmt.jump
6393
  [stmt.pre]: stmt.md#stmt.pre
6394
  [stmt.return]: stmt.md#stmt.return
6395
  [stmt.return.coroutine]: stmt.md#stmt.return.coroutine
6396
  [stmt.switch]: stmt.md#stmt.switch
 
6397
  [support.runtime]: support.md#support.runtime
6398
  [support.types.layout]: support.md#support.types.layout
 
6399
  [temp.arg]: temp.md#temp.arg
6400
  [temp.concept]: temp.md#temp.concept
6401
  [temp.constr.atomic]: temp.md#temp.constr.atomic
6402
  [temp.constr.constr]: temp.md#temp.constr.constr
6403
  [temp.constr.decl]: temp.md#temp.constr.decl
 
6404
  [temp.dep.constexpr]: temp.md#temp.dep.constexpr
 
6405
  [temp.expl.spec]: temp.md#temp.expl.spec
6406
  [temp.explicit]: temp.md#temp.explicit
6407
  [temp.mem]: temp.md#temp.mem
6408
  [temp.names]: temp.md#temp.names
6409
  [temp.over.link]: temp.md#temp.over.link
6410
  [temp.param]: temp.md#temp.param
6411
  [temp.pre]: temp.md#temp.pre
6412
  [temp.res]: temp.md#temp.res
6413
  [temp.spec.partial]: temp.md#temp.spec.partial
 
6414
  [temp.variadic]: temp.md#temp.variadic
6415
  [term.incomplete.type]: basic.md#term.incomplete.type
6416
  [term.object.representation]: basic.md#term.object.representation
6417
  [term.odr.use]: basic.md#term.odr.use
 
6418
  [term.unevaluated.operand]: #term.unevaluated.operand
6419
- [thread]: thread.md#thread
6420
  [type.info]: support.md#type.info
6421
  [typeinfo.syn]: support.md#typeinfo.syn
6422
 
6423
  [^1]: The precedence of operators is not directly specified, but it can
6424
  be derived from the syntax.
@@ -6426,23 +7525,22 @@ A function or variable is *needed for constant evaluation* if it is:
6426
  [^2]: Overloaded operators are never assumed to be associative or
6427
  commutative.
6428
 
6429
  [^3]: The cast and assignment operators must still perform their
6430
  specific conversions as described in  [[expr.type.conv]],
6431
- [[expr.cast]], [[expr.static.cast]] and  [[expr.ass]].
6432
 
6433
  [^4]: The intent of this list is to specify those circumstances in which
6434
  an object can or cannot be aliased.
6435
 
6436
  [^5]: For historical reasons, this conversion is called the
6437
  “lvalue-to-rvalue” conversion, even though that name does not
6438
  accurately reflect the taxonomy of expressions described in 
6439
  [[basic.lval]].
6440
 
6441
  [^6]: In C++ class and array prvalues can have cv-qualified types. This
6442
- differs from ISO C, in which non-lvalues never have cv-qualified
6443
- types.
6444
 
6445
  [^7]: This conversion never applies to non-static member functions
6446
  because an lvalue that refers to a non-static member function cannot
6447
  be obtained.
6448
 
@@ -6458,99 +7556,92 @@ A function or variable is *needed for constant evaluation* if it is:
6458
 
6459
  [^9]: As a consequence, operands of type `bool`, `char8_t`, `char16_t`,
6460
  `char32_t`, `wchar_t`, or of enumeration type are converted to some
6461
  integral type.
6462
 
6463
- [^10]: This also applies when the object expression is an implicit
6464
- `(*this)` [[class.mfct.non.static]].
6465
-
6466
- [^11]: This is true even if the subscript operator is used in the
6467
  following common idiom: `&x[0]`.
6468
 
 
 
6469
  [^12]: If the class member access expression is evaluated, the
6470
  subexpression evaluation happens even if the result is unnecessary
6471
  to determine the value of the entire postfix expression, for example
6472
  if the *id-expression* denotes a static member.
6473
 
6474
- [^13]: Note that `(*(E1))` is an lvalue.
6475
-
6476
- [^14]: The most derived object [[intro.object]] pointed or referred to
6477
  by `v` can contain other `B` objects as base classes, but these are
6478
  ignored.
6479
 
6480
- [^15]: The recommended name for such a class is `extended_type_info`.
6481
 
6482
- [^16]: If `p` is an expression of pointer type, then `*p`, `(*p)`,
6483
- `*(p)`, `((*p))`, `*((p))`, and so on all meet this requirement.
6484
-
6485
- [^17]: The types can have different cv-qualifiers, subject to the
6486
  overall restriction that a `reinterpret_cast` cannot cast away
6487
  constness.
6488
 
6489
- [^18]: `T1` and `T2` can have different cv-qualifiers, subject to the
6490
  overall restriction that a `reinterpret_cast` cannot cast away
6491
  constness.
6492
 
6493
- [^19]: This is sometimes referred to as a type pun when the result
6494
  refers to the same object as the source glvalue.
6495
 
6496
- [^20]: `const_cast` is not limited to conversions that cast away a
6497
  const-qualifier.
6498
 
6499
- [^21]: `sizeof``(``bool``)` is not required to be `1`.
6500
 
6501
- [^22]: The actual size of a potentially-overlapping subobject can be
6502
  less than the result of applying `sizeof` to the subobject, due to
6503
  virtual base classes and less strict padding requirements on
6504
  potentially-overlapping subobjects.
6505
 
6506
- [^23]: If the conversion function returns a signed integer type, the
6507
  second standard conversion converts to the unsigned type
6508
  `std::size_t` and thus thwarts any attempt to detect a negative
6509
  value afterwards.
6510
 
6511
- [^24]: This can include evaluating a *new-initializer* and/or calling a
6512
  constructor.
6513
 
6514
- [^25]: A *lambda-expression* with a *lambda-introducer* that consists of
6515
  empty square brackets can follow the `delete` keyword if the
6516
  *lambda-expression* is enclosed in parentheses.
6517
 
6518
- [^26]: This implies that an object cannot be deleted using a pointer of
6519
- type `void*` because `void` is not an object type.
6520
-
6521
- [^27]: For nonzero-length arrays, this is the same as a pointer to the
6522
  first element of the array created by that *new-expression*.
6523
  Zero-length arrays do not have a first element.
6524
 
6525
- [^28]: This is often called truncation towards zero.
6526
 
6527
- [^29]: As specified in [[basic.compound]], an object that is not an
6528
  array element is considered to belong to a single-element array for
6529
  this purpose and a pointer past the last element of an array of n
6530
  elements is considered to be equivalent to a pointer to a
6531
  hypothetical array element n for this purpose.
6532
 
6533
- [^30]: As specified in [[basic.compound]], an object that is not an
6534
  array element is considered to belong to a single-element array for
6535
  this purpose and a pointer past the last element of an array of n
6536
  elements is considered to be equivalent to a pointer to a
6537
  hypothetical array element n for this purpose.
6538
 
6539
- [^31]: As specified in [[basic.compound]], an object that is not an
6540
  array element is considered to belong to a single-element array for
6541
  this purpose.
6542
 
6543
- [^32]: Overload resolution [[over.match]] is applied as usual.
6544
 
6545
- [^33]: This includes, for example, signed integer overflow [[expr.pre]],
6546
  certain pointer arithmetic [[expr.add]], division by zero
6547
  [[expr.mul]], or certain shift operations [[expr.shift]].
6548
 
6549
- [^34]: Testing this condition can involve a trial evaluation of its
6550
- initializer as described above.
 
 
6551
 
6552
- [^35]: In some cases, constant evaluation is needed to determine whether
6553
  a narrowing conversion is performed [[dcl.init.list]].
6554
 
6555
- [^36]: In some cases, constant evaluation is needed to determine whether
6556
  such an expression is value-dependent [[temp.dep.constexpr]].
 
30
  this Standard. However, these built-in operators participate in overload
31
  resolution, and as part of that process user-defined conversions will be
32
  considered where necessary to convert the operands to types appropriate
33
  for the built-in operator. If a built-in operator is selected, such
34
  conversions will be applied to the operands before the operation is
35
+ considered further according to the rules in [[expr.compound]]; see 
36
+ [[over.match.oper]], [[over.built]].
37
 
38
  If during the evaluation of an expression, the result is not
39
  mathematically defined or not in the range of representable values for
40
  its type, the behavior is undefined.
41
 
 
111
  <a id="fig:basic.lval"></a>
112
 
113
  ![Expression category taxonomy \[fig:basic.lval\]](images/valuecategories.svg)
114
 
115
  - A *glvalue* is an expression whose evaluation determines the identity
116
+ of an object, function, or non-static data member.
117
  - A *prvalue* is an expression whose evaluation initializes an object or
118
  computes the value of an operand of an operator, as specified by the
119
  context in which it appears, or an expression that has type cv `void`.
120
  - An *xvalue* is a glvalue that denotes an object whose resources can be
121
  reused (usually because it is near the end of its lifetime).
122
  - An *lvalue* is a glvalue that is not an xvalue.
123
  - An *rvalue* is a prvalue or an xvalue.
124
 
125
+ Every expression belongs to exactly one of the fundamental categories in
126
+ this taxonomy: lvalue, xvalue, or prvalue. This property of an
127
+ expression is called its *value category*.
128
 
129
  [*Note 1*: The discussion of each built-in operator in
130
  [[expr.compound]] indicates the category of the value it yields and the
131
  value categories of the operands it expects. For example, the built-in
132
  assignment operators expect that the left operand is an lvalue and that
 
137
 
138
  [*Note 2*: Historically, lvalues and rvalues were so-called because
139
  they could appear on the left- and right-hand side of an assignment
140
  (although this is no longer generally true); glvalues are “generalized”
141
  lvalues, prvalues are “pure” rvalues, and xvalues are “eXpiring”
142
+ lvalues. Despite their names, these terms apply to expressions, not
143
  values. — *end note*]
144
 
145
  [*Note 3*:
146
 
147
  An expression is an xvalue if it is:
148
 
149
+ - a move-eligible *id-expression* [[expr.prim.id.unqual]] or
150
+ *splice-expression* [[expr.prim.splice]],
151
  - the result of calling a function, whether implicitly or explicitly,
152
  whose return type is an rvalue reference to object type [[expr.call]],
153
  - a cast to an rvalue reference to object type
154
  [[expr.type.conv]], [[expr.dynamic.cast]], [[expr.static.cast]], [[expr.reinterpret.cast]], [[expr.const.cast]], [[expr.cast]],
155
  - a subscripting operation with an xvalue array operand [[expr.sub]],
 
188
  The *result* of a glvalue is the entity denoted by the expression. The
189
  *result* of a prvalue is the value that the expression stores into its
190
  context; a prvalue that has type cv `void` has no result. A prvalue
191
  whose result is the value *V* is sometimes said to have or name the
192
  value *V*. The *result object* of a prvalue is the object initialized by
193
+ the prvalue; a prvalue that has type cv `void` has no result object.
 
 
194
 
195
  [*Note 4*: Except when the prvalue is the operand of a
196
+ *decltype-specifier*, a prvalue of object type always has a result
197
+ object. For a discarded prvalue that has type other than cv `void`, a
198
+ temporary object is materialized; see [[expr.context]]. — *end note*]
 
199
 
200
+ Whenever a glvalue appears as an operand of an operator that requires a
201
  prvalue for that operand, the lvalue-to-rvalue [[conv.lval]],
202
  array-to-pointer [[conv.array]], or function-to-pointer [[conv.func]]
203
  standard conversions are applied to convert the expression to a prvalue.
204
 
205
  [*Note 5*: An attempt to bind an rvalue reference to an lvalue is not
 
212
 
213
  [*Note 7*: There are no prvalue bit-fields; if a bit-field is converted
214
  to a prvalue [[conv.lval]], a prvalue of the type of the bit-field is
215
  created, which might then be promoted [[conv.prom]]. — *end note*]
216
 
217
+ Unless otherwise specified
218
+ [[expr.reinterpret.cast]], [[expr.const.cast]], whenever a prvalue that
219
+ is not the result of the lvalue-to-rvalue conversion [[conv.lval]]
220
+ appears as an operand of an operator, the temporary materialization
221
+ conversion [[conv.rval]] is applied to convert the expression to an
222
+ xvalue.
223
 
224
+ [*Note 8*: The discussion of reference initialization in 
225
+ [[dcl.init.ref]] and of temporaries in  [[class.temporary]] indicates
226
+ the behavior of lvalues and rvalues in other significant
227
+ contexts. — *end note*]
228
 
229
  Unless otherwise indicated [[dcl.type.decltype]], a prvalue shall always
230
  have complete type or the `void` type; if it has a class type or
231
  (possibly multidimensional) array of class type, that class shall not be
232
  an abstract class [[class.abstract]]. A glvalue shall not have type
233
  cv `void`.
234
 
235
+ [*Note 9*: A glvalue can have complete or incomplete non-`void` type.
236
  Class and array prvalues can have cv-qualified types; other prvalues
237
  always have cv-unqualified types. See [[expr.type]]. — *end note*]
238
 
239
  An lvalue is *modifiable* unless its type is const-qualified or is a
240
  function type.
241
 
242
+ [*Note 10*: A program that attempts to modify an object through a
243
  nonmodifiable lvalue or through an rvalue is ill-formed
244
+ [[expr.assign]], [[expr.post.incr]], [[expr.pre.incr]]. — *end note*]
245
 
246
+ An object of dynamic type `T`_obj is *type-accessible* through a glvalue
247
+ of type `T`_ref if `T`_ref is similar [[conv.qual]] to:
 
248
 
249
+ - `T`_obj,
250
+ - a type that is the signed or unsigned type corresponding to `T`_obj,
251
+ or
252
  - a `char`, `unsigned char`, or `std::byte` type.
253
 
254
+ If a program attempts to access [[defns.access]] the stored value of an
255
+ object through a glvalue through which it is not type-accessible, the
256
+ behavior is undefined.[^4]
257
+
258
  If a program invokes a defaulted copy/move constructor or copy/move
259
  assignment operator for a union of type `U` with a glvalue argument that
260
  does not denote an object of type cv `U` within its lifetime, the
261
  behavior is undefined.
262
 
263
+ [*Note 11*: In C, an entire object of structure type can be accessed,
264
  e.g., using assignment. By contrast, C++ has no notion of accessing an
265
  object of class type through an lvalue of class type. — *end note*]
266
 
267
  ### Type <a id="expr.type">[[expr.type]]</a>
268
 
269
  If an expression initially has the type “reference to `T`”
270
  [[dcl.ref]], [[dcl.init.ref]], the type is adjusted to `T` prior to any
271
+ further analysis; the value category of the expression is not altered.
272
+ Let X be the object or function denoted by the reference. If a pointer
273
+ to X would be valid in the context of the evaluation of the expression
274
+ [[basic.fundamental]], the result designates X; otherwise, the behavior
275
+ is undefined.
276
 
277
  [*Note 1*: Before the lifetime of the reference has started or after it
278
  has ended, the behavior is undefined (see 
279
  [[basic.life]]). — *end note*]
280
 
 
294
  “pointer to *cv12* `void`”, where *cv12* is the union of *cv1* and
295
  *cv2*;
296
  - if `T1` or `T2` is “pointer to `noexcept` function” and the other type
297
  is “pointer to function”, where the function types are otherwise the
298
  same, “pointer to function”;
299
+ - if `T1` is “pointer to `C1`” and `T2` is “pointer to `C2`”, where `C1`
300
+ is reference-related to `C2` or `C2` is reference-related to `C1`
301
+ [[dcl.init.ref]], the qualification-combined type [[conv.qual]] of
302
+ `T1` and `T2` or the qualification-combined type of `T2` and `T1`,
303
+ respectively;
304
  - if `T1` or `T2` is “pointer to member of `C1` of type function”, the
305
  other type is “pointer to member of `C2` of type `noexcept` function”,
306
  and `C1` is reference-related to `C2` or `C2` is reference-related to
307
  `C1` [[dcl.init.ref]], where the function types are otherwise the
308
  same, “pointer to member of `C2` of type function” or “pointer to
 
334
  — *end example*]
335
 
336
  ### Context dependence <a id="expr.context">[[expr.context]]</a>
337
 
338
  In some contexts, *unevaluated operands* appear
339
+ [[expr.prim.req.simple]], [[expr.prim.req.compound]], [[expr.typeid]], [[expr.sizeof]], [[expr.unary.noexcept]], [[expr.reflect]], [[dcl.type.decltype]], [[temp.pre]], [[temp.concept]].
340
  An unevaluated operand is not evaluated.
341
 
342
  [*Note 1*: In an unevaluated operand, a non-static class member can be
343
  named [[expr.prim.id]] and naming of objects or functions does not, by
344
  itself, require that a definition be provided [[basic.def.odr]]. An
 
352
  [[conv.lval]] is applied if and only if the expression is a glvalue of
353
  volatile-qualified type and it is one of the following:
354
 
355
  - `(` *expression* `)`, where *expression* is one of these expressions,
356
  - *id-expression* [[expr.prim.id]],
357
+ - *splice-expression* [[expr.prim.splice]],
358
  - subscripting [[expr.sub]],
359
  - class member access [[expr.ref]],
360
  - indirection [[expr.unary.op]],
361
  - pointer-to-member operation [[expr.mptr.oper]],
362
  - conditional expression [[expr.cond]] where both the second and the
 
398
 
399
  [*Note 1*: A standard conversion sequence can be empty, i.e., it can
400
  consist of no conversions. — *end note*]
401
 
402
  A standard conversion sequence will be applied to an expression if
403
+ necessary to convert it to an expression having a required destination
404
+ type and value category.
405
 
406
  [*Note 2*:
407
 
408
  Expressions with a given type will be implicitly converted to other
409
  types in several contexts:
 
421
  [[dcl.init.ref]].
422
 
423
  — *end note*]
424
 
425
  An expression E can be *implicitly converted* to a type `T` if and only
426
+ if the declaration `T t = E;` is well-formed, for some invented
427
+ temporary variable `t` [[dcl.init]].
428
 
429
  Certain language constructs require that an expression be converted to a
430
  Boolean value. An expression E appearing in such a context is said to be
431
  *contextually converted to `bool`* and is well-formed if and only if the
432
  declaration `bool t(E);` is well-formed, for some invented temporary
 
506
  `T` is volatile-qualified [[intro.execution]], and the glvalue can
507
  refer to an inactive member of a union [[class.union]]. — *end note*]
508
  - Otherwise, if `T` has a class type, the conversion copy-initializes
509
  the result object from the glvalue.
510
  - Otherwise, if the object to which the glvalue refers contains an
511
+ invalid pointer value [[basic.compound]], the behavior is
512
+ *implementation-defined*.
513
+ - Otherwise, if the bits in the value representation of the object to
514
+ which the glvalue refers are not valid for the object’s type, the
515
+ behavior is undefined.
516
+ \[*Example 2*:
517
+ ``` cpp
518
+ bool f() {
519
+ bool b = true;
520
+ char c = 42;
521
+ memcpy(&b, &c, 1);
522
+ return b; // undefined behavior if 42 is not a valid value representation for bool
523
+ }
524
+ ```
525
+
526
+ — *end example*]
527
  - Otherwise, the object indicated by the glvalue is read
528
+ [[defns.access]]. Let `V` be the value contained in the object. If `T`
529
+ is an integer type, the prvalue result is the value of type `T`
530
+ congruent [[basic.fundamental]] to `V`, and `V` otherwise.
531
 
532
  [*Note 2*: See also  [[basic.lval]]. — *end note*]
533
 
534
  ### Array-to-pointer conversion <a id="conv.array">[[conv.array]]</a>
535
 
 
578
  [*Example 1*: The type denoted by the *type-id* `const int **` has
579
  three qualification-decompositions, taking `U` as “`int`”, as “pointer
580
  to `const int`”, and as “pointer to pointer to
581
  `const int`”. — *end example*]
582
 
 
 
 
 
583
  Two types `T1` and `T2` are *similar* if they have
584
  qualification-decompositions with the same n such that corresponding Pᵢ
585
  components are either the same or one is “array of Nᵢ” and the other is
586
  “array of unknown bound of”, and the types denoted by `U` are the same.
587
 
 
633
  pointer-to-member-function types) are never cv-qualified
634
  [[dcl.fct]]. — *end note*]
635
 
636
  ### Integral promotions <a id="conv.prom">[[conv.prom]]</a>
637
 
638
+ For the purposes of [[conv.prom]], a *converted bit-field* is a prvalue
639
+ that is the result of an lvalue-to-rvalue conversion [[conv.lval]]
640
+ applied to a bit-field [[class.bit]].
 
 
641
 
642
+ A prvalue that is not a converted bit-field and has an integer type
643
+ other than `bool`, `char8_t`, `char16_t`, `char32_t`, or `wchar_t` whose
644
+ integer conversion rank [[conv.rank]] is less than the rank of `int` can
645
+ be converted to a prvalue of type `int` if `int` can represent all the
646
+ values of the source type; otherwise, the source prvalue can be
647
+ converted to a prvalue of type `unsigned int`.
 
 
648
 
649
  A prvalue of an unscoped enumeration type whose underlying type is not
650
  fixed can be converted to a prvalue of the first of the following types
651
  that can represent all the values of the enumeration [[dcl.enum]]:
652
  `int`, `unsigned int`, `long int`, `unsigned long int`, `long long int`,
 
662
  [[dcl.enum]] can be converted to a prvalue of its underlying type.
663
  Moreover, if integral promotion can be applied to its underlying type, a
664
  prvalue of an unscoped enumeration type whose underlying type is fixed
665
  can also be converted to a prvalue of the promoted underlying type.
666
 
667
+ [*Note 1*: A converted bit-field of enumeration type is treated as any
668
+ other value of that type for promotion purposes. *end note*]
669
+
670
+ A converted bit-field of integral type can be converted to a prvalue of
671
+ type `int` if `int` can represent all the values of the bit-field;
672
+ otherwise, it can be converted to `unsigned int` if `unsigned int` can
673
+ represent all the values of the bit-field.
674
+
675
+ A prvalue of type `char8_t`, `char16_t`, `char32_t`, or `wchar_t`
676
+ [[basic.fundamental]] (including a converted bit-field that was not
677
+ already promoted to `int` or `unsigned int` according to the rules
678
+ above) can be converted to a prvalue of the first of the following types
679
+ that can represent all the values of its underlying type: `int`,
680
+ `unsigned int`, `long int`, `unsigned long int`, `long long int`,
681
+ `unsigned long long int`, or its underlying type.
682
 
683
  A prvalue of type `bool` can be converted to a prvalue of type `int`,
684
  with `false` becoming zero and `true` becoming one.
685
 
686
  These conversions are called *integral promotions*.
 
756
  A *null pointer constant* is an integer literal [[lex.icon]] with value
757
  zero or a prvalue of type `std::nullptr_t`. A null pointer constant can
758
  be converted to a pointer type; the result is the null pointer value of
759
  that type [[basic.compound]] and is distinguishable from every other
760
  value of object pointer or function pointer type. Such a conversion is
761
+ called a *null pointer conversion*. The conversion of a null pointer
762
+ constant to a pointer to cv-qualified type is a single conversion, and
763
+ not the sequence of a pointer conversion followed by a qualification
764
+ conversion [[conv.qual]]. A null pointer constant of integral type can
765
+ be converted to a prvalue of type `std::nullptr_t`.
 
766
 
767
  [*Note 1*: The resulting prvalue is not a null pointer
768
  value. — *end note*]
769
 
770
  A prvalue of type “pointer to cv `T`”, where `T` is an object type, can
771
  be converted to a prvalue of type “pointer to cv `void`”. The pointer
772
  value [[basic.compound]] is unchanged by this conversion.
773
 
774
+ A prvalue `v` of type “pointer to cv `D`”, where `D` is a complete class
775
  type, can be converted to a prvalue of type “pointer to cv `B`”, where
776
  `B` is a base class [[class.derived]] of `D`. If `B` is an inaccessible
777
  [[class.access]] or ambiguous [[class.member.lookup]] base class of `D`,
778
+ a program that necessitates this conversion is ill-formed. If `v` is a
779
+ null pointer value, the result is a null pointer value. Otherwise, if
780
+ `B` is a virtual base class of `D` and `v` does not point to an object
781
+ whose type is similar [[conv.qual]] to `D` and that is within its
782
+ lifetime or within its period of construction or destruction
783
+ [[class.cdtor]], the behavior is undefined. Otherwise, the result is a
784
+ pointer to the base class subobject of the derived class object.
785
 
786
  ### Pointer-to-member conversions <a id="conv.mem">[[conv.mem]]</a>
787
 
788
  A null pointer constant [[conv.ptr]] can be converted to a
789
  pointer-to-member type; the result is the *null member pointer value* of
790
  that type and is distinguishable from any pointer to member not created
791
  from a null pointer constant. Such a conversion is called a *null member
792
+ pointer conversion*. The conversion of a null pointer constant to a
 
793
  pointer to member of cv-qualified type is a single conversion, and not
794
  the sequence of a pointer-to-member conversion followed by a
795
  qualification conversion [[conv.qual]].
796
 
797
  A prvalue of type “pointer to member of `B` of type cv `T`”, where `B`
798
  is a class type, can be converted to a prvalue of type “pointer to
799
  member of `D` of type cv `T`”, where `D` is a complete class derived
800
  [[class.derived]] from `B`. If `B` is an inaccessible [[class.access]],
801
  ambiguous [[class.member.lookup]], or virtual [[class.mi]] base class of
802
  `D`, or a base class of a virtual base class of `D`, a program that
803
+ necessitates this conversion is ill-formed. If class `D` does not
804
+ contain the original member and is not a base class of the class
805
+ containing the original member, the behavior is undefined. Otherwise,
806
+ the result of the conversion refers to the same member as the pointer to
807
+ member before the conversion took place, but it refers to the base class
808
+ member as if it were a member of the derived class. The result refers to
809
+ the member in `D`’s instance of `B`. Since the result has type “pointer
810
+ to member of `D` of type cv `T`”, indirection through it with a `D`
811
+ object is valid. The result is the same as if indirecting through the
812
+ pointer to member of `B` with the `B` subobject of `D`. The null member
813
+ pointer value is converted to the null member pointer value of the
814
+ destination type.[^8]
815
 
816
  ### Function pointer conversions <a id="conv.fctptr">[[conv.fctptr]]</a>
817
 
818
  A prvalue of type “pointer to `noexcept` function” can be converted to a
819
  prvalue of type “pointer to function”. The result is a pointer to the
 
846
  type cause conversions and yield result types in a similar way. The
847
  purpose is to yield a common type, which is also the type of the result.
848
  This pattern is called the *usual arithmetic conversions*, which are
849
  defined as follows:
850
 
851
+ - The lvalue-to-rvalue conversion [[conv.lval]] is applied to each
852
+ operand and the resulting prvalues are used in place of the original
853
+ operands for the remainder of this section.
854
  - If either operand is of scoped enumeration type [[dcl.enum]], no
855
  conversions are performed; if the other operand does not have the same
856
  type, the expression is ill-formed.
857
+ - Otherwise, if one operand is of enumeration type and the other operand
858
+ is of a different enumeration type or a floating-point type, the
859
+ expression is ill-formed.
860
  - Otherwise, if either operand is of floating-point type, the following
861
  rules are applied:
862
  - If both operands have the same type, no further conversion is
863
+ performed.
864
  - Otherwise, if one of the operands is of a non-floating-point type,
865
  that operand is converted to the type of the operand with the
866
  floating-point type.
867
  - Otherwise, if the floating-point conversion ranks [[conv.rank]] of
868
  the types of the operands are ordered but not equal, then the
 
886
  `U`.
887
  - Otherwise, if `S` can represent all of the values of `U`, `C` is
888
  `S`.
889
  - Otherwise, `C` is the unsigned integer type corresponding to `S`.
890
 
 
 
 
 
891
  ## Primary expressions <a id="expr.prim">[[expr.prim]]</a>
892
 
893
+ ### Grammar <a id="expr.prim.grammar">[[expr.prim.grammar]]</a>
894
+
895
  ``` bnf
896
  primary-expression:
897
  literal
898
  this
899
  '(' expression ')'
900
  id-expression
901
  lambda-expression
902
  fold-expression
903
  requires-expression
904
+ splice-expression
905
  ```
906
 
907
  ### Literals <a id="expr.prim.literal">[[expr.prim.literal]]</a>
908
 
909
  The type of a *literal* is determined based on its form as specified in
 
923
  innermost class scope containing that point.
924
 
925
  [*Note 1*: A *lambda-expression* does not introduce a class
926
  scope. — *end note*]
927
 
928
+ If the expression `this` appears within the predicate of a contract
929
+ assertion [[basic.contract.general]] (including as the result of an
930
+ implicit transformation [[expr.prim.id.general]] and including in the
931
+ bodies of nested *lambda-expression*s) and the current class encloses
932
+ the contract assertion, `const` is combined with the *cv-qualifier-seq*
933
+ used to generate the resulting type (see below).
934
+
935
  If a declaration declares a member function or member function template
936
  of a class `X`, the expression `this` is a prvalue of type “pointer to
937
  *cv-qualifier-seq* `X`” wherever `X` is the current class between the
938
  optional *cv-qualifier-seq* and the end of the *function-definition*,
939
  *member-declarator*, or *declarator*. It shall not appear within the
940
+ declaration of a static or explicit object member function of the
941
+ current class (although its type and value category are defined within
942
+ such member functions as they are within an implicit object member
943
+ function).
944
 
945
  [*Note 2*: This is because declaration matching does not occur until
946
  the complete declarator is known. — *end note*]
947
 
948
  [*Note 3*:
 
1006
 
1007
  ``` bnf
1008
  id-expression:
1009
  unqualified-id
1010
  qualified-id
1011
+ pack-index-expression
1012
  ```
1013
 
1014
  An *id-expression* is a restricted form of a *primary-expression*.
1015
 
1016
  [*Note 1*: An *id-expression* can appear after `.` and `->` operators
1017
  [[expr.ref]]. — *end note*]
1018
 
1019
+ If an *id-expression* E denotes a non-static non-type member of some
1020
+ class `C` at a point where the current class [[expr.prim.this]] is `X`
1021
+ and
1022
+
1023
+ - E is potentially evaluated or `C` is `X` or a base class of `X`, and
1024
+ - E is not the *id-expression* of a class member access expression
1025
+ [[expr.ref]], and
1026
+ - E is not the *id-expression* of a *reflect-expression*
1027
+ [[expr.reflect]], and
1028
+ - if E is a *qualified-id*, E is not the un-parenthesized operand of the
1029
+ unary `&` operator [[expr.unary.op]],
1030
+
1031
+ the *id-expression* is transformed into a class member access expression
1032
+ using `(*this)` as the object expression. If this transformation occurs
1033
+ in the predicate of a precondition assertion of a constructor of `X` or
1034
+ a postcondition assertion of a destructor of `X`, the expression is
1035
+ ill-formed.
1036
+
1037
+ [*Note 2*: If `C` is not `X` or a base class of `X`, the class member
1038
+ access expression is ill-formed. Also, if the *id-expression* occurs
1039
+ within a static or explicit object member function, the class member
1040
+ access is ill-formed. — *end note*]
1041
+
1042
+ This transformation does not apply in the template definition context
1043
+ [[temp.dep.type]].
1044
+
1045
+ [*Example 1*:
1046
+
1047
+ ``` cpp
1048
+ struct C {
1049
+ bool b;
1050
+ C() pre(b) // error
1051
+ pre(&this->b) // OK
1052
+ pre(sizeof(b) > 0); // OK, b is not potentially evaluated.
1053
+ };
1054
+ ```
1055
+
1056
+ — *end example*]
1057
+
1058
  If an *id-expression* E denotes a member M of an anonymous union
1059
  [[class.union.anon]] U:
1060
 
1061
  - If U is a non-static data member, E refers to M as a member of the
1062
+ lookup context of the terminal name of E (after any implicit
1063
+ transformation to a class member access expression).
1064
+ \[*Example 2*: `o.x` is interpreted as `o.u.x`, where u names the
1065
  anonymous union member. — *end example*]
1066
  - Otherwise, E is interpreted as a class member access [[expr.ref]] that
1067
  designates the member subobject M of the anonymous union variable for
1068
+ U. \[*Note 3*: Under this interpretation, E no longer denotes a
1069
+ non-static data member. — *end note*] \[*Example 3*: `N::x` is
1070
  interpreted as `N::u.x`, where u names the anonymous union
1071
  variable. — *end example*]
1072
 
1073
+ An *id-expression* or *splice-expression* that designates a non-static
1074
+ data member or implicit object member function of a class can only be
1075
+ used:
1076
 
1077
+ - as part of a class member access (after any implicit transformation
1078
+ (see above)) in which the object expression refers to the member’s
1079
+ class or a class derived from that class, or
1080
  - to form a pointer to member [[expr.unary.op]], or
1081
+ - if that *id-expression* or *splice-expression* designates a non-static
1082
+ data member and it appears in an unevaluated operand.
1083
+ \[*Example 4*:
1084
  ``` cpp
1085
  struct S {
1086
  int m;
1087
  };
1088
  int i = sizeof(S::m); // OK
1089
  int j = sizeof(S::m + 42); // OK
1090
+ int S::*k = &[:^^S::m:]; // OK
1091
  ```
1092
 
1093
  — *end example*]
1094
 
1095
  For an *id-expression* that denotes an overload set, overload resolution
1096
  is performed to select a unique function [[over.match]], [[over.over]].
1097
 
1098
+ [*Note 4*:
1099
 
1100
  A program cannot refer to a function with a trailing *requires-clause*
1101
  whose *constraint-expression* is not satisfied, because such functions
1102
  are never selected by overload resolution.
1103
 
1104
+ [*Example 5*:
1105
 
1106
  ``` cpp
1107
  template<typename T> struct A {
1108
  static void f(int) requires false;
1109
  };
 
1114
  decltype(A<int>::f)* p2 = nullptr; // error: the type decltype(A<int>::f) is invalid
1115
  }
1116
  ```
1117
 
1118
  In each case, the constraints of `f` are not satisfied. In the
1119
+ declaration of `p2`, those constraints need to be satisfied even though
1120
+ `f` is an unevaluated operand [[term.unevaluated.operand]].
1121
 
1122
  — *end example*]
1123
 
1124
  — *end note*]
1125
 
 
1130
  identifier
1131
  operator-function-id
1132
  conversion-function-id
1133
  literal-operator-id
1134
  '~' type-name
1135
+ '~' computed-type-specifier
1136
  template-id
1137
  ```
1138
 
1139
  An *identifier* is only an *id-expression* if it has been suitably
1140
+ declared [[dcl]] or if it appears as part of a *declarator-id*
1141
+ [[dcl.decl]].
 
1142
 
1143
  [*Note 1*: For *operator-function-id*s, see  [[over.oper]]; for
1144
  *conversion-function-id*s, see  [[class.conv.fct]]; for
1145
  *literal-operator-id*s, see  [[over.literal]]; for *template-id*s, see 
1146
+ [[temp.names]]. A *type-name* or *computed-type-specifier* prefixed by
1147
+ `~` denotes the destructor of the type so named; see 
1148
+ [[expr.prim.id.dtor]]. *end note*]
 
 
1149
 
1150
  A *component name* of an *unqualified-id* U is
1151
 
1152
  - U if it is a name or
1153
  - the component name of the *template-id* or *type-name* of U, if any.
 
1158
 
1159
  The *terminal name* of a construct is the component name of that
1160
  construct that appears lexically last.
1161
 
1162
  The result is the entity denoted by the *unqualified-id*
1163
+ [[basic.lookup.unqual]].
1164
+
1165
+ If
1166
+
1167
+ - the *unqualified-id* appears in a *lambda-expression* at program point
1168
+ P,
1169
+ - the entity is a local entity [[basic.pre]] or a variable declared by
1170
+ an *init-capture* [[expr.prim.lambda.capture]],
1171
+ - naming the entity within the *compound-statement* of the innermost
1172
+ enclosing *lambda-expression* of P, but not in an unevaluated operand,
1173
+ would refer to an entity captured by copy in some intervening
1174
+ *lambda-expression*, and
1175
+ - P is in the function parameter scope, but not the
1176
+ *parameter-declaration-clause*, of the innermost such
1177
+ *lambda-expression* E,
1178
+
1179
+ then the type of the expression is the type of a class member access
1180
+ expression [[expr.ref]] naming the non-static data member that would be
1181
+ declared for such a capture in the object parameter [[dcl.fct]] of the
1182
+ function call operator of E.
1183
+
1184
+ [*Note 3*: If E is not declared `mutable`, the type of such an
1185
+ identifier will typically be `const` qualified. *end note*]
1186
+
1187
+ Otherwise, if the *unqualified-id* names a coroutine parameter, the type
1188
+ of the expression is that of the copy of the parameter
1189
+ [[dcl.fct.def.coroutine]], and the result is that copy.
1190
+
1191
+ Otherwise, if the *unqualified-id* names a result binding
1192
+ [[dcl.contract.res]] attached to a function with return type `U`,
1193
+
1194
+ - if `U` is “reference to `T`”, then the type of the expression is
1195
+ `const T`;
1196
+ - otherwise, the type of the expression is `const U`.
1197
+
1198
+ Otherwise, if the *unqualified-id* appears in the predicate of a
1199
+ contract assertion C [[basic.contract]] and the entity is
1200
+
1201
+ - a variable declared outside of C of object type `T`,
1202
+ - a variable or template parameter declared outside of C of type
1203
+ “reference to `T`”, or
1204
+ - a structured binding of type `T` whose corresponding variable is
1205
+ declared outside of C,
1206
+
1207
+ then the type of the expression is `const` `T`.
1208
+
1209
+ [*Example 1*:
1210
+
1211
+ ``` cpp
1212
+ int n = 0;
1213
+ struct X { bool m(); };
1214
+
1215
+ struct Y {
1216
+ int z = 0;
1217
+
1218
+ void f(int i, int* p, int& r, X x, X* px)
1219
+ pre (++n) // error: attempting to modify const lvalue
1220
+ pre (++i) // error: attempting to modify const lvalue
1221
+ pre (++(*p)) // OK
1222
+ pre (++r) // error: attempting to modify const lvalue
1223
+ pre (x.m()) // error: calling non-const member function
1224
+ pre (px->m()) // OK
1225
+ pre ([=,&i,*this] mutable {
1226
+ ++n; // error: attempting to modify const lvalue
1227
+ ++i; // error: attempting to modify const lvalue
1228
+ ++p; // OK, refers to member of closure type
1229
+ ++r; // OK, refers to non-reference member of closure type
1230
+ ++this->z; // OK, captured *this
1231
+ ++z; // OK, captured *this
1232
+ int j = 17;
1233
+ [&]{
1234
+ int k = 34;
1235
+ ++i; // error: attempting to modify const lvalue
1236
+ ++j; // OK
1237
+ ++k; // OK
1238
+ }();
1239
+ return true;
1240
+ }());
1241
+
1242
+ template <int N, int& R, int* P>
1243
+ void g()
1244
+ pre(++N) // error: attempting to modify prvalue
1245
+ pre(++R) // error: attempting to modify const lvalue
1246
+ pre(++(*P)); // OK
1247
+
1248
+ int h()
1249
+ post(r : ++r) // error: attempting to modify const lvalue
1250
+ post(r: [=] mutable {
1251
+ ++r; // OK, refers to member of closure type
1252
+ return true;
1253
+ }());
1254
+
1255
+ int& k()
1256
+ post(r : ++r); // error: attempting to modify const lvalue
1257
+ };
1258
+ ```
1259
+
1260
+ — *end example*]
1261
+
1262
+ Otherwise, if the entity is a template parameter object for a template
1263
  parameter of type `T` [[temp.param]], the type of the expression is
1264
+ `const T`.
1265
 
1266
+ In all other cases, the type of the expression is the type of the
1267
+ entity.
1268
+
1269
+ [*Note 4*: The type will be adjusted as described in [[expr.type]] if
1270
  it is cv-qualified or is a reference type. — *end note*]
1271
 
1272
  The expression is an xvalue if it is move-eligible (see below); an
1273
  lvalue if the entity is a function, variable, structured binding
1274
+ [[dcl.struct.bind]], result binding [[dcl.contract.res]], data member,
1275
+ or template parameter object; and a prvalue otherwise [[basic.lval]]; it
1276
+ is a bit-field if the identifier designates a bit-field.
1277
 
1278
+ If an *id-expression* E appears in the predicate of a function contract
1279
+ assertion attached to a function *f* and denotes a function parameter of
1280
+ *f* and the implementation introduces any temporary objects to hold the
1281
+ value of that parameter as specified in [[class.temporary]],
1282
+
1283
+ - if the contract assertion is a precondition assertion and the
1284
+ evaluation of the precondition assertion is sequenced before the
1285
+ initialization of the parameter object, E refers to the most recently
1286
+ initialized such temporary object, and
1287
+ - if the contract assertion is a postcondition assertion, it is
1288
+ unspecified whether E refers to one of the temporary objects or the
1289
+ parameter object; the choice is consistent within a single evaluation
1290
+ of a postcondition assertion.
1291
+
1292
+ If an *id-expression* E names a result binding in a postcondition
1293
+ assertion and the implementation introduces any temporary objects to
1294
+ hold the result object as specified in [[class.temporary]], and the
1295
+ postcondition assertion is sequenced before the initialization of the
1296
+ result object [[expr.call]], E refers to the most recently initialized
1297
+ such temporary object.
1298
+
1299
+ [*Example 2*:
1300
 
1301
  ``` cpp
1302
  void f() {
1303
  float x, &r = x;
1304
 
 
1325
  }
1326
  ```
1327
 
1328
  — *end example*]
1329
 
1330
+ An *implicitly movable entity* is a variable with automatic storage
1331
  duration that is either a non-volatile object or an rvalue reference to
1332
+ a non-volatile object type. An *id-expression* or *splice-expression*
1333
+ [[expr.prim.splice]] is *move-eligible* if
1334
 
1335
+ - it designates an implicitly movable entity,
1336
+ - it is the (possibly parenthesized) operand of a `return`
1337
+ [[stmt.return]] or `co_return` [[stmt.return.coroutine]] statement or
1338
+ of a *throw-expression* [[expr.throw]], and
1339
+ - each intervening scope between the declaration of the entity and the
1340
+ innermost enclosing scope of the expression is a block scope and, for
1341
+ a *throw-expression*, is not the block scope of a *try-block* or
1342
+ *function-try-block*.
 
 
 
 
1343
 
1344
  #### Qualified names <a id="expr.prim.id.qual">[[expr.prim.id.qual]]</a>
1345
 
1346
  ``` bnf
1347
  qualified-id:
 
1351
  ``` bnf
1352
  nested-name-specifier:
1353
  '::'
1354
  type-name '::'
1355
  namespace-name '::'
1356
+ computed-type-specifier '::'
1357
+ splice-scope-specifier '::'
1358
  nested-name-specifier identifier '::'
1359
  nested-name-specifier templateₒₚₜ simple-template-id '::'
1360
  ```
1361
 
1362
+ ``` bnf
1363
+ splice-scope-specifier:
1364
+ splice-specifier
1365
+ templateₒₚₜ splice-specialization-specifier
1366
+ ```
1367
+
1368
  The component names of a *qualified-id* are those of its
1369
  *nested-name-specifier* and *unqualified-id*. The component names of a
1370
  *nested-name-specifier* are its *identifier* (if any) and those of its
1371
  *type-name*, *namespace-name*, *simple-template-id*, and/or
1372
  *nested-name-specifier*.
1373
 
1374
+ A *splice-specifier* or *splice-specialization-specifier* that is not
1375
+ followed by `::` is never interpreted as part of a
1376
+ *splice-scope-specifier*. The keyword `template` may only be omitted
1377
+ from the form `\opt{template} splice-specialization-specifier ::` when
1378
+ the *splice-specialization-specifier* is preceded by `typename`.
1379
+
1380
+ [*Example 1*:
1381
+
1382
+ ``` cpp
1383
+ template<int V>
1384
+ struct TCls {
1385
+ static constexpr int s = V;
1386
+ using type = int;
1387
+ };
1388
+
1389
+ int v1 = [:^^TCls<1>:]::s;
1390
+ int v2 = template [:^^TCls:]<2>::s; // OK, template binds to splice-scope-specifier
1391
+ typename [:^^TCls:]<3>::type v3 = 3; // OK, typename binds to the qualified name
1392
+ template [:^^TCls:]<3>::type v4 = 4; // OK, template binds to the splice-scope-specifier
1393
+ typename template [:^^TCls:]<3>::type v5 = 5; // OK, same as v3
1394
+ [:^^TCls:]<3>::type v6 = 6; // error: unexpected <
1395
+ ```
1396
+
1397
+ — *end example*]
1398
+
1399
  A *nested-name-specifier* is *declarative* if it is part of
1400
 
1401
  - a *class-head-name*,
1402
  - an *enum-head-name*,
1403
  - a *qualified-id* that is the *id-expression* of a *declarator-id*, or
1404
  - a declarative *nested-name-specifier*.
1405
 
1406
  A declarative *nested-name-specifier* shall not have a
1407
+ *computed-type-specifier* or a *splice-scope-specifier*. A declaration
1408
+ that uses a declarative *nested-name-specifier* shall be a friend
1409
+ declaration or inhabit a scope that contains the entity being redeclared
1410
+ or specialized.
1411
 
1412
+ The entity designated by a *nested-name-specifier* is determined as
1413
+ follows:
1414
+
1415
+ - The *nested-name-specifier* `::` designates the global namespace.
1416
+ - A *nested-name-specifier* with a *computed-type-specifier* designates
1417
+ the same type designated by the *computed-type-specifier*, which shall
1418
+ be a class or enumeration type.
1419
+ - For a *nested-name-specifier* of the form `splice-specifier ::`, the
1420
+ *splice-specifier* shall designate a class or enumeration type or a
1421
+ namespace. The *nested-name-specifier* designates the same entity as
1422
+ the *splice-specifier*.
1423
+ - For a *nested-name-specifier* of the form
1424
+ `\opt{template} splice-specialization-specifier ::`, the
1425
+ *splice-specifier* of the *splice-specialization-specifier* shall
1426
+ designate a class template or an alias template T. Letting S be the
1427
+ specialization of T corresponding to the template argument list of the
1428
+ *splice-specialization-specifier*, S shall either be a class template
1429
+ specialization or an alias template specialization that denotes a
1430
+ class or enumeration type. The *nested-name-specifier* designates the
1431
+ underlying entity of S.
1432
+ - If a *nested-name-specifier* N is declarative and has a
1433
+ *simple-template-id* with a template argument list A that involves a
1434
  template parameter, let T be the template nominated by N without A. T
1435
  shall be a class template.
 
1436
  - If A is the template argument list [[temp.arg]] of the corresponding
1437
+ *template-head* H [[temp.mem]], N designates the primary template of
1438
+ T; H shall be equivalent to the *template-head* of T
1439
+ [[temp.over.link]].
1440
+ - Otherwise, N designates the partial specialization
1441
+ [[temp.spec.partial]] of T whose template argument list is
1442
+ equivalent to A [[temp.over.link]]; the program is ill-formed if no
1443
+ such partial specialization exists.
1444
+ - Any other *nested-name-specifier* designates the entity denotes by its
1445
+ *type-name*, *namespace-name*, *identifier*, or *simple-template-id*.
1446
+ If the *nested-name-specifier* is not declarative, the entity shall
1447
+ not be a template.
1448
 
1449
  A *qualified-id* shall not be of the form *nested-name-specifier*
1450
+ `template`ₒₚₜ `~` *computed-type-specifier* nor of the form
1451
+ *computed-type-specifier* `::` `~` *type-name*.
1452
 
1453
  The result of a *qualified-id* Q is the entity it denotes
1454
+ [[basic.lookup.qual]].
1455
+
1456
+ If Q appears in the predicate of a contract assertion C
1457
+ [[basic.contract]] and the entity is
1458
+
1459
+ - a variable declared outside of C of object type `T`,
1460
+ - a variable declared outside of C of type “reference to `T`”, or
1461
+ - a structured binding of type `T` whose corresponding variable is
1462
+ declared outside of C,
1463
+
1464
+ then the type of the expression is `const` `T`.
1465
+
1466
+ Otherwise, the type of the expression is the type of the result.
1467
+
1468
+ The result is an lvalue if the member is
1469
 
1470
  - a function other than a non-static member function,
1471
  - a non-static member function if Q is the operand of a unary `&`
1472
  operator,
1473
  - a variable,
1474
  - a structured binding [[dcl.struct.bind]], or
1475
  - a data member,
1476
 
1477
  and a prvalue otherwise.
1478
 
1479
+ #### Pack indexing expression <a id="expr.prim.pack.index">[[expr.prim.pack.index]]</a>
1480
+
1481
+ ``` bnf
1482
+ pack-index-expression:
1483
+ id-expression '...' '[' constant-expression ']'
1484
+ ```
1485
+
1486
+ The *id-expression* P in a *pack-index-expression* shall be an
1487
+ *identifier* that denotes a pack.
1488
+
1489
+ The *constant-expression* shall be a converted constant expression
1490
+ [[expr.const]] of type `std::size_t` whose value V, termed the index, is
1491
+ such that 0 ≤ V < `sizeof...($P$)`.
1492
+
1493
+ A *pack-index-expression* is a pack expansion [[temp.variadic]].
1494
+
1495
+ [*Note 1*: A *pack-index-expression* denotes the Vᵗʰ element of the
1496
+ pack. — *end note*]
1497
+
1498
  #### Destruction <a id="expr.prim.id.dtor">[[expr.prim.id.dtor]]</a>
1499
 
1500
  An *id-expression* that denotes the destructor of a type `T` names the
1501
  destructor of `T` if `T` is a class type [[class.dtor]], otherwise the
1502
  *id-expression* is said to name a *pseudo-destructor*.
 
1543
  ```
1544
 
1545
  ``` bnf
1546
  lambda-declarator:
1547
  lambda-specifier-seq noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ trailing-return-typeₒₚₜ
1548
+ function-contract-specifier-seqₒₚₜ
1549
+ noexcept-specifier attribute-specifier-seqₒₚₜ trailing-return-typeₒₚₜ function-contract-specifier-seqₒₚₜ
1550
+ trailing-return-typeₒₚₜ function-contract-specifier-seqₒₚₜ
1551
  '(' parameter-declaration-clause ')' lambda-specifier-seqₒₚₜ noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ
1552
+ trailing-return-typeₒₚₜ requires-clauseₒₚₜ function-contract-specifier-seqₒₚₜ
1553
  ```
1554
 
1555
  ``` bnf
1556
  lambda-specifier:
1557
  consteval
 
1560
  static
1561
  ```
1562
 
1563
  ``` bnf
1564
  lambda-specifier-seq:
1565
+ lambda-specifier lambda-specifier-seqₒₚₜ
 
1566
  ```
1567
 
1568
  A *lambda-expression* provides a concise way to create a simple function
1569
  object.
1570
 
 
1590
  *attribute-specifier-seq*, which collides with the
1591
  *attribute-specifier-seq* in *lambda-expression*. In such cases, any
1592
  attributes are treated as *attribute-specifier-seq* in
1593
  *lambda-expression*.
1594
 
1595
+ [*Note 2*:
1596
+
1597
+ Such ambiguous cases cannot have valid semantics because the constraint
1598
+ expression would not have type `bool`.
1599
+
1600
+ [*Example 2*:
1601
+
1602
+ ``` cpp
1603
+ auto x = []<class T> requires T::operator int [[some_attribute]] (int) { }
1604
+ ```
1605
+
1606
+ — *end example*]
1607
+
1608
+ — *end note*]
1609
 
1610
  A *lambda-specifier-seq* shall contain at most one of each
1611
  *lambda-specifier* and shall not contain both `constexpr` and
1612
  `consteval`. If the *lambda-declarator* contains an explicit object
1613
  parameter [[dcl.fct]], then no *lambda-specifier* in the
 
1617
  *lambda-capture*.
1618
 
1619
  [*Note 3*: The trailing *requires-clause* is described in
1620
  [[dcl.decl]]. — *end note*]
1621
 
1622
+ A *lambda-expression*'s *parameter-declaration-clause* is the
1623
+ *parameter-declaration-clause* of the *lambda-expression*'s
1624
+ *lambda-declarator*, if any, or empty otherwise. If the
1625
+ *lambda-declarator* does not include a *trailing-return-type*, it is
1626
+ considered to be `-> auto`.
1627
 
1628
  [*Note 4*: In that case, the return type is deduced from `return`
1629
  statements as described in [[dcl.spec.auto]]. — *end note*]
1630
 
1631
+ [*Example 3*:
1632
 
1633
  ``` cpp
1634
  auto x1 = [](int i) { return i; }; // OK, return type is int
1635
  auto x2 = []{ return { 1, 2 }; }; // error: deducing return type from braced-init-list
1636
  int j;
 
1641
 
1642
  A lambda is a *generic lambda* if the *lambda-expression* has any
1643
  generic parameter type placeholders [[dcl.spec.auto]], or if the lambda
1644
  has a *template-parameter-list*.
1645
 
1646
+ [*Example 4*:
1647
 
1648
  ``` cpp
1649
+ auto x = [](int i, auto a) { return i; }; // OK, a generic lambda
1650
+ auto y = [](this auto self, int i) { return i; }; // OK, a generic lambda
1651
+ auto z = []<class T>(int i) { return i; }; // OK, a generic lambda
1652
  ```
1653
 
1654
  — *end example*]
1655
 
1656
  #### Closure types <a id="expr.prim.lambda.closure">[[expr.prim.lambda.closure]]</a>
1657
 
1658
  The type of a *lambda-expression* (which is also the type of the closure
1659
  object) is a unique, unnamed non-union class type, called the *closure
1660
  type*, whose properties are described below.
1661
 
1662
+ The closure type is incomplete until the end of its corresponding
1663
+ *compound-statement*.
1664
+
1665
  The closure type is declared in the smallest block scope, class scope,
1666
  or namespace scope that contains the corresponding *lambda-expression*.
1667
 
1668
  [*Note 1*: This determines the set of namespaces and classes associated
1669
  with the closure type [[basic.lookup.argdep]]. The parameter types of a
1670
  *lambda-declarator* do not affect these associated namespaces and
1671
  classes. — *end note*]
1672
 
1673
+ The closure type is not an aggregate type [[dcl.init.aggr]]; it is a
1674
+ structural type [[term.structural.type]] if and only if the lambda has
1675
+ no *lambda-capture*. An implementation may define the closure type
1676
+ differently from what is described below provided this does not alter
1677
+ the observable behavior of the program other than by changing:
1678
 
1679
  - the size and/or alignment of the closure type,
1680
+ - whether the closure type is trivially copyable [[class.prop]],
1681
+ - whether the closure type is trivially relocatable [[class.prop]],
1682
+ - whether the closure type is replaceable [[class.prop]], or
1683
  - whether the closure type is a standard-layout class [[class.prop]].
1684
 
1685
  An implementation shall not add members of rvalue reference type to the
1686
  closure type.
1687
 
1688
  The closure type for a *lambda-expression* has a public inline function
1689
  call operator (for a non-generic lambda) or function call operator
1690
  template (for a generic lambda) [[over.call]] whose parameters and
1691
+ return type are those of the *lambda-expression*'s
1692
  *parameter-declaration-clause* and *trailing-return-type* respectively,
1693
  and whose *template-parameter-list* consists of the specified
1694
+ *template-parameter-list*, if any. The function call operator or the
1695
+ function call operator template are direct members of the closure type.
1696
+ The *requires-clause* of the function call operator template is the
1697
+ *requires-clause* immediately following
1698
  `<` *template-parameter-list* `>`, if any. The trailing
1699
  *requires-clause* of the function call operator or operator template is
1700
  the *requires-clause* of the *lambda-declarator*, if any.
1701
 
1702
  [*Note 2*: The function call operator template for a generic lambda can
 
1733
  Given a lambda with a *lambda-capture*, the type of the explicit object
1734
  parameter, if any, of the lambda’s function call operator (possibly
1735
  instantiated from a function call operator template) shall be either:
1736
 
1737
  - the closure type,
1738
+ - a class type publicly and unambiguously derived from the closure type,
1739
+ or
1740
  - a reference to a possibly cv-qualified such type.
1741
 
1742
  [*Example 2*:
1743
 
1744
  ``` cpp
 
1762
  `static`. Otherwise, it is a non-static member function or member
1763
  function template [[class.mfct.non.static]] that is declared `const`
1764
  [[class.mfct.non.static]] if and only if the *lambda-expression*’s
1765
  *parameter-declaration-clause* is not followed by `mutable` and the
1766
  *lambda-declarator* does not contain an explicit object parameter. It is
1767
+ neither virtual nor declared `volatile`. Any *noexcept-specifier* or
1768
+ *function-contract-specifier* [[dcl.contract.func]] specified on a
1769
+ *lambda-expression* applies to the corresponding function call operator
1770
+ or operator template. An *attribute-specifier-seq* in a
1771
  *lambda-declarator* appertains to the type of the corresponding function
1772
  call operator or operator template. An *attribute-specifier-seq* in a
1773
  *lambda-expression* preceding a *lambda-declarator* appertains to the
1774
  corresponding function call operator or operator template. The function
1775
  call operator or any given operator template specialization is a
 
1848
 
1849
  — *end example*]
1850
 
1851
  — *end note*]
1852
 
1853
+ If all potential references to a local entity implicitly captured by a
1854
+ *lambda-expression* L occur within the function contract assertions
1855
+ [[dcl.contract.func]] of the call operator or operator template of L or
1856
+ within *assertion-statement*s [[stmt.contract.assert]] within the body
1857
+ of L, the program is ill-formed.
1858
+
1859
+ [*Note 4*: Adding a contract assertion to an existing C++ program
1860
+ cannot cause additional captures. — *end note*]
1861
+
1862
+ [*Example 6*:
1863
+
1864
+ ``` cpp
1865
+ static int i = 0;
1866
+
1867
+ void test() {
1868
+ auto f1 = [=] pre(i > 0) {}; // OK, no local entities are captured.
1869
+
1870
+ int i = 1;
1871
+ auto f2 = [=] pre(i > 0) {}; // error: cannot implicitly capture i here
1872
+ auto f3 = [i] pre(i > 0) {}; // OK, i is captured explicitly.
1873
+
1874
+ auto f4 = [=] {
1875
+ contract_assert(i > 0); // error: cannot implicitly capture i here
1876
+ };
1877
+
1878
+ auto f5 = [=] {
1879
+ contract_assert(i > 0); // OK, i is referenced elsewhere.
1880
+ (void)i;
1881
+ };
1882
+
1883
+ auto f6 = [=] pre( // #1
1884
+ []{
1885
+ bool x = true;
1886
+ return [=]{ return x; }(); // OK, #1 captures nothing.
1887
+ }()) {};
1888
+
1889
+ bool y = true;
1890
+ auto f7 = [=] pre([=]{ return y; }()); // error: outer capture of y is invalid.
1891
+ }
1892
+ ```
1893
+
1894
+ — *end example*]
1895
+
1896
  The closure type for a non-generic *lambda-expression* with no
1897
+ *lambda-capture* and no explicit object parameter [[dcl.fct]] whose
1898
+ constraints (if any) are satisfied has a conversion function to pointer
1899
+ to function with C++ language linkage [[dcl.link]] having the same
1900
+ parameter and return types as the closure type’s function call operator.
1901
+ The conversion is to “pointer to `noexcept` function” if the function
1902
+ call operator has a non-throwing exception specification. If the
1903
+ function call operator is a static member function, then the value
1904
+ returned by this conversion function is a pointer to the function call
1905
+ operator. Otherwise, the value returned by this conversion function is a
1906
+ pointer to a function `F` that, when invoked, has the same effect as
1907
+ invoking the closure type’s function call operator on a
1908
+ default-constructed instance of the closure type. `F` is a constexpr
1909
+ function if the function call operator is a constexpr function and is an
1910
+ immediate function if the function call operator is an immediate
1911
+ function.
1912
 
1913
+ For a generic lambda with no *lambda-capture* and no explicit object
1914
+ parameter [[dcl.fct]], the closure type has a conversion function
1915
+ template to pointer to function. The conversion function template has
1916
+ the same invented template parameter list, and the pointer to function
1917
+ has the same parameter types, as the function call operator template.
1918
+ The return type of the pointer to function shall behave as if it were a
1919
+ *decltype-specifier* denoting the return type of the corresponding
1920
+ function call operator template specialization.
1921
 
1922
+ [*Note 5*:
1923
 
1924
  If the generic lambda has no *trailing-return-type* or the
1925
  *trailing-return-type* contains a placeholder type, return type
1926
  deduction of the corresponding function call operator template
1927
  specialization has to be done. The corresponding specialization is that
 
1953
  };
1954
  ```
1955
 
1956
  — *end note*]
1957
 
1958
+ [*Example 7*:
1959
 
1960
  ``` cpp
1961
  void f1(int (*)(int)) { }
1962
  void f2(char (*)(int)) { }
1963
 
 
1977
 
1978
  — *end example*]
1979
 
1980
  If the function call operator template is a static member function
1981
  template, then the value returned by any given specialization of this
1982
+ conversion function template is a pointer to the corresponding function
1983
+ call operator template specialization. Otherwise, the value returned by
1984
+ any given specialization of this conversion function template is a
1985
+ pointer to a function `F` that, when invoked, has the same effect as
1986
+ invoking the generic lambda’s corresponding function call operator
1987
+ template specialization on a default-constructed instance of the closure
1988
+ type. `F` is a constexpr function if the corresponding specialization is
1989
+ a constexpr function and `F` is an immediate function if the function
1990
+ call operator template specialization is an immediate function.
 
1991
 
1992
+ [*Note 6*: This will result in the implicit instantiation of the
1993
  generic lambda’s body. The instantiated generic lambda’s return type and
1994
+ parameter types need to match the return type and parameter types of the
1995
+ pointer to function. — *end note*]
1996
 
1997
+ [*Example 8*:
1998
 
1999
  ``` cpp
2000
  auto GL = [](auto a) { std::cout << a; return a; };
2001
  int (*GL_int)(int) = GL; // OK, through conversion function template
2002
  GL_int(3); // OK, same as GL(3)
 
2006
 
2007
  The conversion function or conversion function template is public,
2008
  constexpr, non-virtual, non-explicit, const, and has a non-throwing
2009
  exception specification [[except.spec]].
2010
 
2011
+ [*Example 9*:
2012
 
2013
  ``` cpp
2014
  auto Fwd = [](int (*fp)(int), auto a) { return fp(a); };
2015
  auto C = [](auto a) { return a; };
2016
 
 
2025
 
2026
  The *lambda-expression*’s *compound-statement* yields the
2027
  *function-body* [[dcl.fct.def]] of the function call operator, but it is
2028
  not within the scope of the closure type.
2029
 
2030
+ [*Example 10*:
2031
 
2032
  ``` cpp
2033
  struct S1 {
2034
  int x, y;
2035
  int operator()(int);
 
2042
  };
2043
  ```
2044
 
2045
  — *end example*]
2046
 
2047
+ Unless the *compound-statement* is that of a
2048
+ *consteval-block-declaration* [[dcl.pre]], a variable `__func__` is
2049
+ implicitly defined at the beginning of the *compound-statement* of the
2050
+ *lambda-expression*, with semantics as described in 
2051
+ [[dcl.fct.def.general]].
2052
 
2053
  The closure type associated with a *lambda-expression* has no default
2054
  constructor if the *lambda-expression* has a *lambda-capture* and a
2055
  defaulted default constructor otherwise. It has a defaulted copy
2056
  constructor and a defaulted move constructor [[class.copy.ctor]]. It has
2057
  a deleted copy assignment operator if the *lambda-expression* has a
2058
  *lambda-capture* and defaulted copy and move assignment operators
2059
  otherwise [[class.copy.assign]].
2060
 
2061
+ [*Note 7*: These special member functions are implicitly defined as
2062
  usual, which can result in them being defined as deleted. — *end note*]
2063
 
2064
  The closure type associated with a *lambda-expression* has an
2065
  implicitly-declared destructor [[class.dtor]].
2066
 
 
2098
  ``` bnf
2099
  simple-capture:
2100
  identifier '...'ₒₚₜ
2101
  '&' identifier '...'ₒₚₜ
2102
  this
2103
+ '*' this
2104
  ```
2105
 
2106
  ``` bnf
2107
  init-capture:
2108
  '...'ₒₚₜ identifier initializer
2109
  '&' '...'ₒₚₜ identifier initializer
2110
  ```
2111
 
2112
  The body of a *lambda-expression* may refer to local entities of
2113
+ enclosing scopes by capturing those entities, as described below.
2114
 
2115
  If a *lambda-capture* includes a *capture-default* that is `&`, no
2116
  identifier in a *simple-capture* of that *lambda-capture* shall be
2117
  preceded by `&`. If a *lambda-capture* includes a *capture-default* that
2118
  is `=`, each *simple-capture* of that *lambda-capture* shall be of the
2119
  form “`&` *identifier* `...`ₒₚₜ ”, “`this`”, or “`* this`”.
2120
 
2121
  [*Note 1*: The form `[&,this]` is redundant but accepted for
2122
+ compatibility with C++14. — *end note*]
2123
 
2124
  Ignoring appearances in *initializer*s of *init-capture*s, an identifier
2125
  or `this` shall not appear more than once in a *lambda-capture*.
2126
 
2127
  [*Example 1*:
 
2140
  ```
2141
 
2142
  — *end example*]
2143
 
2144
  A *lambda-expression* shall not have a *capture-default* or
2145
+ *simple-capture* in its *lambda-introducer* unless
2146
+
2147
+ - its innermost enclosing scope is a block scope [[basic.scope.block]],
2148
+ - it appears within a default member initializer and its innermost
2149
+ enclosing scope is the corresponding class scope
2150
+ [[basic.scope.class]], or
2151
+ - it appears within a contract assertion and its innermost enclosing
2152
+ scope is the corresponding contract-assertion scope
2153
+ [[basic.scope.contract]].
2154
 
2155
  The *identifier* in a *simple-capture* shall denote a local entity
2156
  [[basic.lookup.unqual]], [[basic.pre]]. The *simple-capture*s `this` and
2157
  `* this` denote the local entity `*this`. An entity that is designated
2158
  by a *simple-capture* is said to be *explicitly captured*.
 
2370
  An entity is *captured by copy* if
2371
 
2372
  - it is implicitly captured, the *capture-default* is `=`, and the
2373
  captured entity is not `*this`, or
2374
  - it is explicitly captured with a capture that is not of the form
2375
+ `this`, `&` *identifier* `...`ₒₚₜ , or `&` `...`ₒₚₜ *identifier*
2376
+ *initializer*.
2377
 
2378
  For each entity captured by copy, an unnamed non-static data member is
2379
  declared in the closure type. The declaration order of these members is
2380
  unspecified. The type of such a data member is the referenced type if
2381
  the entity is a reference to an object, an lvalue reference to the
 
2402
  ``` cpp
2403
  void f(const int*);
2404
  void g() {
2405
  const int N = 10;
2406
  [=] {
2407
+ int arr[N]; // OK, not an odr-use, refers to variable with automatic storage duration
2408
  f(&N); // OK, causes N to be captured; &N points to
2409
  // the corresponding member of the closure type
2410
  };
2411
  }
2412
  ```
 
2573
  }
2574
  ```
2575
 
2576
  — *end example*]
2577
 
2578
+ A fold expression is a pack expansion.
2579
+
2580
  ### Requires expressions <a id="expr.prim.req">[[expr.prim.req]]</a>
2581
 
2582
  #### General <a id="expr.prim.req.general">[[expr.prim.req.general]]</a>
2583
 
2584
  A *requires-expression* provides a concise way to express requirements
 
2600
  '{' requirement-seq '}'
2601
  ```
2602
 
2603
  ``` bnf
2604
  requirement-seq:
2605
+ requirement requirement-seqₒₚₜ
 
2606
  ```
2607
 
2608
  ``` bnf
2609
  requirement:
2610
  simple-requirement
 
2612
  compound-requirement
2613
  nested-requirement
2614
  ```
2615
 
2616
  A *requires-expression* is a prvalue of type `bool` whose value is
2617
+ described below.
 
2618
 
2619
  [*Example 1*:
2620
 
2621
  A common use of *requires-expression*s is to define requirements in
2622
  concepts such as the one below:
 
2643
  introduces the *requires-expression*.
2644
 
2645
  — *end example*]
2646
 
2647
  A *requires-expression* may introduce local parameters using a
2648
+ *parameter-declaration-clause*. A local parameter of a
2649
+ *requires-expression* shall not have a default argument. The type of
2650
+ such a parameter is determined as specified for a function parameter in 
2651
+ [[dcl.fct]]. These parameters have no linkage, storage, or lifetime;
2652
+ they are only used as notation for the purpose of defining
2653
+ *requirement*s. The *parameter-declaration-clause* of a
2654
+ *requirement-parameter-list* shall not terminate with an ellipsis.
2655
 
2656
  [*Example 2*:
2657
 
2658
  ``` cpp
2659
  template<typename T>
2660
  concept C = requires(T t, ...) { // error: terminates with an ellipsis
2661
  t;
2662
  };
2663
+ template<typename T>
2664
+ concept C2 = requires(T p[2]) {
2665
+ (decltype(p))nullptr; // OK, p has type ``pointer to T''
2666
+ };
2667
  ```
2668
 
2669
  — *end example*]
2670
 
2671
+ The substitution of template arguments into a *requires-expression* can
2672
+ result in the formation of invalid types or expressions in the immediate
2673
+ context of its *requirement*s [[temp.deduct.general]] or the violation
2674
+ of the semantic constraints of those *requirement*s. In such cases, the
2675
+ *requires-expression* evaluates to `false`; it does not cause the
2676
+ program to be ill-formed. The substitution and semantic constraint
2677
+ checking proceeds in lexical order and stops when a condition that
2678
+ determines the result of the *requires-expression* is encountered. If
2679
+ substitution (if any) and semantic constraint checking succeed, the
2680
+ *requires-expression* evaluates to `true`.
2681
 
2682
  [*Note 1*: If a *requires-expression* contains invalid types or
2683
  expressions in its *requirement*s, and it does not appear within the
2684
  declaration of a templated entity, then the program is
2685
  ill-formed. — *end note*]
 
2691
  [*Example 3*:
2692
 
2693
  ``` cpp
2694
  template<typename T> concept C =
2695
  requires {
2696
+ new decltype((void)T{}); // ill-formed, no diagnostic required
2697
  };
2698
  ```
2699
 
2700
  — *end example*]
2701
 
 
2704
  ``` bnf
2705
  simple-requirement:
2706
  expression ';'
2707
  ```
2708
 
2709
+ A *simple-requirement* asserts the validity of an *expression*. The
2710
+ *expression* is an unevaluated operand.
2711
 
2712
  [*Note 1*: The enclosing *requires-expression* will evaluate to `false`
2713
+ if substitution of template arguments into the *expression*
2714
+ fails. *end note*]
 
2715
 
2716
  [*Example 1*:
2717
 
2718
  ``` cpp
2719
  template<typename T> concept C =
 
2733
  #### Type requirements <a id="expr.prim.req.type">[[expr.prim.req.type]]</a>
2734
 
2735
  ``` bnf
2736
  type-requirement:
2737
  typename nested-name-specifierₒₚₜ type-name ';'
2738
+ typename splice-specifier
2739
+ typename splice-specialization-specifier
2740
  ```
2741
 
2742
+ A *type-requirement* asserts the validity of a type. The component names
2743
+ of a *type-requirement* are those of its *nested-name-specifier* (if
2744
+ any) and *type-name* (if any).
2745
 
2746
  [*Note 1*: The enclosing *requires-expression* will evaluate to `false`
2747
  if substitution of template arguments fails. — *end note*]
2748
 
2749
  [*Example 1*:
 
2752
  template<typename T, typename T::type = 0> struct S;
2753
  template<typename T> using Ref = T&;
2754
 
2755
  template<typename T> concept C = requires {
2756
  typename T::inner; // required nested member name
2757
+ typename S<T>; // required valid[temp.names] template-id; fails if T::type does not exist as a type
2758
+ // to which 0 can be implicitly converted
2759
  typename Ref<T>; // required alias template substitution, fails if T is void
2760
+ typename [:T::r1:]; // fails if T::r1 is not a reflection of a type
2761
+ typename [:T::r2:]<int>; // fails if T::r2 is not a reflection of a template Z for which Z<int> is a type
2762
  };
2763
  ```
2764
 
2765
  — *end example*]
2766
 
 
2777
  ``` bnf
2778
  return-type-requirement:
2779
  '->' type-constraint
2780
  ```
2781
 
2782
+ A *compound-requirement* asserts properties of the *expression* E. The
2783
+ *expression* is an unevaluated operand. Substitution of template
2784
+ arguments (if any) and verification of semantic properties proceed in
2785
+ the following order:
2786
 
2787
  - Substitution of template arguments (if any) into the *expression* is
2788
  performed.
2789
  - If the `noexcept` specifier is present, E shall not be a
2790
  potentially-throwing expression [[except.spec]].
 
2874
  `D<T>` is satisfied if `sizeof(decltype (+t)) == 1`
2875
  [[temp.constr.atomic]].
2876
 
2877
  — *end example*]
2878
 
2879
+ ### Expression splicing <a id="expr.prim.splice">[[expr.prim.splice]]</a>
2880
+
2881
+ ``` bnf
2882
+ splice-expression:
2883
+ splice-specifier
2884
+ template splice-specifier
2885
+ template splice-specialization-specifier
2886
+ ```
2887
+
2888
+ A *splice-specifier* or *splice-specialization-specifier* immediately
2889
+ followed by `::` or preceded by `typename` is never interpreted as part
2890
+ of a *splice-expression*.
2891
+
2892
+ [*Example 1*:
2893
+
2894
+ ``` cpp
2895
+ struct S { static constexpr int a = 1; };
2896
+ template<typename> struct TCls { static constexpr int b = 2; };
2897
+
2898
+ constexpr int c = [:^^S:]::a; // OK, [:^^ S:] is not an expression
2899
+ constexpr int d = template [:^^TCls:]<int>::b; // OK, template [:^^ TCls:]<int> is not an expression
2900
+ template<auto V> constexpr int e = [:V:]; // OK
2901
+ constexpr int f = template [:^^e:]<^^S::a>; // OK
2902
+
2903
+ constexpr auto g = typename [:^^int:](42); // OK, typename [:^^ int:] is a splice-type-specifier
2904
+
2905
+ constexpr auto h = ^^g;
2906
+ constexpr auto i = e<[:^^h:]>; // error: unparenthesized splice-expression used as template argument
2907
+ constexpr auto j = e<([:^^h:])>; // OK
2908
+ ```
2909
+
2910
+ — *end example*]
2911
+
2912
+ For a *splice-expression* of the form *splice-specifier*, let S be the
2913
+ construct designated by *splice-specifier*.
2914
+
2915
+ - The expression is ill-formed if S is
2916
+ - a constructor,
2917
+ - a destructor,
2918
+ - an unnamed bit-field, or
2919
+ - a local entity [[basic.pre]] such that
2920
+ - there is a lambda scope that intervenes between the expression and
2921
+ the point at which S was introduced and
2922
+ - the expression would be potentially evaluated if the effect of any
2923
+ enclosing `typeid` expressions [[expr.typeid]] were ignored.
2924
+ - Otherwise, if S is a function F, the expression denotes an overload
2925
+ set containing all declarations of F that precede either the
2926
+ expression or the point immediately following the *class-specifier* of
2927
+ the outermost class for which the expression is in a complete-class
2928
+ context; overload resolution is performed
2929
+ [[over.match]], [[over.over]].
2930
+ - Otherwise, if S is an object or a non-static data member, the
2931
+ expression is an lvalue designating S. The expression has the same
2932
+ type as that of S, and is a bit-field if and only if S is a bit-field.
2933
+ \[*Note 1*: The implicit transformation whereby an *id-expression*
2934
+ denoting a non-static member becomes a class member access
2935
+ [[expr.prim.id]] does not apply to a
2936
+ *splice-expression*. — *end note*]
2937
+ - Otherwise, if S is a variable or a structured binding, S shall either
2938
+ have static or thread storage duration or shall inhabit a scope
2939
+ enclosing the expression. The expression is an lvalue referring to the
2940
+ object or function X associated with or referenced by S, has the same
2941
+ type as that of S, and is a bit-field if and only if X is a bit-field.
2942
+ \[*Note 2*: The type of a *splice-expression* designating a variable
2943
+ or structured binding of reference type will be adjusted to a
2944
+ non-reference type [[expr.type]]. — *end note*]
2945
+ - Otherwise, if S is a value or an enumerator, the expression is a
2946
+ prvalue that computes S and whose type is the same as that of S.
2947
+ - Otherwise, the expression is ill-formed.
2948
+
2949
+ For a *splice-expression* of the form `template splice-specifier`, the
2950
+ *splice-specifier* shall designate a function template T that is not a
2951
+ constructor template. The expression denotes an overload set containing
2952
+ all declarations of T that precede either the expression or the point
2953
+ immediately following the *class-specifier* of the outermost class for
2954
+ which the expression is in a complete-class context; overload resolution
2955
+ is performed.
2956
+
2957
+ [*Note 3*: During overload resolution, candidate function templates
2958
+ undergo template argument deduction and the resulting specializations
2959
+ are considered as candidate functions. — *end note*]
2960
+
2961
+ For a *splice-expression* of the form
2962
+ `template splice-specialization-specifier`, the *splice-specifier* of
2963
+ the *splice-specialization-specifier* shall designate a template T.
2964
+
2965
+ - If T is a function template, the expression denotes an overload set
2966
+ containing all declarations of T that precede either the expression or
2967
+ the point immediately following the *class-specifier* of the outermost
2968
+ class for which the expression is in a complete-class context;
2969
+ overload resolution is performed [[over.match]], [[over.over]].
2970
+ - Otherwise, if T is a variable template, let S be the specialization of
2971
+ T corresponding to the template argument list of the
2972
+ *splice-specialization-specifier*. The expression is an lvalue
2973
+ referring to the object associated with S and has the same type as
2974
+ that of S.
2975
+ - Otherwise, the expression is ill-formed.
2976
+
2977
+ [*Note 4*: Class members are accessible from any point when designated
2978
+ by *splice-expression*s [[class.access.base]]. A class member access
2979
+ expression [[expr.ref]] whose right operand is a *splice-expression* is
2980
+ ill-formed if the left operand (considered as a pointer) cannot be
2981
+ implicitly converted to a pointer to the designating class of the right
2982
+ operand. — *end note*]
2983
+
2984
  ## Compound expressions <a id="expr.compound">[[expr.compound]]</a>
2985
 
2986
  ### Postfix expressions <a id="expr.post">[[expr.post]]</a>
2987
 
2988
  #### General <a id="expr.post.general">[[expr.post.general]]</a>
 
2996
  postfix-expression '(' expression-listₒₚₜ ')'
2997
  simple-type-specifier '(' expression-listₒₚₜ ')'
2998
  typename-specifier '(' expression-listₒₚₜ ')'
2999
  simple-type-specifier braced-init-list
3000
  typename-specifier braced-init-list
3001
+ postfix-expression '.' templateₒₚₜ id-expression
3002
+ postfix-expression '.' splice-expression
3003
+ postfix-expression '->' templateₒₚₜ id-expression
3004
+ postfix-expression '->' splice-expression
3005
  postfix-expression '++'
3006
  postfix-expression '--'
3007
  dynamic_cast '<' type-id '>' '(' expression ')'
3008
  static_cast '<' type-id '>' '(' expression ')'
3009
  reinterpret_cast '<' type-id '>' '(' expression ')'
 
3026
 
3027
  A *subscript expression* is a postfix expression followed by square
3028
  brackets containing a possibly empty, comma-separated list of
3029
  *initializer-clause*s that constitute the arguments to the subscript
3030
  operator. The *postfix-expression* and the initialization of the object
3031
+ parameter [[dcl.fct]] of any applicable subscript operator function
3032
+ [[over.sub]] is sequenced before each expression in the
3033
+ *expression-list* and also before any default argument
3034
+ [[dcl.fct.default]]. The initialization of a non-object parameter of a
3035
+ subscript operator function `S`, including every associated value
3036
+ computation and side effect, is indeterminately sequenced with respect
3037
+ to that of any other non-object parameter of `S`.
3038
 
3039
  With the built-in subscript operator, an *expression-list* shall be
3040
  present, consisting of a single *assignment-expression*. One of the
3041
  expressions shall be a glvalue of type “array of `T`” or a prvalue of
3042
  type “pointer to `T`” and the other shall be a prvalue of unscoped
3043
  enumeration or integral type. The result is of type “`T`”. The type
3044
+ “`T`” shall be a completely-defined object type.[^10]
3045
 
3046
  The expression `E1[E2]` is identical (by definition) to `*((E1)+(E2))`,
3047
  except that in the case of an array operand, the result is an lvalue if
3048
  that operand is an lvalue and an xvalue otherwise.
3049
 
 
3056
 
3057
  A function call is a postfix expression followed by parentheses
3058
  containing a possibly empty, comma-separated list of
3059
  *initializer-clause*s which constitute the arguments to the function.
3060
 
3061
+ [*Note 1*: If the postfix expression is a function name, the
3062
+ appropriate function and the validity of the call are determined
3063
+ according to the rules in  [[over.match]]. — *end note*]
3064
 
3065
  The postfix expression shall have function type or function pointer
3066
  type. For a call to a non-member function or to a static member
3067
+ function, the postfix expression shall be either an lvalue that refers
3068
  to a function (in which case the function-to-pointer standard conversion
3069
+ [[conv.func]] is suppressed on the postfix expression), or a prvalue of
3070
+ function pointer type.
3071
 
3072
  If the selected function is non-virtual, or if the *id-expression* in
3073
  the class member access expression is a *qualified-id*, that function is
3074
  called. Otherwise, its final overrider [[class.virtual]] in the dynamic
3075
  type of the object expression is called; such a call is referred to as a
 
3078
  [*Note 2*: The dynamic type is the type of the object referred to by
3079
  the current value of the object expression. [[class.cdtor]] describes
3080
  the behavior of virtual function calls when the object expression refers
3081
  to an object under construction or destruction. — *end note*]
3082
 
3083
+ [*Note 3*: If a function name is used, and name lookup [[basic.lookup]]
3084
+ does not find a declaration of that name, the program is ill-formed. No
3085
+ function is implicitly declared by such a call. — *end note*]
 
3086
 
3087
  If the *postfix-expression* names a destructor or pseudo-destructor
3088
  [[expr.prim.id.dtor]], the type of the function call expression is
3089
  `void`; otherwise, the type of the function call expression is the
3090
  return type of the statically chosen function (i.e., ignoring the
 
3093
  which case the *postfix-expression* is a possibly-parenthesized class
3094
  member access), the function call destroys the object of scalar type
3095
  denoted by the object expression of the class member access
3096
  [[expr.ref]], [[basic.life]].
3097
 
3098
+ A type `T`_call is *call-compatible* with a function type `T`_func if
3099
+ `T`_call is the same type as `T`_func or if the type “pointer to
3100
+ `T`_func” can be converted to type “pointer to `T`_callvia a function
3101
+ pointer conversion [[conv.fctptr]]. Calling a function through an
3102
+ expression whose function type is not call-compatible with the type of
3103
+ the called function’s definition results in undefined behavior.
3104
 
3105
+ [*Note 4*: This requirement allows the case when the expression has the
3106
+ type of a potentially-throwing function, but the called function has a
3107
  non-throwing exception specification, and the function types are
3108
  otherwise the same. — *end note*]
3109
 
3110
  When a function is called, each parameter [[dcl.fct]] is initialized
3111
+ [[dcl.init]], [[class.copy.ctor]] with its corresponding argument, and
3112
+ each precondition assertion of the function is evaluated
3113
+ [[dcl.contract.func]]. If the function is an explicit object member
3114
+ function and there is an implied object argument [[over.call.func]], the
3115
+ list of provided arguments is preceded by the implied object argument
3116
+ for the purposes of this correspondence. If there is no corresponding
3117
+ argument, the default argument for the parameter is used.
3118
 
3119
  [*Example 1*:
3120
 
3121
  ``` cpp
3122
  template<typename ...T> int f(int n = 0, T ...t);
3123
  int x = f<int>(); // error: no argument for second function parameter
3124
  ```
3125
 
3126
  — *end example*]
3127
 
3128
+ If the function is an implicit object member function, the object
3129
+ expression of the class member access shall be a glvalue and the
3130
+ implicit object parameter of the function [[over.match.funcs]] is
3131
+ initialized with that glvalue, converted as if by an explicit type
3132
  conversion [[expr.cast]].
3133
 
3134
  [*Note 5*: There is no access or ambiguity checking on this conversion;
3135
  the access checking and disambiguation are done as part of the (possibly
3136
  implicit) class member access operator. See  [[class.member.lookup]],
 
3141
 
3142
  [*Note 6*: This still allows a parameter to be a pointer or reference
3143
  to such a type. However, it prevents a passed-by-value parameter to have
3144
  an incomplete or abstract class type. — *end note*]
3145
 
3146
+ It is *implementation-defined* whether a parameter is destroyed when the
3147
+ function in which it is defined exits
3148
+ [[stmt.return]], [[except.ctor]], [[expr.await]] or at the end of the
3149
+ enclosing full-expression; parameters are always destroyed in the
3150
+ reverse order of their construction. The initialization and destruction
3151
+ of each parameter occurs within the context of the full-expression
3152
+ [[intro.execution]] where the function call appears.
3153
 
3154
+ [*Example 2*: The access [[class.access.general]] of the constructor,
3155
+ conversion functions, or destructor is checked at the point of call. If
3156
+ a constructor or destructor for a function parameter throws an
3157
+ exception, any *function-try-block* [[except.pre]] of the called
3158
+ function with a handler that can handle the exception is not
 
3159
  considered. — *end example*]
3160
 
3161
  The *postfix-expression* is sequenced before each *expression* in the
3162
  *expression-list* and any default argument. The initialization of a
3163
+ parameter or, if the implementation introduces any temporary objects to
3164
+ hold the values of function parameters [[class.temporary]], the
3165
+ initialization of those temporaries, including every associated value
3166
+ computation and side effect, is indeterminately sequenced with respect
3167
+ to that of any other parameter. These evaluations are sequenced before
3168
+ the evaluation of the precondition assertions of the function, which are
3169
+ evaluated in sequence [[dcl.contract.func]]. For any temporaries
3170
+ introduced to hold the values of function parameters, the initialization
3171
+ of the parameter objects from those temporaries is indeterminately
3172
+ sequenced with respect to the evaluation of each precondition assertion.
3173
 
3174
  [*Note 7*: All side effects of argument evaluations are sequenced
3175
  before the function is entered (see 
3176
  [[intro.execution]]). — *end note*]
3177
 
 
3215
  function call if the return type of the final overrider is different
3216
  from the return type of the statically chosen function, the value
3217
  returned from the final overrider is converted to the return type of the
3218
  statically chosen function.
3219
 
3220
+ When the called function exits normally [[stmt.return]], [[expr.await]],
3221
+ all postcondition assertions of the function are evaluated in sequence
3222
+ [[dcl.contract.func]]. If the implementation introduces any temporary
3223
+ objects to hold the result value as specified in [[class.temporary]],
3224
+ the evaluation of each postcondition assertion is indeterminately
3225
+ sequenced with respect to the initialization of any of those temporaries
3226
+ or the result object. These evaluations, in turn, are sequenced before
3227
+ the destruction of any function parameters.
3228
+
3229
  [*Note 9*: A function can change the values of its non-const
3230
  parameters, but these changes cannot affect the values of the arguments
3231
  except where a parameter is of a reference type [[dcl.ref]]; if the
3232
+ reference is to a const-qualified type, `const_cast` needs to be used to
3233
+ cast away the constness in order to modify the argument’s value. Where a
3234
+ parameter is of `const` reference type a temporary object is introduced
3235
+ if needed
3236
  [[dcl.type]], [[lex.literal]], [[lex.string]], [[dcl.array]], [[class.temporary]].
3237
  In addition, it is possible to modify the values of non-constant objects
3238
  through pointer parameters. — *end note*]
3239
 
3240
  A function can be declared to accept fewer arguments (by declaring
 
3260
  function-to-pointer [[conv.func]] standard conversions are performed on
3261
  the argument expression. An argument that has type cv `std::nullptr_t`
3262
  is converted to type `void*` [[conv.ptr]]. After these conversions, if
3263
  the argument does not have arithmetic, enumeration, pointer,
3264
  pointer-to-member, or class type, the program is ill-formed. Passing a
3265
+ potentially-evaluated argument of a scoped enumeration type [[dcl.enum]]
3266
+ or of a class type [[class]] having an eligible non-trivial copy
3267
+ constructor [[special]], [[class.copy.ctor]], an eligible non-trivial
3268
+ move constructor, or a non-trivial destructor [[class.dtor]], with no
3269
+ corresponding parameter, is conditionally-supported with
3270
+ *implementation-defined* semantics. If the argument has integral or
3271
  enumeration type that is subject to the integral promotions
3272
  [[conv.prom]], or a floating-point type that is subject to the
3273
  floating-point promotion [[conv.fpprom]], the value of the argument is
3274
  converted to the promoted type before the call. These promotions are
3275
  referred to as the *default argument promotions*.
 
3277
  Recursive calls are permitted, except to the `main` function
3278
  [[basic.start.main]].
3279
 
3280
  A function call is an lvalue if the result type is an lvalue reference
3281
  type or an rvalue reference to function type, an xvalue if the result
3282
+ type is an rvalue reference to object type, and a prvalue otherwise. If
3283
+ it is a non-void prvalue, the type of the function call expression shall
3284
+ be complete, except as specified in [[dcl.type.decltype]].
3285
 
3286
  #### Explicit type conversion (functional notation) <a id="expr.type.conv">[[expr.type.conv]]</a>
3287
 
3288
  A *simple-type-specifier* [[dcl.type.simple]] or *typename-specifier*
3289
  [[temp.res]] followed by a parenthesized optional *expression-list* or
 
3292
  deduced class type, it is replaced by the return type of the function
3293
  selected by overload resolution for class template deduction
3294
  [[over.match.class.deduct]] for the remainder of this subclause.
3295
  Otherwise, if the type contains a placeholder type, it is replaced by
3296
  the type determined by placeholder type deduction
3297
+ [[dcl.type.auto.deduct]]. Let `T` denote the resulting type. Then:
3298
+
3299
+ - If the initializer is a parenthesized single expression, the type
3300
+ conversion expression is equivalent to the corresponding cast
3301
+ expression [[expr.cast]].
3302
+ - Otherwise, if `T` is cv `void`, the initializer shall be `()` or `{}`
3303
+ (after pack expansion, if any), and the expression is a prvalue of
3304
+ type `void` that performs no initialization.
3305
+ - Otherwise, if `T` is a reference type, the expression has the same
3306
+ effect as direct-initializing an invented variable `t` of type `T`
3307
+ from the initializer and then using `t` as the result of the
3308
+ expression; the result is an lvalue if `T` is an lvalue reference type
3309
+ or an rvalue reference to function type and an xvalue otherwise.
3310
+ - Otherwise, the expression is a prvalue of type `T` whose result object
3311
+ is direct-initialized [[dcl.init]] with the initializer.
3312
+
3313
+ If the initializer is a parenthesized optional *expression-list*, `T`
3314
+ shall not be an array type.
3315
 
3316
  [*Example 1*:
3317
 
3318
  ``` cpp
3319
  struct A {};
 
3327
  }
3328
  ```
3329
 
3330
  — *end example*]
3331
 
 
 
 
 
 
 
 
 
 
 
3332
  #### Class member access <a id="expr.ref">[[expr.ref]]</a>
3333
 
3334
  A postfix expression followed by a dot `.` or an arrow `->`, optionally
3335
  followed by the keyword `template`, and then followed by an
3336
+ *id-expression* or a *splice-expression*, is a postfix expression.
 
3337
 
3338
+ [*Note 1*: If the keyword `template` is used and followed by an
3339
+ *id-expression*, the unqualified name is considered to refer to a
3340
+ template [[temp.names]]. If a *simple-template-id* results and is
3341
+ followed by a `::`, the *id-expression* is a
3342
+ *qualified-id*. — *end note*]
3343
 
3344
+ For a dot that is followed by an expression that designates a static
3345
+ member or an enumerator, the first expression is a discarded-value
3346
+ expression [[expr.context]]; if the expression after the dot designates
3347
+ a non-static data member, the first expression shall be a glvalue. A
3348
+ postfix expression that is followed by an arrow shall be a prvalue
3349
+ having pointer type. The expression `E1->E2` is converted to the
3350
+ equivalent form `(*(E1)).E2`; the remainder of [[expr.ref]] will address
3351
+ only the form using a dot.[^11]
3352
 
3353
+ The postfix expression before the dot is evaluated;[^12]
 
 
 
 
3354
 
3355
+ the result of that evaluation, together with the *id-expression* or
3356
+ *splice-expression*, determines the result of the entire postfix
3357
+ expression.
3358
+
3359
+ Abbreviating *postfix-expression*`.`*id-expression* or
3360
+ *postfix-expression*`.`*splice-expression* as `E1.E2`, `E1` is called
3361
+ the *object expression*. If the object expression is of scalar type,
3362
+ `E2` shall name the pseudo-destructor of that same type (ignoring
3363
  cv-qualifications) and `E1.E2` is a prvalue of type “function of ()
3364
  returning `void`”.
3365
 
3366
  [*Note 2*: This value can only be used for a notional function call
3367
  [[expr.prim.id.dtor]]. — *end note*]
 
3374
  when the class is complete [[class.member.lookup]]. — *end note*]
3375
 
3376
  [*Note 4*: [[basic.lookup.qual]] describes how names are looked up
3377
  after the `.` and `->` operators. — *end note*]
3378
 
3379
+ If `E2` is a *splice-expression*, then let `T1` be the type of `E1`.
3380
+ `E2` shall designate either a member of `T1` or a direct base class
3381
+ relationship (`T1`, `B`).
 
 
 
3382
 
3383
+ If `E2` designates a bit-field, `E1.E2` is a bit-field. The type and
3384
+ value category of `E1.E2` are determined as follows. In the remainder
3385
+ of  [[expr.ref]], *cq* represents either `const` or the absence of
3386
+ `const` and *vq* represents either `volatile` or the absence of
3387
+ `volatile`. *cv* represents an arbitrary set of cv-qualifiers, as
3388
+ defined in  [[basic.type.qualifier]].
3389
 
3390
+ If `E2` designates an entity that is declared to have type “reference to
3391
+ `T`”, then `E1.E2` is an lvalue of type `T`. In that case, if `E2`
3392
+ designates a static data member, `E1.E2` designates the object or
3393
+ function to which the reference is bound, otherwise `E1.E2` designates
3394
+ the object or function to which the corresponding reference member of
3395
+ `E1` is bound. Otherwise, one of the following rules applies.
3396
+
3397
+ - If `E2` designates a static data member and the type of `E2` is `T`,
3398
+ then `E1.E2` is an lvalue; the expression designates the named member
3399
+ of the class. The type of `E1.E2` is `T`.
3400
+ - Otherwise, if `E2` designates a non-static data member and the type of
3401
+ `E1` is *cq1 vq1* `X`”, and the type of `E2` is “*cq2 vq2* `T`”, the
3402
+ expression designates the corresponding member subobject of the object
3403
+ designated by `E1`. If `E1` is an lvalue, then `E1.E2` is an lvalue;
3404
+ otherwise `E1.E2` is an xvalue. Let the notation *vq12* stand for the
3405
+ “union” of *vq1* and *vq2*; that is, if *vq1* or *vq2* is `volatile`,
3406
+ then *vq12* is `volatile`. Similarly, let the notation *cq12* stand
3407
+ for the “union” of *cq1* and *cq2*; that is, if *cq1* or *cq2* is
3408
+ `const`, then *cq12* is `const`. If the entity designated by `E2` is
3409
+ declared to be a `mutable` member, then the type of `E1.E2` is “*vq12*
3410
+ `T`”. If the entity designated by `E2` is not declared to be a
3411
+ `mutable` member, then the type of `E1.E2` is “*cq12* *vq12* `T`”.
3412
+ - Otherwise, if `E2` denotes an overload set, the expression shall be
3413
+ the (possibly-parenthesized) left-hand operand of a member function
3414
+ call [[expr.call]], and function overload resolution [[over.match]] is
3415
+ used to select the function to which `E2` refers. The type of `E1.E2`
3416
+ is the type of `E2` and `E1.E2` refers to the function referred to by
3417
+ `E2`.
3418
  - If `E2` refers to a static member function, `E1.E2` is an lvalue.
3419
  - Otherwise (when `E2` refers to a non-static member function),
3420
+ `E1.E2` is a prvalue. \[*Note 5*: Any redundant set of parentheses
3421
+ surrounding the expression is ignored
3422
+ [[expr.prim.paren]]. *end note*]
3423
+ - Otherwise, if `E2` designates a nested type, the expression `E1.E2` is
3424
+ ill-formed.
3425
+ - Otherwise, if `E2` designates a member enumerator and the type of `E2`
3426
+ is `T`, the expression `E1.E2` is a prvalue of type `T` whose value is
3427
+ the value of the enumerator.
3428
+ - Otherwise, if `E2` designates a direct base class relationship (D, B)
3429
+ and the type of `E1` is cv `T`, the expression designates the direct
3430
+ base class subobject of type B of the object designated by `E1`. If
3431
+ `E1` is an lvalue, then `E1.E2` is an lvalue; otherwise, `E1.E2` is an
3432
+ xvalue. The type of `E1.E2` is “cv `B`”.
3433
+ \[*Note 6*: This can only occur in an expression of the form
3434
+ `e1.[:e2:]`. *end note*]
3435
+ \[*Example 1*:
3436
+ ``` cpp
3437
+ struct B {
3438
+ int b;
3439
+ };
3440
+ struct C : B {
3441
+ int get() const { return b; }
3442
+ };
3443
+ struct D : B, C { };
3444
+
3445
+ constexpr int f() {
3446
+ D d = {1, {}};
3447
+
3448
+ // b unambiguously refers to the direct base class of type B,
3449
+ // not the indirect base class of type B
3450
+ B& b = d.[: std::meta::bases_of(^^D, std::meta::access_context::current())[0] :];
3451
+ b.b += 10;
3452
+ return 10 * b.b + d.get();
3453
+ }
3454
+ static_assert(f() == 110);
3455
+ ```
3456
+
3457
+ — *end example*]
3458
+ - Otherwise, the program is ill-formed.
3459
+
3460
+ If `E2` designates a non-static member (possibly after overload
3461
+ resolution), the program is ill-formed if the class of which `E2`
3462
+ designates a direct member is an ambiguous base [[class.member.lookup]]
3463
+ of the designating class [[class.access.base]] of `E2`.
3464
+
3465
+ [*Note 7*: The program is also ill-formed if the naming class is an
3466
  ambiguous base of the class type of the object expression; see 
3467
  [[class.access.base]]. — *end note*]
3468
 
3469
+ If `E2` designates a non-static member (possibly after overload
3470
+ resolution) and the result of `E1` is an object whose type is not
3471
+ similar [[conv.qual]] to the type of `E1`, the behavior is undefined.
3472
 
3473
+ [*Example 2*:
3474
 
3475
  ``` cpp
3476
  struct A { int i; };
3477
  struct B { int j; };
3478
  struct D : A, B {};
 
3485
 
3486
  — *end example*]
3487
 
3488
  #### Increment and decrement <a id="expr.post.incr">[[expr.post.incr]]</a>
3489
 
3490
+ The value of a postfix `++` expression is the value obtained by applying
3491
+ the lvalue-to-rvalue conversion [[conv.lval]] to its operand.
3492
 
3493
  [*Note 1*: The value obtained is a copy of the original
3494
  value. — *end note*]
3495
 
3496
  The operand shall be a modifiable lvalue. The type of the operand shall
3497
  be an arithmetic type other than cv `bool`, or a pointer to a complete
3498
  object type. An operand with volatile-qualified type is deprecated; see 
3499
  [[depr.volatile.type]]. The value of the operand object is modified
3500
+ [[defns.access]] as if it were the operand of the prefix `++` operator
3501
+ [[expr.pre.incr]]. The value computation of the `++` expression is
3502
+ sequenced before the modification of the operand object. With respect to
3503
+ an indeterminately-sequenced function call, the operation of postfix
3504
+ `++` is a single evaluation.
3505
 
3506
  [*Note 2*: Therefore, a function call cannot intervene between the
3507
  lvalue-to-rvalue conversion and the side effect associated with any
3508
  single postfix `++` operator. — *end note*]
3509
 
3510
  The result is a prvalue. The type of the result is the cv-unqualified
3511
+ version of the type of the operand.
 
 
 
3512
 
3513
  The operand of postfix `--` is decremented analogously to the postfix
3514
  `++` operator.
3515
 
3516
  [*Note 3*: For prefix increment and decrement, see 
 
3538
  such that `B` is a base class of `D`, the result is a pointer to the
3539
  unique `B` subobject of the `D` object pointed to by `v`, or a null
3540
  pointer value if `v` is a null pointer value. Similarly, if `T` is
3541
  “reference to *cv1* `B`” and `v` has type *cv2* `D` such that `B` is a
3542
  base class of `D`, the result is the unique `B` subobject of the `D`
3543
+ object referred to by `v`.[^13]
3544
 
3545
  In both the pointer and reference cases, the program is ill-formed if
3546
  `B` is an inaccessible or ambiguous base class of `D`.
3547
 
3548
  [*Example 1*:
 
3560
  Otherwise, `v` shall be a pointer to or a glvalue of a polymorphic type
3561
  [[class.virtual]].
3562
 
3563
  If `v` is a null pointer value, the result is a null pointer value.
3564
 
3565
+ If `v` has type “pointer to cv `U`” and `v` does not point to an object
3566
+ whose type is similar [[conv.qual]] to `U` and that is within its
3567
+ lifetime or within its period of construction or destruction
3568
+ [[class.cdtor]], the behavior is undefined. If `v` is a glvalue of type
3569
+ `U` and `v` does not refer to an object whose type is similar to `U` and
3570
+ that is within its lifetime or within its period of construction or
3571
+ destruction, the behavior is undefined.
3572
+
3573
  If `T` is “pointer to cv `void`”, then the result is a pointer to the
3574
  most derived object pointed to by `v`. Otherwise, a runtime check is
3575
  applied to see if the object pointed or referred to by `v` can be
3576
  converted to the type pointed or referred to by `T`.
3577
 
 
3579
  check logically executes as follows:
3580
 
3581
  - If, in the most derived object pointed (referred) to by `v`, `v`
3582
  points (refers) to a public base class subobject of a `C` object, and
3583
  if only one object of type `C` is derived from the subobject pointed
3584
+ (referred) to by `v`, the result points (refers) to that `C` object.
3585
  - Otherwise, if `v` points (refers) to a public base class subobject of
3586
  the most derived object, and the type of the most derived object has a
3587
  base class, of type `C`, that is unambiguous and public, the result
3588
  points (refers) to the `C` subobject of the most derived object.
3589
  - Otherwise, the runtime check *fails*.
 
3629
 
3630
  #### Type identification <a id="expr.typeid">[[expr.typeid]]</a>
3631
 
3632
  The result of a `typeid` expression is an lvalue of static type `const`
3633
  `std::type_info` [[type.info]] and dynamic type `const` `std::type_info`
3634
+ or `const` `name` where `name` is an *implementation-defined* class
3635
  publicly derived from `std::type_info` which preserves the behavior
3636
+ described in  [[type.info]].[^14]
3637
 
3638
  The lifetime of the object referred to by the lvalue extends to the end
3639
  of the program. Whether or not the destructor is called for the
3640
  `std::type_info` object at the end of the program is unspecified.
3641
 
3642
  If the type of the *expression* or *type-id* operand is a (possibly
3643
  cv-qualified) class type or a reference to (possibly cv-qualified) class
3644
  type, that class shall be completely defined.
3645
 
3646
+ If an *expression* operand of `typeid` is a possibly-parenthesized
3647
+ *unary-expression* whose *unary-operator* is `*` and whose operand
3648
+ evaluates to a null pointer value [[basic.compound]], the `typeid`
3649
+ expression throws an exception [[except.throw]] of a type that would
3650
+ match a handler of type `std::bad_typeid` [[bad.typeid]].
3651
+
3652
+ [*Note 1*: In other contexts, evaluating such a *unary-expression*
3653
+ results in undefined behavior [[expr.unary.op]]. — *end note*]
3654
+
3655
  When `typeid` is applied to a glvalue whose type is a polymorphic class
3656
  type [[class.virtual]], the result refers to a `std::type_info` object
3657
  representing the type of the most derived object [[intro.object]] (that
3658
+ is, the dynamic type) to which the glvalue refers.
 
 
 
 
 
3659
 
3660
  When `typeid` is applied to an expression other than a glvalue of a
3661
  polymorphic class type, the result refers to a `std::type_info` object
3662
  representing the static type of the expression. Lvalue-to-rvalue
3663
  [[conv.lval]], array-to-pointer [[conv.array]], and function-to-pointer
 
3670
  `std::type_info` object representing the type of the *type-id*. If the
3671
  type of the *type-id* is a reference to a possibly cv-qualified type,
3672
  the result of the `typeid` expression refers to a `std::type_info`
3673
  object representing the cv-unqualified referenced type.
3674
 
3675
+ [*Note 2*: The *type-id* cannot denote a function type with a
3676
  *cv-qualifier-seq* or a *ref-qualifier* [[dcl.fct]]. — *end note*]
3677
 
3678
  If the type of the expression or *type-id* is a cv-qualified type, the
3679
  result of the `typeid` expression refers to a `std::type_info` object
3680
  representing the cv-unqualified type.
 
3697
  The type `std::type_info` [[type.info]] is not predefined; if a standard
3698
  library declaration [[typeinfo.syn]], [[std.modules]] of
3699
  `std::type_info` does not precede [[basic.lookup.general]] a `typeid`
3700
  expression, the program is ill-formed.
3701
 
3702
+ [*Note 3*: Subclause [[class.cdtor]] describes the behavior of `typeid`
3703
  applied to an object under construction or destruction. — *end note*]
3704
 
3705
  #### Static cast <a id="expr.static.cast">[[expr.static.cast]]</a>
3706
 
3707
  The result of the expression `static_cast<T>(v)` is the result of
3708
  converting the expression `v` to type `T`. If `T` is an lvalue reference
3709
  type or an rvalue reference to function type, the result is an lvalue;
3710
  if `T` is an rvalue reference to object type, the result is an xvalue;
3711
+ otherwise, the result is a prvalue.
 
3712
 
3713
  An lvalue of type “*cv1* `B`”, where `B` is a class type, can be cast to
3714
+ type “reference to *cv2* `D`”, where `D` is a complete class derived
3715
  [[class.derived]] from `B`, if *cv2* is the same cv-qualification as, or
3716
  greater cv-qualification than, *cv1*. If `B` is a virtual base class of
3717
  `D` or a base class of a virtual base class of `D`, or if no valid
3718
  standard conversion from “pointer to `D`” to “pointer to `B`” exists
3719
  [[conv.ptr]], the program is ill-formed. An xvalue of type “*cv1* `B`”
 
3744
  used as the operand of the `static_cast` for the remainder of this
3745
  subclause. If `T2` is an inaccessible [[class.access]] or ambiguous
3746
  [[class.member.lookup]] base class of `T1`, a program that necessitates
3747
  such a cast is ill-formed.
3748
 
3749
+ Any expression can be explicitly converted to type cv `void`, in which
3750
+ case the operand is a discarded-value expression [[expr.prop]].
3751
+
3752
+ [*Note 1*: Such a `static_cast` has no result as it is a prvalue of
3753
+ type `void`; see  [[basic.lval]]. — *end note*]
3754
+
3755
+ [*Note 2*: However, if the value is in a temporary object
3756
+ [[class.temporary]], the destructor for that object is not executed
3757
+ until the usual time, and the value of the object is preserved for the
3758
+ purpose of executing the destructor. — *end note*]
3759
+
3760
+ Otherwise, an expression E can be explicitly converted to a type `T` if
3761
+ there is an implicit conversion sequence [[over.best.ics]] from E to
3762
+ `T`, if overload resolution for a direct-initialization [[dcl.init]] of
3763
+ an object or reference of type `T` from E would find at least one viable
3764
  function [[over.match.viable]], or if `T` is an aggregate type
3765
  [[dcl.init.aggr]] having a first element `x` and there is an implicit
3766
  conversion sequence from E to the type of `x`. If `T` is a reference
3767
  type, the effect is the same as performing the declaration and
3768
  initialization
 
3773
 
3774
  for some invented temporary variable `t` [[dcl.init]] and then using the
3775
  temporary variable as the result of the conversion. Otherwise, the
3776
  result object is direct-initialized from E.
3777
 
3778
+ [*Note 3*: The conversion is ill-formed when attempting to convert an
3779
  expression of class type to an inaccessible or ambiguous base
3780
  class. — *end note*]
3781
 
3782
+ [*Note 4*: If `T` is “array of unknown bound of `U`”, this
3783
  direct-initialization defines the type of the expression as
3784
  `U[1]`. — *end note*]
3785
 
3786
+ Otherwise, the lvalue-to-rvalue [[conv.lval]], array-to-pointer
3787
+ [[conv.array]], and function-to-pointer [[conv.func]] conversions are
3788
+ applied to the operand, and the conversions that can be performed using
3789
+ `static_cast` are listed below. No other conversion can be performed
3790
+ using `static_cast`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3791
 
3792
  A value of a scoped enumeration type [[dcl.enum]] can be explicitly
3793
  converted to an integral type; the result is the same as that of
3794
  converting to the enumeration’s underlying type and then to the
3795
  destination type. A value of a scoped enumeration type can also be
 
3842
 
3843
  If no valid standard conversion from “pointer to member of `B` of type
3844
  `T`” to “pointer to member of `D` of type `T`” exists [[conv.mem]], the
3845
  program is ill-formed. The null member pointer value [[conv.mem]] is
3846
  converted to the null member pointer value of the destination type. If
3847
+ class `B` contains the original member, or is a base class of the class
3848
+ containing the original member, the resulting pointer to member points
3849
+ to the original member. Otherwise, the behavior is undefined.
 
3850
 
3851
  [*Note 6*: Although class `B` need not contain the original member, the
3852
  dynamic type of the object with which indirection through the pointer to
3853
  member is performed must contain the original member; see 
3854
  [[expr.mptr.oper]]. — *end note*]
 
3856
  A prvalue of type “pointer to *cv1* `void`” can be converted to a
3857
  prvalue of type “pointer to *cv2* `T`”, where `T` is an object type and
3858
  *cv2* is the same cv-qualification as, or greater cv-qualification than,
3859
  *cv1*. If the original pointer value represents the address `A` of a
3860
  byte in memory and `A` does not satisfy the alignment requirement of
3861
+ `T`, then the resulting pointer value [[basic.compound]] is unspecified.
3862
+ Otherwise, if the original pointer value points to an object *a*, and
3863
+ there is an object *b* of type similar to `T` that is
3864
+ pointer-interconvertible [[basic.compound]] with *a*, the result is a
3865
+ pointer to *b*. Otherwise, the pointer value is unchanged by the
3866
+ conversion.
3867
 
3868
+ [*Example 2*:
3869
 
3870
  ``` cpp
3871
  T* p1 = new T;
3872
  const T* p2 = static_cast<const T*>(static_cast<void*>(p1));
3873
  bool b = p1 == p2; // b will have the value true.
 
3912
  any type to the type `std::nullptr_t`. — *end note*]
3913
 
3914
  A value of integral type or enumeration type can be explicitly converted
3915
  to a pointer. A pointer converted to an integer of sufficient size (if
3916
  any such exists on the implementation) and back to the same pointer type
3917
+ will have its original value [[basic.compound]]; mappings between
3918
+ pointers and integers are otherwise *implementation-defined*.
3919
 
3920
  A function pointer can be explicitly converted to a function pointer of
3921
  a different type.
3922
 
3923
  [*Note 4*: The effect of calling a function through a pointer to a
 
3927
  Except that converting a prvalue of type “pointer to `T1`” to the type
3928
  “pointer to `T2`” (where `T1` and `T2` are function types) and back to
3929
  its original type yields the original pointer value, the result of such
3930
  a pointer conversion is unspecified.
3931
 
 
 
 
3932
  An object pointer can be explicitly converted to an object pointer of a
3933
+ different type.[^15]
3934
 
3935
  When a prvalue `v` of object pointer type is converted to the object
3936
  pointer type “pointer to cv `T`”, the result is
3937
  `static_cast<cv T*>(static_cast<cv~void*>(v))`.
3938
 
3939
+ [*Note 5*: Converting a pointer of type “pointer to `T1`” that points
3940
  to an object of type `T1` to the type “pointer to `T2`” (where `T2` is
3941
  an object type and the alignment requirements of `T2` are no stricter
3942
  than those of `T1`) and back to its original type yields the original
3943
  pointer value. — *end note*]
3944
 
 
3950
  yield the original pointer value.
3951
 
3952
  The null pointer value [[basic.compound]] is converted to the null
3953
  pointer value of the destination type.
3954
 
3955
+ [*Note 6*: A null pointer constant of type `std::nullptr_t` cannot be
3956
  converted to a pointer type, and a null pointer constant of integral
3957
  type is not necessarily converted to a null pointer
3958
  value. — *end note*]
3959
 
3960
  A prvalue of type “pointer to member of `X` of type `T1`” can be
3961
  explicitly converted to a prvalue of a different type “pointer to member
3962
  of `Y` of type `T2`” if `T1` and `T2` are both function types or both
3963
+ object types.[^16]
3964
 
3965
  The null member pointer value [[conv.mem]] is converted to the null
3966
  member pointer value of the destination type. The result of this
3967
  conversion is unspecified, except in the following cases:
3968
 
 
3973
  `T1`” to the type “pointer to data member of `Y` of type `T2`” (where
3974
  the alignment requirements of `T2` are no stricter than those of `T1`)
3975
  and back to its original type yields the original pointer-to-member
3976
  value.
3977
 
3978
+ If `v` is a glvalue of type `T1`, designating an object or function *x*,
3979
+ it can be cast to the type “reference to `T2`” if an expression of type
3980
+ “pointer to `T1`” can be explicitly converted to the type “pointer to
3981
+ `T2`” using a `reinterpret_cast`. The result is that of
3982
+ `*reinterpret_cast<T2 *>(p)` where `p` is a pointer to *x* of type
3983
+ “pointer to `T1`”.
3984
+
3985
+ [*Note 7*:
3986
+
3987
+ No temporary is materialized [[conv.rval]] or created, no copy is made,
3988
+ and no constructors [[class.ctor]] or conversion functions
3989
+ [[class.conv]] are called.[^17]
3990
+
3991
+ — *end note*]
3992
 
3993
  #### Const cast <a id="expr.const.cast">[[expr.const.cast]]</a>
3994
 
3995
  The result of the expression `const_cast<T>(v)` is of type `T`. If `T`
3996
  is an lvalue reference to object type, the result is an lvalue; if `T`
3997
  is an rvalue reference to object type, the result is an xvalue;
3998
  otherwise, the result is a prvalue and the lvalue-to-rvalue
3999
  [[conv.lval]], array-to-pointer [[conv.array]], and function-to-pointer
4000
  [[conv.func]] standard conversions are performed on the expression `v`.
4001
+ The temporary materialization conversion [[conv.rval]] is not performed
4002
+ on `v`, other than as specified below. Conversions that can be performed
4003
+ explicitly using `const_cast` are listed below. No other conversion
4004
+ shall be performed explicitly using `const_cast`.
4005
 
4006
  [*Note 1*: Subject to the restrictions in this subclause, an expression
4007
  can be cast to its own type using a `const_cast`
4008
  operator. — *end note*]
4009
 
4010
+ For two similar object pointer or pointer to data member types `T1` and
4011
+ `T2` [[conv.qual]], a prvalue of type `T1` can be explicitly converted
4012
+ to the type `T2` using a `const_cast` if, considering the
4013
+ qualification-decompositions of both types, each P¹is the same as P²ᵢ
4014
+ for all i. If `v` is a null pointer or null member pointer, the result
4015
+ is a null pointer or null member pointer, respectively. Otherwise, the
4016
+ result points to or past the end of the same object, or points to the
4017
+ same member, respectively, as `v`.
 
 
 
 
 
 
 
 
 
 
 
4018
 
4019
  For two object types `T1` and `T2`, if a pointer to `T1` can be
4020
  explicitly converted to the type “pointer to `T2`” using a `const_cast`,
4021
  then the following conversions can also be made:
4022
 
4023
  - an lvalue of type `T1` can be explicitly converted to an lvalue of
4024
  type `T2` using the cast `const_cast<T2&>`;
4025
  - a glvalue of type `T1` can be explicitly converted to an xvalue of
4026
  type `T2` using the cast `const_cast<T2&&>`; and
4027
+ - if `T1` is a class or array type, a prvalue of type `T1` can be
4028
+ explicitly converted to an xvalue of type `T2` using the cast
4029
+ `const_cast<T2&&>`. The temporary materialization conversion is
4030
+ performed on `v`.
4031
 
4032
+ The result refers to the same object as the (possibly converted)
4033
+ operand.
 
4034
 
4035
+ [*Example 1*:
4036
+
4037
+ ``` cpp
4038
+ typedef int *A[3]; // array of 3 pointer to int
4039
+ typedef const int *const CA[3]; // array of 3 const pointer to const int
4040
+
4041
+ auto &&r2 = const_cast<A&&>(CA{}); // OK, temporary materialization conversion is performed
4042
+ ```
4043
+
4044
+ — *end example*]
4045
 
4046
  [*Note 2*:
4047
 
4048
  Depending on the type of the object, a write operation through the
4049
  pointer, lvalue or pointer to data member resulting from a `const_cast`
4050
+ that casts away a const-qualifier[^18]
4051
 
4052
  can produce undefined behavior [[dcl.type.cv]].
4053
 
4054
  — *end note*]
4055
 
 
4095
  sizeof '...' '(' identifier ')'
4096
  alignof '(' type-id ')'
4097
  noexcept-expression
4098
  new-expression
4099
  delete-expression
4100
+ reflect-expression
4101
  ```
4102
 
4103
  ``` bnf
4104
  %% Ed. note: character protrusion would misalign operators.
4105
 
 
4109
 
4110
  #### Unary operators <a id="expr.unary.op">[[expr.unary.op]]</a>
4111
 
4112
  The unary `*` operator performs *indirection*. Its operand shall be a
4113
  prvalue of type “pointer to `T`”, where `T` is an object or function
4114
+ type. The operator yields an lvalue of type `T`. If the operand points
4115
+ to an object or function, the result denotes that object or function;
4116
+ otherwise, the behavior is undefined except as specified in
4117
+ [[expr.typeid]].
4118
 
4119
+ [*Note 1*: Indirection through a pointer to an out-of-lifetime object
4120
+ is valid [[basic.life]]. — *end note*]
4121
+
4122
+ [*Note 2*: Indirection through a pointer to an incomplete type (other
4123
  than cv `void`) is valid. The lvalue thus obtained can be used in
4124
  limited ways (to initialize a reference, for example); this lvalue must
4125
  not be converted to a prvalue, see  [[conv.lval]]. — *end note*]
4126
 
4127
  Each of the following unary operators yields a prvalue.
4128
 
4129
  The operand of the unary `&` operator shall be an lvalue of some type
4130
+ `T`.
4131
 
4132
+ - If the operand is a *qualified-id* or *splice-expression* designating
4133
+ a non-static member `m`, other than an explicit object member
4134
+ function, `m` shall be a direct member of some class `C` that is not
4135
+ an anonymous union. The result has type “pointer to member of class
4136
+ `C` of type `T`” and designates `C::m`. \[*Note 3*: A *qualified-id*
4137
+ that names a member of a namespace-scope anonymous union is considered
4138
+ to be a class member access expression [[expr.prim.id.general]] and
4139
+ cannot be used to form a pointer to member. — *end note*]
4140
  - Otherwise, the result has type “pointer to `T`” and points to the
4141
  designated object [[intro.memory]] or function [[basic.compound]]. If
4142
+ the operand designates an explicit object member function [[dcl.fct]],
4143
+ the operand shall be a *qualified-id* or a *splice-expression*.
4144
+ \[*Note 4*: In particular, taking the address of a variable of type
4145
+ cv `T`” yields a pointer of type “pointer to cv `T`”. — *end note*]
4146
 
4147
  [*Example 1*:
4148
 
4149
  ``` cpp
4150
  struct A { int i; };
 
4156
  bool b = p2 > p1; // defined behavior, with value true
4157
  ```
4158
 
4159
  — *end example*]
4160
 
4161
+ [*Note 5*: A pointer to member formed from a `mutable` non-static data
4162
  member [[dcl.stc]] does not reflect the `mutable` specifier associated
4163
  with the non-static data member. — *end note*]
4164
 
4165
  A pointer to member is only formed when an explicit `&` is used and its
4166
+ operand is a *qualified-id* or *splice-expression* not enclosed in
4167
+ parentheses.
4168
 
4169
+ [*Note 6*: That is, the expression `&(qualified-id)`, where the
4170
  *qualified-id* is enclosed in parentheses, does not form an expression
4171
  of type “pointer to member”. Neither does `qualified-id`, because there
4172
  is no implicit conversion from a *qualified-id* for a non-static member
4173
  function to the type “pointer to member function” as there is from an
4174
  lvalue of function type to the type “pointer to function” [[conv.func]].
 
4178
  If `&` is applied to an lvalue of incomplete class type and the complete
4179
  type declares `operator&()`, it is unspecified whether the operator has
4180
  the built-in meaning or the operator function is called. The operand of
4181
  `&` shall not be a bit-field.
4182
 
4183
+ [*Note 7*: The address of an overload set [[over]] can be taken only in
4184
  a context that uniquely determines which function is referred to (see 
4185
  [[over.over]]). Since the context can affect whether the operand is a
4186
  static or non-static member function, the context can also affect
4187
  whether the expression has type “pointer to function” or “pointer to
4188
  member function”. — *end note*]
4189
 
4190
+ The operand of the unary `+` operator shall be a prvalue of arithmetic,
4191
+ unscoped enumeration, or pointer type and the result is the value of the
4192
  argument. Integral promotion is performed on integral or enumeration
4193
  operands. The type of the result is the type of the promoted operand.
4194
 
4195
+ The operand of the unary `-` operator shall be a prvalue of arithmetic
4196
+ or unscoped enumeration type and the result is the negative of its
4197
+ operand. Integral promotion is performed on integral or enumeration
4198
+ operands. The negative of an unsigned quantity is computed by
4199
+ subtracting its value from 2ⁿ, where n is the number of bits in the
4200
+ promoted operand. The type of the result is the type of the promoted
4201
+ operand.
4202
 
4203
+ [*Note 8*: The result is the two’s complement of the operand (where
4204
  operand and result are considered as unsigned). — *end note*]
4205
 
4206
  The operand of the logical negation operator `!` is contextually
4207
  converted to `bool` [[conv]]; its value is `true` if the converted
4208
  operand is `false` and `false` otherwise. The type of the result is
4209
  `bool`.
4210
 
4211
+ The operand of the `~` operator shall be a prvalue of integral or
4212
+ unscoped enumeration type. Integral promotions are performed. The type
4213
+ of the result is the type of the promoted operand. Given the
4214
+ coefficients `xᵢ` of the base-2 representation [[basic.fundamental]] of
4215
+ the promoted operand `x`, the coefficient `rᵢ` of the base-2
4216
+ representation of the result `r` is 1 if `xᵢ` is 0, and 0 otherwise.
4217
 
4218
+ [*Note 9*: The result is the ones’ complement of the operand (where
4219
  operand and result are considered as unsigned). — *end note*]
4220
 
4221
  There is an ambiguity in the grammar when `~` is followed by a
4222
+ *type-name* or *computed-type-specifier*. The ambiguity is resolved by
4223
  treating `~` as the operator rather than as the start of an
4224
  *unqualified-id* naming a destructor.
4225
 
4226
+ [*Note 10*: Because the grammar does not permit an operator to follow
4227
  the `.`, `->`, or `::` tokens, a `~` followed by a *type-name* or
4228
+ *computed-type-specifier* in a member access expression or
4229
+ *qualified-id* is unambiguously parsed as a destructor
4230
+ name. — *end note*]
4231
 
4232
  #### Increment and decrement <a id="expr.pre.incr">[[expr.pre.incr]]</a>
4233
 
4234
+ The operand of prefix `++` or `--` shall not be of type cv `bool`. An
4235
+ operand with volatile-qualified type is deprecated; see 
4236
+ [[depr.volatile.type]]. The expression `++x` is otherwise equivalent to
4237
+ `x+=1` and the expression `--x` is otherwise equivalent to `x-=1`
4238
+ [[expr.assign]].
 
 
4239
 
4240
+ [*Note 1*: For postfix increment and decrement, see 
 
 
 
 
 
 
 
4241
  [[expr.post.incr]]. — *end note*]
4242
 
4243
  #### Await <a id="expr.await">[[expr.await]]</a>
4244
 
4245
  The `co_await` expression is used to suspend evaluation of a coroutine
4246
  [[dcl.fct.def.coroutine]] while awaiting completion of the computation
4247
+ represented by the operand expression. Suspending the evaluation of a
4248
+ coroutine transfers control to its caller or resumer.
4249
 
4250
  ``` bnf
4251
  await-expression:
4252
+ co_await cast-expression
4253
  ```
4254
 
4255
+ An *await-expression* shall appear only as a potentially-evaluated
4256
+ expression within the *compound-statement* of a *function-body* or
4257
+ *lambda-expression*, in either case outside of a *handler*
4258
+ [[except.pre]]. In a *declaration-statement* or in the
4259
  *simple-declaration* (if any) of an *init-statement*, an
4260
  *await-expression* shall appear only in an *initializer* of that
4261
  *declaration-statement* or *simple-declaration*. An *await-expression*
4262
  shall not appear in a default argument [[dcl.fct.default]]. An
4263
  *await-expression* shall not appear in the initializer of a block
4264
+ variable with static or thread storage duration. An *await-expression*
4265
+ shall not be a potentially-evaluated subexpression of the predicate of a
4266
+ contract assertion [[basic.contract]]. A context within a function where
4267
+ an *await-expression* can appear is called a *suspension context* of the
4268
+ function.
4269
 
4270
  Evaluation of an *await-expression* involves the following auxiliary
4271
  types, expressions, and objects:
4272
 
4273
  - *p* is an lvalue naming the promise object [[dcl.fct.def.coroutine]]
 
4387
 
4388
  [*Note 1*:
4389
 
4390
  In particular, the values of `sizeof(bool)`, `sizeof(char16_t)`,
4391
  `sizeof(char32_t)`, and `sizeof(wchar_t)` are
4392
+ implementation-defined.[^19]
4393
 
4394
  — *end note*]
4395
 
4396
  [*Note 2*: See  [[intro.memory]] for the definition of byte and 
4397
  [[term.object.representation]] for the definition of object
 
4400
  When applied to a reference type, the result is the size of the
4401
  referenced type. When applied to a class, the result is the number of
4402
  bytes in an object of that class including any padding required for
4403
  placing objects of that type in an array. The result of applying
4404
  `sizeof` to a potentially-overlapping subobject is the size of the type,
4405
+ not the size of the subobject.[^20]
4406
 
4407
  When applied to an array, the result is the total number of bytes in the
4408
  array. This implies that the size of an array of n elements is n times
4409
  the size of an element.
4410
 
4411
  The lvalue-to-rvalue [[conv.lval]], array-to-pointer [[conv.array]], and
4412
  function-to-pointer [[conv.func]] standard conversions are not applied
4413
  to the operand of `sizeof`. If the operand is a prvalue, the temporary
4414
  materialization conversion [[conv.rval]] is applied.
4415
 
4416
+ The *identifier* in a `sizeof...` expression shall name a pack. The
4417
  `sizeof...` operator yields the number of elements in the pack
4418
  [[temp.variadic]]. A `sizeof...` expression is a pack expansion
4419
  [[temp.variadic]].
4420
 
4421
  [*Example 1*:
4422
 
4423
  ``` cpp
4424
  template<class... Types>
4425
  struct count {
4426
+ static constexpr std::size_t value = sizeof...(Types);
4427
  };
4428
  ```
4429
 
4430
  — *end example*]
4431
 
4432
  The result of `sizeof` and `sizeof...` is a prvalue of type
4433
  `std::size_t`.
4434
 
4435
  [*Note 3*: A `sizeof` expression is an integral constant expression
4436
+ [[expr.const]]. The *typedef-name* `std::size_t` is declared in the
4437
+ standard header `<cstddef>`
4438
+ [[cstddef.syn]], [[support.types.layout]]. — *end note*]
4439
 
4440
  #### Alignof <a id="expr.alignof">[[expr.alignof]]</a>
4441
 
4442
  An `alignof` expression yields the alignment requirement of its operand
4443
  type. The operand shall be a *type-id* representing a complete object
4444
  type, or an array thereof, or a reference to one of those types.
4445
 
4446
  The result is a prvalue of type `std::size_t`.
4447
 
4448
  [*Note 1*: An `alignof` expression is an integral constant expression
4449
+ [[expr.const]]. The *typedef-name* `std::size_t` is declared in the
4450
+ standard header `<cstddef>`
4451
+ [[cstddef.syn]], [[support.types.layout]]. — *end note*]
4452
 
4453
  When `alignof` is applied to a reference type, the result is the
4454
  alignment of the referenced type. When `alignof` is applied to an array
4455
  type, the result is the alignment of the element type.
4456
 
4457
  #### `noexcept` operator <a id="expr.unary.noexcept">[[expr.unary.noexcept]]</a>
4458
 
 
 
 
 
4459
  ``` bnf
4460
  noexcept-expression:
4461
  noexcept '(' expression ')'
4462
  ```
4463
 
4464
+ The operand of the `noexcept` operator is an unevaluated operand
4465
+ [[term.unevaluated.operand]]. If the operand is a prvalue, the temporary
4466
+ materialization conversion [[conv.rval]] is applied.
4467
+
4468
+ The result of the `noexcept` operator is a prvalue of type `bool`. The
4469
+ result is `false` if the full-expression of the operand is
4470
+ potentially-throwing [[except.spec]], and `true` otherwise.
4471
 
4472
  [*Note 1*: A *noexcept-expression* is an integral constant expression
4473
  [[expr.const]]. — *end note*]
4474
 
 
 
 
4475
  #### New <a id="expr.new">[[expr.new]]</a>
4476
 
4477
+ The *new-expression* attempts to create an object of the *type-id* or
4478
+ *new-type-id* [[dcl.name]] to which it is applied. The type of that
4479
  object is the *allocated type*. This type shall be a complete object
4480
  type [[term.incomplete.type]], but not an abstract class type
4481
  [[class.abstract]] or array thereof [[intro.object]].
4482
 
4483
  [*Note 1*: Because references are not objects, references cannot be
 
4519
  new-initializer:
4520
  '(' expression-listₒₚₜ ')'
4521
  braced-init-list
4522
  ```
4523
 
4524
+ If a placeholder type [[dcl.spec.auto]] or a placeholder for a deduced
4525
+ class type [[dcl.type.class.deduct]] appears in the *type-specifier-seq*
4526
+ of a *new-type-id* or *type-id* of a *new-expression*, the allocated
4527
+ type is deduced as follows: Let *init* be the *new-initializer*, if any,
4528
+ and `T` be the *new-type-id* or *type-id* of the *new-expression*, then
4529
+ the allocated type is the type deduced for the variable `x` in the
4530
+ invented declaration [[dcl.spec.auto]]:
4531
 
4532
  ``` cpp
4533
  T x init ;
4534
  ```
4535
 
 
4601
  its value shall be greater than zero.
4602
 
4603
  [*Example 4*: Given the definition `int n = 42`, `new float[n][5]` is
4604
  well-formed (because `n` is the *expression* of a
4605
  *noptr-new-declarator*), but `new float[5][n]` is ill-formed (because
4606
+ `n` is not a constant expression). Furthermore, `new float[0]` is
4607
+ well-formed (because `0` is the *expression* of a
4608
+ *noptr-new-declarator*, where a value of zero results in the allocation
4609
+ of an array with no elements), but `new float[n][0]` is ill-formed
4610
+ (because `0` is the *constant-expression* of a *noptr-new-declarator*,
4611
+ where only values greater than zero are allowed). — *end example*]
4612
 
4613
  If the *type-id* or *new-type-id* denotes an array type of unknown bound
4614
  [[dcl.array]], the *new-initializer* shall not be omitted; the allocated
4615
  object is an array with `n` elements, where `n` is determined from the
4616
  number of initial elements supplied in the *new-initializer*
4617
  [[dcl.init.aggr]], [[dcl.init.string]].
4618
 
4619
  If the *expression* in a *noptr-new-declarator* is present, it is
4620
+ implicitly converted to `std::size_t`. The value of the *expression* is
4621
+ invalid if
4622
 
4623
  - the expression is of non-class type and its value before converting to
4624
  `std::size_t` is less than zero;
4625
  - the expression is of class type and its value before application of
4626
+ the second standard conversion [[over.ics.user]][^21] is less than
4627
  zero;
4628
  - its value is such that the size of the allocated object would exceed
4629
  the *implementation-defined* limit [[implimits]]; or
4630
  - the *new-initializer* is a *braced-init-list* and the number of array
4631
  elements for which initializers are provided (including the
4632
  terminating `'\0'` in a *string-literal* [[lex.string]]) exceeds the
4633
  number of elements to initialize.
4634
 
4635
+ If the value of the *expression* is invalid after converting to
4636
+ `std::size_t`:
4637
 
4638
  - if the *expression* is a potentially-evaluated core constant
4639
  expression, the program is ill-formed;
4640
  - otherwise, an allocation function is not called; instead
4641
  - if the allocation function that would have been called has a
 
4647
  `std::bad_array_new_length` [[new.badlength]].
4648
 
4649
  When the value of the *expression* is zero, the allocation function is
4650
  called to allocate an array with no elements.
4651
 
4652
+ If the allocated type is an array, the *new-initializer* is a
4653
+ *braced-init-list*, and the *expression* is potentially-evaluated and
4654
+ not a core constant expression, the semantic constraints of
4655
+ copy-initializing a hypothetical element of the array from an empty
4656
+ initializer list are checked [[dcl.init.list]].
4657
+
4658
+ [*Note 5*: The array can contain more elements than there are elements
4659
+ in the *braced-init-list*, requiring initialization of the remainder of
4660
+ the array elements from an empty initializer list. — *end note*]
4661
+
4662
  Objects created by a *new-expression* have dynamic storage duration
4663
  [[basic.stc.dynamic]].
4664
 
4665
+ [*Note 6*: The lifetime of such an object is not necessarily
4666
  restricted to the scope in which it is created. — *end note*]
4667
 
4668
  When the allocated type is “array of `N` `T`” (that is, the
4669
  *noptr-new-declarator* syntax is used or the *new-type-id* or *type-id*
4670
  denotes an array type), the *new-expression* yields a prvalue of type
4671
  “pointer to `T`” that points to the initial element (if any) of the
4672
  array. Otherwise, let `T` be the allocated type; the *new-expression* is
4673
  a prvalue of type “pointer to T” that points to the object created.
4674
 
4675
+ [*Note 7*: Both `new int` and `new int[10]` have type `int*` and the
4676
  type of `new int[i][10]` is `int (*)[10]`. — *end note*]
4677
 
4678
  A *new-expression* may obtain storage for the object by calling an
4679
  allocation function [[basic.stc.dynamic.allocation]]. If the
4680
  *new-expression* terminates by throwing an exception, it may release
 
4683
  type, the allocation function’s name is `operator new` and the
4684
  deallocation function’s name is `operator delete`. If the allocated type
4685
  is an array type, the allocation function’s name is `operator new[]` and
4686
  the deallocation function’s name is `operator delete[]`.
4687
 
4688
+ [*Note 8*: An implementation is expected to provide default definitions
4689
  for the global allocation functions
4690
  [[basic.stc.dynamic]], [[new.delete.single]], [[new.delete.array]]. A
4691
  C++ program can provide alternative definitions of these functions
4692
  [[replacement.functions]] and/or class-specific versions [[class.free]].
4693
  The set of allocation and deallocation functions that can be called by a
 
4704
  An implementation is allowed to omit a call to a replaceable global
4705
  allocation function [[new.delete.single]], [[new.delete.array]]. When it
4706
  does so, the storage is instead provided by the implementation or
4707
  provided by extending the allocation of another *new-expression*.
4708
 
4709
+ During an evaluation of a constant expression, a call to a replaceable
4710
+ allocation function is always omitted [[expr.const]].
 
 
 
 
4711
 
4712
  The implementation may extend the allocation of a *new-expression* `e1`
4713
  to provide storage for a *new-expression* `e2` if the following would be
4714
  true were the allocation not extended:
4715
 
 
4848
  value of the *new-expression* shall be null.
4849
 
4850
  [*Note 11*: When the allocation function returns a value other than
4851
  null, it must be a pointer to a block of storage in which space for the
4852
  object has been reserved. The block of storage is assumed to be
4853
+ appropriately aligned [[basic.align]] and of the requested size. The
4854
+ address of the created object will not necessarily be the same as that
4855
+ of the block if the object is an array. — *end note*]
4856
 
4857
  A *new-expression* that creates an object of type `T` initializes that
4858
  object as follows:
4859
 
4860
  - If the *new-initializer* is omitted, the object is default-initialized
 
4866
  The invocation of the allocation function is sequenced before the
4867
  evaluations of expressions in the *new-initializer*. Initialization of
4868
  the allocated object is sequenced before the value computation of the
4869
  *new-expression*.
4870
 
4871
+ If the *new-expression* creates an array of objects of class type, the
4872
+ destructor is potentially invoked [[class.dtor]].
 
 
 
 
4873
 
4874
+ If any part of the object initialization described above[^22]
4875
 
4876
  terminates by throwing an exception and a suitable deallocation function
4877
  can be found, the deallocation function is called to free the memory in
4878
  which the object was being constructed, after which the exception
4879
  continues to propagate in the context of the *new-expression*. If no
 
4898
  otherwise, no deallocation function will be called. If the lookup finds
4899
  a usual deallocation function and that function, considered as a
4900
  placement deallocation function, would have been selected as a match for
4901
  the allocation function, the program is ill-formed. For a non-placement
4902
  allocation function, the normal deallocation function lookup is used to
4903
+ find the matching deallocation function [[expr.delete]]. In any case,
4904
+ the matching deallocation function (if any) shall be non-deleted and
4905
+ accessible from the point where the *new-expression* appears.
4906
 
4907
  [*Example 7*:
4908
 
4909
  ``` cpp
4910
  struct S {
 
4943
  ```
4944
 
4945
  The first alternative is a *single-object delete expression*, and the
4946
  second is an *array delete expression*. Whenever the `delete` keyword is
4947
  immediately followed by empty square brackets, it shall be interpreted
4948
+ as the second alternative.[^23]
4949
 
4950
+ If the operand is of class type, it is contextually implicitly converted
4951
+ [[conv]] to a pointer to object type and the converted operand is used
4952
+ in place of the original operand for the remainder of this subclause.
4953
+ Otherwise, it shall be a prvalue of pointer to object type. The
4954
+ *delete-expression* has type `void`.
4955
 
4956
+ In a single-object delete expression, the value of the operand of
4957
+ `delete` may be a null pointer value, a pointer value that resulted from
4958
+ a previous non-array *new-expression*, or a pointer to a base class
4959
+ subobject of an object created by such a *new-expression*. If not, the
4960
+ behavior is undefined. In an array delete expression, the value of the
4961
+ operand of `delete` may be a null pointer value or a pointer value that
4962
+ resulted from a previous array *new-expression* whose allocation
4963
+ function was not a non-allocating form [[new.delete.placement]].[^24]
 
 
 
 
 
 
4964
 
4965
  If not, the behavior is undefined.
4966
 
4967
  [*Note 1*: This means that the syntax of the *delete-expression* must
4968
  match the type of the object allocated by `new`, not the syntax of the
 
4980
  object to be deleted and the static type shall have a virtual destructor
4981
  or the behavior is undefined. In an array delete expression, if the
4982
  dynamic type of the object to be deleted is not similar to its static
4983
  type, the behavior is undefined.
4984
 
 
 
 
4985
  If the object being deleted has incomplete class type at the point of
4986
+ deletion, the program is ill-formed.
 
4987
 
4988
  If the value of the operand of the *delete-expression* is not a null
4989
  pointer value and the selected deallocation function (see below) is not
4990
+ a destroying operator delete, evaluating the *delete-expression* invokes
4991
+ the destructor (if any) for the object or the elements of the array
4992
+ being deleted. The destructor shall be accessible from the point where
4993
+ the *delete-expression* appears. In the case of an array, the elements
4994
+ are destroyed in order of decreasing address (that is, in reverse order
4995
+ of the completion of their constructor; see  [[class.base.init]]).
4996
 
4997
  If the value of the operand of the *delete-expression* is not a null
4998
  pointer value, then:
4999
 
5000
  - If the allocation call for the *new-expression* for the object to be
 
5051
 
5052
  [*Note 5*: If only a placement deallocation function is found in a
5053
  class, the program is ill-formed because the lookup set is empty
5054
  [[basic.lookup]]. — *end note*]
5055
 
5056
+ The deallocation function to be called is selected as follows:
 
5057
 
5058
  - If any of the deallocation functions is a destroying operator delete,
5059
  all deallocation functions that are not destroying operator deletes
5060
  are eliminated from further consideration.
5061
  - If the type has new-extended alignment, a function with a parameter of
 
5071
  or a (possibly multidimensional) array thereof, the function with a
5072
  parameter of type `std::size_t` is selected.
5073
  - Otherwise, it is unspecified whether a deallocation function with a
5074
  parameter of type `std::size_t` is selected.
5075
 
5076
+ Unless the deallocation function is selected at the point of definition
5077
+ of the dynamic type’s virtual destructor, the selected deallocation
5078
+ function shall be accessible from the point where the
5079
+ *delete-expression* appears.
5080
+
5081
  For a single-object delete expression, the deleted object is the object
5082
  A pointed to by the operand if the static type of A does not have a
5083
  virtual destructor, and the most-derived object of A otherwise.
5084
 
5085
  [*Note 6*: If the deallocation function is not a destroying operator
 
5110
  function, and either the first argument was not the result of a prior
5111
  call to a replaceable allocation function or the second or third
5112
  argument was not the corresponding argument in said call, the behavior
5113
  is undefined [[new.delete.single]], [[new.delete.array]]. — *end note*]
5114
 
5115
+ #### The reflection operator <a id="expr.reflect">[[expr.reflect]]</a>
5116
+
5117
+ ``` bnf
5118
+ reflect-expression:
5119
+ '^^' '::'
5120
+ '^^' reflection-name
5121
+ '^^' type-id
5122
+ '^^' id-expression
5123
+ ```
5124
+
5125
+ ``` bnf
5126
+ reflection-name:
5127
+ nested-name-specifierₒₚₜ identifier
5128
+ nested-name-specifier template identifier
5129
+ ```
5130
+
5131
+ The unary `^^` operator, called the *reflection operator*, yields a
5132
+ prvalue of type `std::meta::info` [[basic.fundamental]].
5133
+
5134
+ [*Note 1*: This document places no restriction on representing, by
5135
+ reflections, constructs not described by this document or using the
5136
+ names of such constructs as operands of
5137
+ *reflect-expression*s. — *end note*]
5138
+
5139
+ The component names of a *reflection-name* are those of its
5140
+ *nested-name-specifier* (if any) and its *identifier*. The terminal name
5141
+ of a *reflection-name* of the form *nested-name-specifier* `template`
5142
+ *identifier* shall denote a template.
5143
+
5144
+ A *reflect-expression* is parsed as the longest possible sequence of
5145
+ tokens that could syntactically form a *reflect-expression*. An
5146
+ unparenthesized *reflect-expression* that represents a template shall
5147
+ not be followed by `<`.
5148
+
5149
+ [*Example 1*:
5150
+
5151
+ ``` cpp
5152
+ static_assert(std::meta::is_type(^^int())); // ^^ applies to the type-id int()
5153
+
5154
+ template<bool> struct X {};
5155
+ consteval bool operator<(std::meta::info, X<false>) { return false; }
5156
+ consteval void g(std::meta::info r, X<false> xv) {
5157
+ r == ^^int && true; // error: ^^ applies to the type-id int&&
5158
+ r == ^^int & true; // error: ^^ applies to the type-id int&
5159
+ r == (^^int) && true; // OK
5160
+ r == ^^int &&&& true; // error: int &&&& is not a valid type-id
5161
+ ^^X < xv; // error: reflect-expression that represents a template is followed by <
5162
+ (^^X) < xv; // OK
5163
+ ^^X<true> < xv; // OK
5164
+ }
5165
+ ```
5166
+
5167
+ — *end example*]
5168
+
5169
+ A *reflect-expression* of the form `^^ ::` represents the global
5170
+ namespace.
5171
+
5172
+ If a *reflect-expression* R matches the form `^^ reflection-name`, it is
5173
+ interpreted as such; the *identifier* is looked up and the
5174
+ representation of R is determined as follows:
5175
+
5176
+ - If lookup finds a declaration that replaced a *using-declarator*
5177
+ during a single search [[basic.lookup.general]], [[namespace.udecl]],
5178
+ R is ill-formed.
5179
+ \[*Example 2*:
5180
+ ``` cpp
5181
+ struct A { struct S {}; };
5182
+ struct B : A { using A::S; };
5183
+ constexpr std::meta::info r1 = ^^B::S; // error: A::S found through using-declarator
5184
+
5185
+ struct C : virtual B { struct S {}; };
5186
+ struct D : virtual B, C {};
5187
+ D::S s; // OK, names C::S per [class.member.lookup]
5188
+ constexpr std::meta::info r2 = ^^D::S; // OK, result C::S not found through using-declarator
5189
+ ```
5190
+
5191
+ — *end example*]
5192
+ - Otherwise, if lookup finds a namespace alias [[namespace.alias]], R
5193
+ represents that namespace alias.
5194
+ - Otherwise, if lookup finds a namespace [[basic.namespace]], R
5195
+ represents that namespace.
5196
+ - Otherwise, if lookup finds a concept [[temp.concept]], R represents
5197
+ the denoted concept.
5198
+ - Otherwise, if lookup finds a template [[temp.names]], the
5199
+ representation of R is determined as follows:
5200
+ - If lookup finds an injected-class-name [[class.pre]], then:
5201
+ - If the *reflection-name* is of the form
5202
+ `nested-name-specifier template identifier`, then R represents the
5203
+ class template named by the injected-class-name.
5204
+ - Otherwise, the injected-class-name shall be unambiguous when
5205
+ considered as a *type-name* and R represents the class template
5206
+ specialization so named.
5207
+ - Otherwise, if lookup finds an overload set, that overload set shall
5208
+ contain only declarations of a unique function template F; R
5209
+ represents F.
5210
+ - Otherwise, if lookup finds a class template, variable template, or
5211
+ alias template, R represents that template. \[*Note 2*: Lookup never
5212
+ finds a partial or explicit specialization. — *end note*]
5213
+ - Otherwise, if lookup finds a type alias A, R represents the underlying
5214
+ entity of A if A was introduced by the declaration of a template
5215
+ parameter; otherwise, R represents A.
5216
+ - Otherwise, if lookup finds a class or an enumeration, R represents the
5217
+ denoted type.
5218
+ - Otherwise, if lookup finds a class member of an anonymous union
5219
+ [[class.union.anon]], R represents that class member.
5220
+ - Otherwise, the *reflection-name* shall be an *id-expression* `I` and R
5221
+ is `^^ I` (see below).
5222
+
5223
+ A *reflect-expression* R of the form `^^ type-id` represents an entity
5224
+ determined as follows:
5225
+
5226
+ - If the *type-id* designates a placeholder type
5227
+ [[dcl.spec.auto.general]], R is ill-formed.
5228
+ - Otherwise, if the *type-id* names a type alias that is a
5229
+ specialization of an alias template [[temp.alias]], R represents that
5230
+ type alias.
5231
+ - Otherwise, R represents the type denoted by the *type-id*.
5232
+
5233
+ A *reflect-expression* R of the form `^^ id-expression` represents an
5234
+ entity determined as follows:
5235
+
5236
+ - If the *id-expression* denotes
5237
+ - a variable declared by an *init-capture*
5238
+ [[expr.prim.lambda.capture]],
5239
+ - a function-local predefined variable [[dcl.fct.def.general]],
5240
+ - a local parameter introduced by a *requires-expression*
5241
+ [[expr.prim.req]], or
5242
+ - a local entity E [[basic.pre]] for which a lambda scope intervenes
5243
+ between the point at which E was introduced and R,
5244
+
5245
+ then R is ill-formed.
5246
+ - Otherwise, if the *id-expression* denotes an overload set S, overload
5247
+ resolution for the expression `&S` with no target shall select a
5248
+ unique function [[over.over]]; R represents that function.
5249
+ - Otherwise, if the *id-expression* denotes a variable, structured
5250
+ binding, enumerator, or non-static data member, R represents that
5251
+ entity.
5252
+ - Otherwise, R is ill-formed. \[*Note 3*: This includes
5253
+ *unqualified-id*s that name a constant template parameter and
5254
+ *pack-index-expression*s. — *end note*]
5255
+
5256
+ The *id-expression* of a *reflect-expression* is an unevaluated operand
5257
+ [[expr.context]].
5258
+
5259
+ [*Example 3*:
5260
+
5261
+ ``` cpp
5262
+ template<typename T> void fn() requires (^^T != ^^int);
5263
+ template<typename T> void fn() requires (^^T == ^^int);
5264
+ template<typename T> void fn() requires (sizeof(T) == sizeof(int));
5265
+
5266
+ constexpr std::meta::info a = ^^fn<char>; // OK
5267
+ constexpr std::meta::info b = ^^fn<int>; // error: ambiguous
5268
+
5269
+ constexpr std::meta::info c = ^^std::vector; // OK
5270
+
5271
+ template<typename T>
5272
+ struct S {
5273
+ static constexpr std::meta::info r = ^^T;
5274
+ using type = T;
5275
+ };
5276
+ static_assert(S<int>::r == ^^int);
5277
+ static_assert(^^S<int>::type != ^^int);
5278
+
5279
+ typedef struct X {} Y;
5280
+ typedef struct Z {} Z;
5281
+ constexpr std::meta::info e = ^^Y; // OK, represents the type alias Y
5282
+ constexpr std::meta::info f = ^^Z; // OK, represents the type alias Z, not the type[basic.lookup.general]
5283
+ ```
5284
+
5285
+ — *end example*]
5286
 
5287
  ### Explicit type conversion (cast notation) <a id="expr.cast">[[expr.cast]]</a>
5288
 
5289
  The result of the expression `(T)` *cast-expression* is of type `T`. The
5290
  result is an lvalue if `T` is an lvalue reference type or an rvalue
 
5334
  of a derived class type, respectively.
5335
 
5336
  If a conversion can be interpreted in more than one of the ways listed
5337
  above, the interpretation that appears first in the list is used, even
5338
  if a cast resulting from that interpretation is ill-formed. If a
5339
+ `static_cast` followed by a `const_cast` is used and the conversion can
5340
+ be interpreted in more than one way as such, the conversion is
5341
+ ill-formed.
5342
 
5343
  [*Example 1*:
5344
 
5345
  ``` cpp
5346
  struct A { };
 
5348
  struct I2 : A { };
5349
  struct D : I1, I2 { };
5350
  A* foo( D* p ) {
5351
  return (A*)( p ); // ill-formed static_cast interpretation
5352
  }
5353
+
5354
+ int*** ptr = 0;
5355
+ auto t = (int const*const*const*)ptr; // OK, const_cast interpretation
5356
+
5357
+ struct S {
5358
+ operator const int*();
5359
+ operator volatile int*();
5360
+ };
5361
+ int *p = (int*)S(); // error: two possible interpretations using static_cast followed by const_cast
5362
  ```
5363
 
5364
  — *end example*]
5365
 
5366
  The operand of a cast using the cast notation can be a prvalue of type
 
5370
  incomplete, it is unspecified whether the `static_cast` or the
5371
  `reinterpret_cast` interpretation is used, even if there is an
5372
  inheritance relationship between the two classes.
5373
 
5374
  [*Note 2*: For example, if the classes were defined later in the
5375
+ translation unit, a multi-pass compiler could validly interpret a cast
5376
+ between pointers to the classes as if the class types were complete at
5377
+ the point of the cast. — *end note*]
5378
 
5379
  ### Pointer-to-member operators <a id="expr.mptr.oper">[[expr.mptr.oper]]</a>
5380
 
5381
  The pointer-to-member operators `->*` and `.*` group left-to-right.
5382
 
 
5385
  cast-expression
5386
  pm-expression '.*' cast-expression
5387
  pm-expression '->*' cast-expression
5388
  ```
5389
 
5390
+ The binary operator `.*` binds its second operand, which shall be a
5391
+ prvalue of type “pointer to member of `T`” to its first operand, which
5392
+ shall be a glvalue of class `T` or of a class of which `T` is an
5393
+ unambiguous and accessible base class. The result is an object or a
5394
+ function of the type specified by the second operand.
5395
 
5396
+ The binary operator `->*` binds its second operand, which shall be a
5397
+ prvalue of type “pointer to member of `T`” to its first operand, which
5398
+ shall be of type “pointer to `U`” where `U` is either `T` or a class of
5399
+ which `T` is an unambiguous and accessible base class. The expression
5400
+ `E1->*E2` is converted into the equivalent form `(*(E1)).*E2`.
5401
 
5402
  Abbreviating *pm-expression*`.*`*cast-expression* as `E1.*E2`, `E1` is
5403
  called the *object expression*. If the result of `E1` is an object whose
5404
  type is not similar to the type of `E1`, or whose most derived object
5405
  does not contain the member to which `E2` refers, the behavior is
 
5475
 
5476
  The binary `*` operator indicates multiplication.
5477
 
5478
  The binary `/` operator yields the quotient, and the binary `%` operator
5479
  yields the remainder from the division of the first expression by the
5480
+ second. If the second operand of `/` or `%` is zero, the behavior is
5481
+ undefined. For integral operands, the `/` operator yields the algebraic
5482
+ quotient with any fractional part discarded;[^25]
5483
 
5484
  if the quotient `a/b` is representable in the type of the result,
5485
  `(a/b)*b + a%b` is equal to `a`; otherwise, the behavior of both `a/b`
5486
  and `a%b` is undefined.
5487
 
5488
  ### Additive operators <a id="expr.add">[[expr.add]]</a>
5489
 
5490
+ The additive operators `+` and `-` group left-to-right. Each operand
5491
+ shall be a prvalue. If both operands have arithmetic or unscoped
5492
+ enumeration type, the usual arithmetic conversions [[expr.arith.conv]]
5493
+ are performed. Otherwise, if one operand has arithmetic or unscoped
5494
+ enumeration type, integral promotion is applied [[conv.prom]] to that
5495
+ operand. A converted or promoted operand is used in place of the
5496
+ corresponding original operand for the remainder of this section.
5497
 
5498
  ``` bnf
5499
  additive-expression:
5500
  multiplicative-expression
5501
  additive-expression '+' multiplicative-expression
5502
  additive-expression '-' multiplicative-expression
5503
  ```
5504
 
5505
+ For addition, either both operands shall have arithmetic type, or one
5506
+ operand shall be a pointer to a completely-defined object type and the
5507
+ other shall have integral type.
 
5508
 
5509
  For subtraction, one of the following shall hold:
5510
 
5511
+ - both operands have arithmetic type; or
5512
  - both operands are pointers to cv-qualified or cv-unqualified versions
5513
  of the same completely-defined object type; or
5514
  - the left operand is a pointer to a completely-defined object type and
5515
+ the right operand has integral type.
5516
 
5517
  The result of the binary `+` operator is the sum of the operands. The
5518
  result of the binary `-` operator is the difference resulting from the
5519
  subtraction of the second operand from the first.
5520
 
5521
  When an expression `J` that has integral type is added to or subtracted
5522
  from an expression `P` of pointer type, the result has the type of `P`.
5523
 
5524
  - If `P` evaluates to a null pointer value and `J` evaluates to 0, the
5525
  result is a null pointer value.
5526
+ - Otherwise, if `P` points to a (possibly-hypothetical) array element i
5527
+ of an array object `x` with n elements [[dcl.array]],[^26] the
5528
+ expressions `P + J` and `J + P` (where `J` has the value j) point to
5529
+ the (possibly-hypothetical) array element i + j of `x` if
5530
+ 0 ≤ i + j ≤ n and the expression `P - J` points to the
5531
+ (possibly-hypothetical) array element i - j of `x` if 0 ≤ i - j ≤ n.
5532
  - Otherwise, the behavior is undefined.
5533
 
5534
  [*Note 1*: Adding a value other than 0 or 1 to a pointer to a base
5535
  class subobject, a member subobject, or a complete object results in
5536
  undefined behavior. — *end note*]
5537
 
5538
  When two pointer expressions `P` and `Q` are subtracted, the type of the
5539
  result is an *implementation-defined* signed integral type; this type
5540
+ shall be the same type that is named by `std::ptrdiff_t` in the
5541
  `<cstddef>` header [[support.types.layout]].
5542
 
5543
  - If `P` and `Q` both evaluate to null pointer values, the result is 0.
5544
  - Otherwise, if `P` and `Q` point to, respectively, array elements i and
5545
  j of the same array object `x`, the expression `P - Q` has the value
5546
+ i - j. \[*Note 2*: If the value i - j is not in the range of
5547
+ representable values of type `std::ptrdiff_t`, the behavior is
5548
+ undefined [[expr.pre]]. *end note*]
5549
+ - Otherwise, the behavior is undefined.
5550
 
5551
  For addition or subtraction, if the expressions `P` or `Q` have type
5552
  “pointer to cv `T`”, where `T` and the array element type are not
5553
  similar [[conv.qual]], the behavior is undefined.
5554
 
 
5572
  additive-expression
5573
  shift-expression '<<' additive-expression
5574
  shift-expression '>>' additive-expression
5575
  ```
5576
 
5577
+ The operands shall be prvalues of integral or unscoped enumeration type
5578
+ and integral promotions are performed. The type of the result is that of
5579
+ the promoted left operand. The behavior is undefined if the right
5580
+ operand is negative, or greater than or equal to the width of the
5581
+ promoted left operand.
5582
 
5583
  The value of `E1 << E2` is the unique value congruent to `E1` × 2^`E2`
5584
  modulo 2ᴺ, where N is the width of the type of the result.
5585
 
5586
  [*Note 1*: `E1` is left-shifted `E2` bit positions; vacated bits are
5587
  zero-filled. — *end note*]
5588
 
5589
+ The value of `E1 >> E2` is `E1` / 2^`E2`, rounded towards negative
5590
+ infinity.
5591
 
5592
  [*Note 2*: `E1` is right-shifted `E2` bit positions. Right-shift on
5593
  signed integral types is an arithmetic right shift, which performs
5594
  sign-extension. — *end note*]
5595
 
 
5682
  relational-expression '>' compare-expression
5683
  relational-expression '<=' compare-expression
5684
  relational-expression '>=' compare-expression
5685
  ```
5686
 
5687
+ The lvalue-to-rvalue [[conv.lval]] and function-to-pointer [[conv.func]]
5688
+ standard conversions are performed on the operands. If one of the
5689
+ operands is a pointer, the array-to-pointer conversion [[conv.array]] is
5690
+ performed on the other operand.
5691
 
5692
  The converted operands shall have arithmetic, enumeration, or pointer
5693
  type. The operators `<` (less than), `>` (greater than), `<=` (less than
5694
  or equal to), and `>=` (greater than or equal to) all yield `false` or
5695
  `true`. The type of the result is `bool`.
5696
 
5697
  The usual arithmetic conversions [[expr.arith.conv]] are performed on
5698
+ operands of arithmetic or enumeration type. If both converted operands
5699
+ are pointers, pointer conversions [[conv.ptr]], function pointer
5700
+ conversions [[conv.fctptr]], and qualification conversions [[conv.qual]]
5701
+ are performed to bring them to their composite pointer type
5702
+ [[expr.type]]. After conversions, the operands shall have the same type.
5703
 
5704
+ The result of comparing unequal pointers to objects[^27]
5705
 
5706
  is defined in terms of a partial order consistent with the following
5707
  rules:
5708
 
5709
  - If two pointers point to different elements of the same array, or to
 
5723
  `p>q`, `q<=p`, and `q<p` all yield `true` and `p<=q`, `p<q`, `q>=p`, and
5724
  `q>p` all yield `false`. Otherwise, the result of each of the operators
5725
  is unspecified.
5726
 
5727
  [*Note 1*: A relational operator applied to unequal function pointers
5728
+ yields an unspecified result. A pointer value of type “pointer to
5729
+ cv `void`” can point to an object [[basic.compound]]. — *end note*]
5730
 
5731
  If both operands (after conversions) are of arithmetic or enumeration
5732
  type, each of the operators shall yield `true` if the specified
5733
  relationship is true and `false` if it is false.
5734
 
 
5740
  equality-expression '==' relational-expression
5741
  equality-expression '!=' relational-expression
5742
  ```
5743
 
5744
  The `==` (equal to) and the `!=` (not equal to) operators group
5745
+ left-to-right. The lvalue-to-rvalue [[conv.lval]] and
5746
+ function-to-pointer [[conv.func]] standard conversions are performed on
5747
+ the operands. If one of the operands is a pointer or a null pointer
5748
+ constant [[conv.ptr]], the array-to-pointer conversion [[conv.array]] is
5749
+ performed on the other operand.
5750
 
5751
+ The converted operands shall have scalar type. The operators `==` and
 
5752
  `!=` both yield `true` or `false`, i.e., a result of type `bool`. In
5753
  each case below, the operands shall have the same type after the
5754
  specified conversions have been applied.
5755
 
5756
+ If at least one of the converted operands is a pointer, pointer
5757
+ conversions [[conv.ptr]], function pointer conversions [[conv.fctptr]],
5758
+ and qualification conversions [[conv.qual]] are performed on both
5759
+ operands to bring them to their composite pointer type [[expr.type]].
5760
+ Comparing pointers is defined as follows:
5761
 
5762
  - If one pointer represents the address of a complete object, and
5763
  another pointer represents the address one past the last element of a
5764
+ different complete object,[^28] the result of the comparison is
5765
  unspecified.
5766
  - Otherwise, if the pointers are both null, both point to the same
5767
  function, or both represent the same address [[basic.compound]], they
5768
  compare equal.
5769
  - Otherwise, the pointers compare unequal.
 
5823
  — *end example*]
5824
 
5825
  Two operands of type `std::nullptr_t` or one operand of type
5826
  `std::nullptr_t` and the other a null pointer constant compare equal.
5827
 
5828
+ If both operands are of type `std::meta::info`, they compare equal if
5829
+ both operands
5830
+
5831
+ - are null reflection values,
5832
+ - represent values that are template-argument-equivalent [[temp.type]],
5833
+ - represent the same object,
5834
+ - represent the same entity,
5835
+ - represent the same annotation [[dcl.attr.annotation]],
5836
+ - represent the same direct base class relationship, or
5837
+ - represent equal data member descriptions [[class.mem.general]],
5838
+
5839
+ and they compare unequal otherwise.
5840
+
5841
  If two operands compare equal, the result is `true` for the `==`
5842
  operator and `false` for the `!=` operator. If two operands compare
5843
  unequal, the result is `false` for the `==` operator and `true` for the
5844
  `!=` operator. Otherwise, the result of each of the operators is
5845
  unspecified.
 
5994
  but an implicit conversion sequence can only be formed if the
5995
  reference would bind directly.
5996
  - If `E2` is a prvalue or if neither of the conversion sequences above
5997
  can be formed and at least one of the operands has (possibly
5998
  cv-qualified) class type:
5999
+ - if `T1` and `T2` are the same class type (ignoring
6000
+ cv-qualification):
6001
+ - if `T2` is at least as cv-qualified as `T1`, the target type is
6002
  `T2`,
6003
+ - otherwise, no conversion sequence is formed for this operand;
6004
  - otherwise, if `T2` is a base class of `T1`, the target type is *cv1*
6005
+ `T2`, where *cv1* denotes the cv-qualifiers of `T1`;
6006
  - otherwise, the target type is the type that `E2` would have after
6007
  applying the lvalue-to-rvalue [[conv.lval]], array-to-pointer
6008
  [[conv.array]], and function-to-pointer [[conv.func]] standard
6009
  conversions.
6010
 
6011
  Using this process, it is determined whether an implicit conversion
6012
  sequence can be formed from the second operand to the target type
6013
+ determined for the third operand, and vice versa, with the following
6014
+ outcome:
 
 
 
 
 
 
6015
 
6016
+ - If both sequences can be formed, or one can be formed but it is the
6017
+ ambiguous conversion sequence, the program is ill-formed.
6018
+ - If no conversion sequence can be formed, the operands are left
6019
+ unchanged and further checking is performed as described below.
6020
+ - Otherwise, if exactly one conversion sequence can be formed, that
6021
+ conversion is applied to the chosen operand and the converted operand
6022
+ is used in place of the original operand for the remainder of this
6023
+ subclause. \[*Note 3*: The conversion might be ill-formed even if an
6024
+ implicit conversion sequence could be formed. — *end note*]
6025
 
6026
  If the second and third operands are glvalues of the same value category
6027
  and have the same type, the result is of that type and value category
6028
  and it is a bit-field if the second or the third operand is a bit-field,
6029
  or if both are bit-fields.
 
6035
  the overload resolution fails, the program is ill-formed. Otherwise, the
6036
  conversions thus determined are applied, and the converted operands are
6037
  used in place of the original operands for the remainder of this
6038
  subclause.
6039
 
6040
+ Array-to-pointer [[conv.array]] and function-to-pointer [[conv.func]]
6041
+ standard conversions are performed on the second and third operands.
6042
+ After those conversions, one of the following shall hold:
 
6043
 
6044
  - The second and third operands have the same type; the result is of
6045
+ that type and the result is copy-initialized using the selected
6046
  operand.
6047
  - The second and third operands have arithmetic or enumeration type; the
6048
  usual arithmetic conversions [[expr.arith.conv]] are performed to
6049
  bring them to a common type, and the result is of that type.
6050
  - One or both of the second and third operands have pointer type;
6051
+ lvalue-to-rvalue [[conv.lval]], pointer [[conv.ptr]], function pointer
6052
  [[conv.fctptr]], and qualification conversions [[conv.qual]] are
6053
  performed to bring them to their composite pointer type [[expr.type]].
6054
  The result is of the composite pointer type.
6055
  - One or both of the second and third operands have pointer-to-member
6056
+ type; lvalue-to-rvalue [[conv.lval]], pointer to member [[conv.mem]],
6057
+ function pointer [[conv.fctptr]], and qualification conversions
6058
  [[conv.qual]] are performed to bring them to their composite pointer
6059
  type [[expr.type]]. The result is of the composite pointer type.
6060
  - Both the second and third operands have type `std::nullptr_t` or one
6061
  has that type and the other is a null pointer constant. The result is
6062
  of type `std::nullptr_t`.
6063
 
6064
  ### Yielding a value <a id="expr.yield">[[expr.yield]]</a>
6065
 
6066
  ``` bnf
6067
  yield-expression:
6068
+ co_yield assignment-expression
6069
+ co_yield braced-init-list
6070
  ```
6071
 
6072
  A *yield-expression* shall appear only within a suspension context of a
6073
  function [[expr.await]]. Let *e* be the operand of the
6074
  *yield-expression* and *p* be an lvalue naming the promise object of the
 
6120
  throw assignment-expressionₒₚₜ
6121
  ```
6122
 
6123
  A *throw-expression* is of type `void`.
6124
 
6125
+ A *throw-expression* with an operand throws an exception
6126
+ [[except.throw]]. The array-to-pointer [[conv.array]] and
6127
+ function-to-pointer [[conv.func]] standard conversions are performed on
6128
+ the operand. The type of the exception object is determined by removing
6129
+ any top-level *cv-qualifier*s from the type of the (possibly converted)
6130
+ operand. The exception object is copy-initialized [[dcl.init.general]]
6131
+ from the (possibly converted) operand.
6132
 
6133
  A *throw-expression* with no operand rethrows the currently handled
6134
+ exception [[except.handle]]. If no exception is presently being handled,
6135
+ the function `std::terminate` is invoked [[except.terminate]].
6136
+ Otherwise, the exception is reactivated with the existing exception
6137
+ object; no new exception object is created. The exception is no longer
6138
+ considered to be caught.
6139
 
6140
  [*Example 1*:
6141
 
6142
  An exception handler that cannot completely handle the exception itself
6143
  can be written like this:
 
6151
  }
6152
  ```
6153
 
6154
  — *end example*]
6155
 
6156
+ ### Assignment and compound assignment operators <a id="expr.assign">[[expr.assign]]</a>
 
 
 
 
6157
 
6158
  The assignment operator (`=`) and the compound assignment operators all
6159
  group right-to-left. All require a modifiable lvalue as their left
6160
  operand; their result is an lvalue of the type of the left operand,
6161
  referring to the left operand. The result in all cases is a bit-field if
 
6181
  ``` bnf
6182
  assignment-operator: one of
6183
  '= *= /= %= += -= >>= <<= &= ^= |='
6184
  ```
6185
 
6186
+ In simple assignment (`=`), let `V` be the result of the right operand;
6187
+ the object referred to by the left operand is modified [[defns.access]]
6188
+ by replacing its value with `V` or, if the object is of integer type,
6189
+ with the value congruent [[basic.fundamental]] to `V`.
6190
 
6191
  If the right operand is an expression, it is implicitly converted
6192
  [[conv]] to the cv-unqualified type of the left operand.
6193
 
6194
  When the left operand of an assignment operator is a bit-field that
 
6218
  [*Note 3*: This restriction applies to the relationship between the
6219
  left and right sides of the assignment operation; it is not a statement
6220
  about how the target of the assignment can be aliased in general. See 
6221
  [[basic.lval]]. — *end note*]
6222
 
6223
+ A *braced-init-list* B may appear on the right-hand side of
6224
 
6225
+ - an assignment to a scalar of type `T`, in which case B shall have at
6226
+ most a single element. The meaning of `x = B` is `x = t`, where `t` is
6227
+ an invented temporary variable declared and initialized as `T t = B`.
6228
+ - an assignment to an object of class type, in which case B is passed as
6229
+ the argument to the assignment operator function selected by overload
6230
+ resolution [[over.assign]], [[over.match]].
 
6231
 
6232
  [*Example 1*:
6233
 
6234
  ``` cpp
6235
  complex<double> z;
 
6285
  Certain contexts require expressions that satisfy additional
6286
  requirements as detailed in this subclause; other contexts have
6287
  different semantics depending on whether or not an expression satisfies
6288
  these requirements. Expressions that satisfy these requirements,
6289
  assuming that copy elision [[class.copy.elision]] is not performed, are
6290
+ called constant expressions.
6291
 
6292
  [*Note 1*: Constant expressions can be evaluated during
6293
  translation. — *end note*]
6294
 
6295
  ``` bnf
6296
  constant-expression:
6297
  conditional-expression
6298
  ```
6299
 
6300
+ The *constituent values* of an object o are
6301
+
6302
+ - if o has scalar type, the value of o;
6303
+ - otherwise, the constituent values of any direct subobjects of o other
6304
+ than inactive union members.
6305
+
6306
+ The *constituent references* of an object o are
6307
+
6308
+ - any direct members of o that have reference type, and
6309
+ - the constituent references of any direct subobjects of o other than
6310
+ inactive union members.
6311
+
6312
+ The constituent values and constituent references of a variable `x` are
6313
+ defined as follows:
6314
+
6315
+ - If `x` declares an object, the constituent values and references of
6316
+ that object are constituent values and references of `x`.
6317
+ - If `x` declares a reference, that reference is a constituent reference
6318
+ of `x`.
6319
+
6320
+ For any constituent reference `r` of a variable `x`, if `r` is bound to
6321
+ a temporary object or subobject thereof whose lifetime is extended to
6322
+ that of `r`, the constituent values and references of that temporary
6323
+ object are also constituent values and references of `x`, recursively.
6324
+
6325
+ An object o is *constexpr-referenceable* from a point P if
6326
+
6327
+ - o has static storage duration, or
6328
+ - o has automatic storage duration, and, letting `v` denote
6329
+ - the variable corresponding to o’s complete object or
6330
+ - the variable to whose lifetime that of o is extended,
6331
+
6332
+ the smallest scope enclosing `v` and the smallest scope enclosing P
6333
+ that are neither
6334
+ - block scopes nor
6335
+ - function parameter scopes associated with a
6336
+ *requirement-parameter-list*
6337
+
6338
+ are the same function parameter scope.
6339
+
6340
+ [*Example 1*:
6341
+
6342
+ ``` cpp
6343
+ struct A {
6344
+ int m;
6345
+ const int& r;
6346
+ };
6347
+ void f() {
6348
+ static int sx;
6349
+ thread_local int tx; // tx is never constexpr-referenceable
6350
+ int ax;
6351
+ A aa = {1, 2};
6352
+ static A sa = {3, 4};
6353
+ // The objects sx, ax, and aa.m, sa.m, and the temporaries to which aa.r and sa.r are bound, are constexpr-referenceable.
6354
+ auto lambda = [] {
6355
+ int ay;
6356
+ // The objects sx, sa.m, and ay (but not ax or aa), and the
6357
+ // temporary to which sa.r is bound, are constexpr-referenceable.
6358
+ };
6359
+ }
6360
+ ```
6361
+
6362
+ — *end example*]
6363
+
6364
+ An object or reference `x` is *constexpr-representable* at a point P if,
6365
+ for each constituent value of `x` that points to or past an object o,
6366
+ and for each constituent reference of `x` that refers to an object o, o
6367
+ is constexpr-referenceable from P.
6368
+
6369
+ A variable `v` is *constant-initializable* if
6370
 
 
 
6371
  - the full-expression of its initialization is a constant expression
6372
+ when interpreted as a *constant-expression* with all contract
6373
+ assertions using the ignore evaluation semantic
6374
+ [[basic.contract.eval]], \[*Note 2*: Within this evaluation,
6375
+ `std::is_constant_evaluated()` [[meta.const.eval]] returns
6376
+ `true`. *end note*] \[*Note 3*: The initialization, when evaluated,
6377
+ can still evaluate contract assertions with other evaluation
6378
+ semantics, resulting in a diagnostic or ill-formed program if a
6379
+ contract violation occurs. — *end note*]
6380
+ - immediately after the initializing declaration of `v`, the object or
6381
+ reference `x` declared by `v` is constexpr-representable, and
6382
+ - if `x` has static or thread storage duration, `x` is
6383
+ constexpr-representable at the nearest point whose immediate scope is
6384
+ a namespace scope that follows the initializing declaration of `v`.
6385
+
6386
+ A constant-initializable variable is *constant-initialized* if either it
6387
+ has an initializer or its type is const-default-constructible
6388
+ [[dcl.init.general]].
6389
+
6390
+ [*Example 2*:
6391
+
6392
+ ``` cpp
6393
+ void f() {
6394
+ int ax = 0; // ax is constant-initialized
6395
+ thread_local int tx = 0; // tx is constant-initialized
6396
+ static int sx; // sx is not constant-initialized
6397
+ static int& rss = sx; // rss is constant-initialized
6398
+ static int& rst = tx; // rst is not constant-initialized
6399
+ static int& rsa = ax; // rsa is not constant-initialized
6400
+ thread_local int& rts = sx; // rts is constant-initialized
6401
+ thread_local int& rtt = tx; // rtt is not constant-initialized
6402
+ thread_local int& rta = ax; // rta is not constant-initialized
6403
+ int& ras = sx; // ras is constant-initialized
6404
+ int& rat = tx; // rat is not constant-initialized
6405
+ int& raa = ax; // raa is constant-initialized
6406
+ }
6407
+ ```
6408
+
6409
+ — *end example*]
6410
 
6411
  A variable is *potentially-constant* if it is constexpr or it has
6412
  reference or non-volatile const-qualified integral or enumeration type.
6413
 
6414
  A constant-initialized potentially-constant variable V is *usable in
 
6417
 
6418
  - V is constexpr,
6419
  - V is not initialized to a TU-local value, or
6420
  - P is in the same translation unit as D.
6421
 
6422
+ An object or reference is *potentially usable in constant expressions*
6423
+ at point P if it is
6424
 
6425
+ - the object or reference declared by a variable that is usable in
6426
+ constant expressions at P,
 
6427
  - a temporary object of non-volatile const-qualified literal type whose
6428
  lifetime is extended [[class.temporary]] to that of a variable that is
6429
+ usable in constant expressions at P,
6430
+ - a template parameter object [[temp.param]],
6431
+ - a string literal object [[lex.string]],
6432
+ - a non-mutable subobject of any of the above, or
6433
+ - a reference member of any of the above.
6434
+
6435
+ An object or reference is *usable in constant expressions* at point P if
6436
+ it is an object or reference that is potentially usable in constant
6437
+ expressions at P and is constexpr-representable at P.
6438
+
6439
+ [*Example 3*:
6440
+
6441
+ ``` cpp
6442
+ struct A {
6443
+ int* const & r;
6444
+ };
6445
+ void f(int x) {
6446
+ constexpr A a = {&x};
6447
+ static_assert(a.r == &x); // OK
6448
+ [&] {
6449
+ static_assert(a.r != nullptr); // error: a.r is not usable in constant expressions at this point
6450
+ }();
6451
+ }
6452
+ ```
6453
+
6454
+ — *end example*]
6455
 
6456
  An expression E is a *core constant expression* unless the evaluation of
6457
  E, following the rules of the abstract machine [[intro.execution]],
6458
  would evaluate one of the following:
6459
 
6460
  - `this` [[expr.prim.this]], except
6461
  - in a constexpr function [[dcl.constexpr]] that is being evaluated as
6462
  part of E or
6463
  - when appearing as the *postfix-expression* of an implicit or
6464
  explicit class member access expression [[expr.ref]];
6465
+ - a control flow that passes through a declaration of a block variable
6466
+ [[basic.scope.block]] with static [[basic.stc.static]] or thread
6467
+ [[basic.stc.thread]] storage duration, unless that variable is usable
6468
+ in constant expressions;
6469
+ \[*Example 4*:
6470
  ``` cpp
6471
  constexpr char test() {
6472
  static const int x = 5;
6473
  static constexpr char c[] = "Hello World";
6474
  return *(c + x);
6475
  }
6476
  static_assert(' ' == test());
6477
  ```
6478
 
6479
  — *end example*]
6480
+ - an invocation of a non-constexpr function;[^29]
6481
  - an invocation of an undefined constexpr function;
6482
  - an invocation of an instantiated constexpr function that is not
6483
  constexpr-suitable;
6484
  - an invocation of a virtual function [[class.virtual]] for an object
6485
  whose dynamic type is constexpr-unknown;
6486
  - an expression that would exceed the implementation-defined limits (see
6487
  [[implimits]]);
6488
+ - an operation that would have undefined or erroneous behavior as
6489
+ specified in [[intro]] through [[\lastcorechapter]];[^30]
6490
  - an lvalue-to-rvalue conversion [[conv.lval]] unless it is applied to
6491
+ - a glvalue of type cv `std::nullptr_t`,
6492
  - a non-volatile glvalue that refers to an object that is usable in
6493
  constant expressions, or
6494
  - a non-volatile glvalue of literal type that refers to a non-volatile
6495
  object whose lifetime began within the evaluation of E;
6496
  - an lvalue-to-rvalue conversion that is applied to a glvalue that
 
6503
  evaluation of E;
6504
  - in a *lambda-expression*, a reference to `this` or to a variable with
6505
  automatic storage duration defined outside that *lambda-expression*,
6506
  where the reference would be an odr-use
6507
  [[term.odr.use]], [[expr.prim.lambda]];
6508
+ \[*Example 5*:
6509
  ``` cpp
6510
  void g() {
6511
  const int n = 0;
6512
  [=] {
6513
  constexpr int i = n; // OK, n is not odr-used here
 
6515
  };
6516
  }
6517
  ```
6518
 
6519
  — *end example*]
6520
+ \[*Note 4*:
6521
  If the odr-use occurs in an invocation of a function call operator of
6522
  a closure type, it no longer refers to `this` or to an enclosing
6523
+ variable with automatic storage duration due to the transformation
6524
  [[expr.prim.lambda.capture]] of the *id-expression* into an access of
6525
  the corresponding data member.
6526
+ \[*Example 6*:
6527
  ``` cpp
6528
  auto monad = [](auto v) { return [=] { return v; }; };
6529
  auto bind = [](auto m) {
6530
  return [=](auto fvm) { return fvm(m()); };
6531
  };
 
6534
  static_assert(bind(monad(2))(monad)() == monad(2)());
6535
  ```
6536
 
6537
  — *end example*]
6538
  — *end note*]
6539
+ - a conversion from a prvalue `P` of type “pointer to cv `void` to a
6540
+ type “*cv1* pointer to `T`”, where `T` is not *cv2* `void`, unless `P`
6541
+ is a null pointer value or points to an object whose type is similar
6542
+ to `T`;
6543
  - a `reinterpret_cast` [[expr.reinterpret.cast]];
6544
  - a modification of an object
6545
+ [[expr.assign]], [[expr.post.incr]], [[expr.pre.incr]] unless it is
6546
  applied to a non-volatile lvalue of literal type that refers to a
6547
  non-volatile object whose lifetime began within the evaluation of E;
6548
  - an invocation of a destructor [[class.dtor]] or a function call whose
6549
  *postfix-expression* names a pseudo-destructor [[expr.call]], in
6550
  either case for an object whose lifetime did not begin within the
6551
  evaluation of E;
6552
+ - a *new-expression* [[expr.new]], unless either
6553
+ - the selected allocation function is a replaceable global allocation
6554
+ function [[new.delete.single]], [[new.delete.array]] and the
6555
+ allocated storage is deallocated within the evaluation of E, or
6556
+ - the selected allocation function is a non-allocating form
6557
+ [[new.delete.placement]] with an allocated type `T`, where
6558
+ - the placement argument to the *new-expression* points to an object
6559
+ whose type is similar to `T` [[conv.qual]] or, if `T` is an array
6560
+ type, to the first element of an object of a type similar to `T`,
6561
+ and
6562
+ - the placement argument points to storage whose duration began
6563
+ within the evaluation of E;
6564
  - a *delete-expression* [[expr.delete]], unless it deallocates a region
6565
  of storage allocated within the evaluation of E;
6566
  - a call to an instance of `std::allocator<T>::allocate`
6567
  [[allocator.members]], unless the allocated storage is deallocated
6568
  within the evaluation of E;
6569
  - a call to an instance of `std::allocator<T>::deallocate`
6570
  [[allocator.members]], unless it deallocates a region of storage
6571
  allocated within the evaluation of E;
6572
+ - a construction of an exception object, unless the exception object and
6573
+ all of its implicit copies created by invocations of
6574
+ `std::current_exception` or `std::rethrow_exception` [[propagation]]
6575
+ are destroyed within the evaluation of E;
6576
  - an *await-expression* [[expr.await]];
6577
  - a *yield-expression* [[expr.yield]];
6578
  - a three-way comparison [[expr.spaceship]], relational [[expr.rel]], or
6579
  equality [[expr.eq]] operator where the result is unspecified;
 
6580
  - a `dynamic_cast` [[expr.dynamic.cast]] or `typeid` [[expr.typeid]]
6581
  expression on a glvalue that refers to an object whose dynamic type is
6582
+ constexpr-unknown;
6583
+ - a `dynamic_cast` [[expr.dynamic.cast]] expression, `typeid`
6584
+ [[expr.typeid]] expression, or `new-expression` [[expr.new]] that
6585
+ would throw an exception where no definition of the exception type is
6586
+ reachable;
6587
+ - an expression that would produce an injected declaration (see below),
6588
+ unless E is the corresponding expression of a
6589
+ *consteval-block-declaration* [[dcl.pre]];
6590
  - an *asm-declaration* [[dcl.asm]];
6591
  - an invocation of the `va_arg` macro [[cstdarg.syn]];
6592
  - a non-constant library call [[defns.nonconst.libcall]]; or
6593
+ - a `goto` statement [[stmt.goto]]. \[*Note 5*: A `goto` statement
6594
+ introduced by equivalence [[stmt]] is not in scope. For example, a
6595
+ `while` statement [[stmt.while]] can be executed during constant
6596
+ evaluation. — *end note*]
6597
+
6598
+ It is *implementation-defined* whether E is a core constant expression
6599
+ if E satisfies the constraints of a core constant expression, but
6600
+ evaluation of E has runtime-undefined behavior.
6601
 
6602
  It is unspecified whether E is a core constant expression if E satisfies
6603
  the constraints of a core constant expression, but evaluation of E would
6604
  evaluate
6605
 
6606
  - an operation that has undefined behavior as specified in [[library]]
6607
+ through [[exec]] or
6608
+ - an invocation of the `va_start` macro [[cstdarg.syn]].
 
 
 
 
 
 
 
6609
 
6610
+ [*Example 7*:
6611
 
6612
  ``` cpp
6613
  int x; // not constant
6614
  struct A {
6615
  constexpr A(bool b) : m(b?42:x) { }
 
6650
  — *end example*]
6651
 
6652
  For the purposes of determining whether an expression E is a core
6653
  constant expression, the evaluation of the body of a member function of
6654
  `std::allocator<T>` as defined in [[allocator.members]], where `T` is a
6655
+ literal type, is ignored.
 
 
 
 
6656
 
6657
  For the purposes of determining whether E is a core constant expression,
6658
  the evaluation of a call to a trivial copy/move constructor or copy/move
6659
  assignment operator of a union is considered to copy/move the active
6660
  member of the union, if any.
6661
 
6662
+ [*Note 6*: The copy/move of the active member is
6663
  trivial. — *end note*]
6664
 
6665
+ For the purposes of determining whether E is a core constant expression,
6666
+ the evaluation of an *id-expression* that names a structured binding `v`
6667
+ [[dcl.struct.bind]] has the following semantics:
6668
+
6669
+ - If `v` is an lvalue referring to the object bound to an invented
6670
+ reference `r`, the behavior is as if `r` were nominated.
6671
+ - Otherwise, if `v` names an array element or class member, the behavior
6672
+ is that of evaluating `e[i]` or `e.m`, respectively, where e is the
6673
+ name of the variable initialized from the initializer of the
6674
+ structured binding declaration, and i is the index of the element
6675
+ referred to by `v` or m is the name of the member referred to by `v`,
6676
+ respectively.
6677
+
6678
+ [*Example 8*:
6679
+
6680
+ ``` cpp
6681
+ #include <tuple>
6682
+ struct S {
6683
+ mutable int m;
6684
+ constexpr S(int m): m(m) {}
6685
+ virtual int g() const;
6686
+ };
6687
+ void f(std::tuple<S&> t) {
6688
+ auto [r] = t;
6689
+ static_assert(r.g() >= 0); // error: dynamic type is constexpr-unknown
6690
+ constexpr auto [m] = S(1);
6691
+ static_assert(m == 1); // error: lvalue-to-rvalue conversion on mutable
6692
+ // subobject e.m, where e is a constexpr object of type S
6693
+ using A = int[2];
6694
+ constexpr auto [v0, v1] = A{2, 3};
6695
+ static_assert(v0 + v1 == 5); // OK, equivalent to e[0] + e[1] where e is a constexpr array
6696
+ }
6697
+ ```
6698
+
6699
+ — *end example*]
6700
+
6701
  During the evaluation of an expression E as a core constant expression,
6702
+ all *id-expression*s, *splice-expression*s, and uses of `*this` that
6703
+ refer to an object or reference whose lifetime did not begin with the
6704
+ evaluation of E are treated as referring to a specific instance of that
6705
+ object or reference whose lifetime and that of all subobjects (including
6706
+ all union members) includes the entire constant evaluation. For such an
6707
+ object that is not usable in constant expressions, the dynamic type of
6708
+ the object is *constexpr-unknown*. For such a reference that is not
6709
+ usable in constant expressions, the reference is treated as binding to
6710
+ an unspecified object of the referenced type whose lifetime and that of
6711
+ all subobjects includes the entire constant evaluation and whose dynamic
6712
+ type is constexpr-unknown.
6713
 
6714
+ [*Example 9*:
6715
 
6716
  ``` cpp
6717
  template <typename T, size_t N>
6718
  constexpr size_t array_size(T (&)[N]) {
6719
  return N;
 
6765
  constexpr auto& gallagher = typeid(trident); // error: constexpr-unknown dynamic type
6766
  ```
6767
 
6768
  — *end example*]
6769
 
6770
+ An object `a` is said to have *constant destruction* if
6771
 
6772
  - it is not of class type nor (possibly multidimensional) array thereof,
6773
  or
6774
  - it is of class type or (possibly multidimensional) array thereof, that
6775
+ class type has a constexpr destructor [[dcl.constexpr]], and for a
6776
+ hypothetical expression E whose only effect is to destroy `a`, E would
6777
+ be a core constant expression if the lifetime of `a` and its
6778
+ non-mutable subobjects (but not its mutable subobjects) were
6779
+ considered to start within E.
6780
 
6781
  An *integral constant expression* is an expression of integral or
6782
  unscoped enumeration type, implicitly converted to a prvalue, where the
6783
  converted expression is a core constant expression.
6784
 
6785
+ [*Note 7*: Such expressions can be used as bit-field lengths
6786
  [[class.bit]], as enumerator initializers if the underlying type is not
6787
  fixed [[dcl.enum]], and as alignments [[dcl.align]]. — *end note*]
6788
 
6789
  If an expression of literal class type is used in a context where an
6790
  integral constant expression is required, then that expression is
6791
  contextually implicitly converted [[conv]] to an integral or unscoped
6792
  enumeration type and the selected conversion function shall be
6793
  `constexpr`.
6794
 
6795
+ [*Example 10*:
6796
 
6797
  ``` cpp
6798
  struct A {
6799
  constexpr A(int i) : val(i) { }
6800
  constexpr operator int() const { return val; }
 
6819
  - function-to-pointer conversions [[conv.func]],
6820
  - qualification conversions [[conv.qual]],
6821
  - integral promotions [[conv.prom]],
6822
  - integral conversions [[conv.integral]] other than narrowing
6823
  conversions [[dcl.init.list]],
6824
+ - floating-point promotions [[conv.fpprom]],
6825
+ - floating-point conversions [[conv.double]] where the source value can
6826
+ be represented exactly in the destination type,
6827
  - null pointer conversions [[conv.ptr]] from `std::nullptr_t`,
6828
  - null member pointer conversions [[conv.mem]] from `std::nullptr_t`,
6829
  and
6830
  - function pointer conversions [[conv.fctptr]],
6831
 
6832
  and where the reference binding (if any) binds directly.
6833
 
6834
+ [*Note 8*: Such expressions can be used in `new` expressions
6835
  [[expr.new]], as case expressions [[stmt.switch]], as enumerator
6836
  initializers if the underlying type is fixed [[dcl.enum]], as array
6837
+ bounds [[dcl.array]], as constant template arguments [[temp.arg]], and
6838
+ as the constant expression of a *splice-specifier*
6839
+ [[basic.splice]]. — *end note*]
6840
 
6841
  A *contextually converted constant expression of type `bool`* is an
6842
  expression, contextually converted to `bool` [[conv]], where the
6843
  converted expression is a constant expression and the conversion
6844
  sequence contains only the conversions above.
6845
 
6846
+ A *constant expression* is either
 
 
 
6847
 
6848
+ - a glvalue core constant expression E for which
6849
+ - E refers to a non-immediate function,
6850
+ - E designates an object `o`, and if the complete object of `o` is of
6851
+ consteval-only type then so is E,
6852
+ \[*Example 11*:
6853
+ ``` cpp
6854
+ struct Base { };
6855
+ struct Derived : Base { std::meta::info r; };
 
 
 
 
 
6856
 
6857
+ consteval const Base& fn(const Derived& derived) { return derived; }
 
 
 
6858
 
6859
+ constexpr Derived obj{.r=^^::}; // OK
6860
+ constexpr const Derived& d = obj; // OK
6861
+ constexpr const Base& b = fn(obj); // error: not a constant expression because Derived
6862
+ // is a consteval-only type but Base is not.
6863
+ ```
6864
+
6865
+ — *end example*]
6866
+
6867
+ or
6868
+ - a prvalue core constant expression whose result object [[basic.lval]]
6869
+ satisfies the following constraints:
6870
+ - each constituent reference refers to an object or a non-immediate
6871
+ function,
6872
+ - no constituent value of scalar type is an indeterminate or erroneous
6873
+ value [[basic.indet]],
6874
+ - no constituent value of pointer type is a pointer to an immediate
6875
+ function or an invalid pointer value [[basic.compound]],
6876
+ - no constituent value of pointer-to-member type designates an
6877
+ immediate function, and
6878
+ - unless the value is of consteval-only type,
6879
+ - no constituent value of pointer-to-member type points to a direct
6880
+ member of a consteval-only class type,
6881
+ - no constituent value of pointer type points to or past an object
6882
+ whose complete object is of consteval-only type, and
6883
+ - no constituent reference refers to an object whose complete object
6884
+ is of consteval-only type.
6885
+
6886
+ [*Note 9*: A glvalue core constant expression that either refers to or
6887
  points to an unspecified object is not a constant
6888
  expression. — *end note*]
6889
 
6890
+ [*Example 12*:
6891
 
6892
  ``` cpp
6893
  consteval int f() { return 42; }
6894
  consteval auto g() { return f; }
6895
  consteval int h(int (*p)() = g()) { return p(); }
6896
  constexpr int r = h(); // OK
6897
  constexpr auto e = g(); // error: a pointer to an immediate function is
6898
  // not a permitted result of a constant expression
6899
+
6900
+ struct S {
6901
+ int x;
6902
+ constexpr S() {}
6903
+ };
6904
+ int i() {
6905
+ constexpr S s; // error: s.x has erroneous value
6906
+ }
6907
  ```
6908
 
6909
  — *end example*]
6910
 
6911
  *Recommended practice:* Implementations should provide consistent
6912
  results of floating-point evaluations, irrespective of whether the
6913
  evaluation is performed during translation or during program execution.
6914
 
6915
+ [*Note 10*:
6916
 
6917
  Since this document imposes no restrictions on the accuracy of
6918
  floating-point operations, it is unspecified whether the evaluation of a
6919
  floating-point expression during translation yields the same result as
6920
  the evaluation of the same expression (or the same operations on the
6921
  same values) during program execution.
6922
 
6923
+ [*Example 13*:
6924
 
6925
  ``` cpp
6926
  bool f() {
6927
  char array[1 + int(1 + 0.2 - 0.1 - 0.1)]; // Must be evaluated during translation
6928
  int size = 1 + int(1 + 0.2 - 0.1 - 0.1); // May be evaluated at runtime
 
6951
  function and is not in an immediate function context. An aggregate
6952
  initialization is an immediate invocation if it evaluates a default
6953
  member initializer that has a subexpression that is an
6954
  immediate-escalating expression.
6955
 
6956
+ A potentially-evaluated expression or conversion is
6957
+ *immediate-escalating* if it is neither initially in an immediate
6958
+ function context nor a subexpression of an immediate invocation, and
6959
 
6960
+ - it is an *id-expression* or *splice-expression* that designates an
6961
+ immediate function,
6962
+ - it is an immediate invocation that is not a constant expression, or
6963
+ - it is of consteval-only type [[basic.types.general]].
6964
 
6965
  An *immediate-escalating* function is
6966
 
6967
  - the call operator of a lambda that is not declared with the
6968
  `consteval` specifier,
 
6972
  defined with the `constexpr` specifier.
6973
 
6974
  An immediate-escalating expression shall appear only in an
6975
  immediate-escalating function.
6976
 
6977
+ An *immediate function* is a function that is either
6978
 
6979
  - declared with the `consteval` specifier, or
6980
+ - an immediate-escalating function `F` whose function body contains
6981
+ either
6982
+ - an immediate-escalating expression or
6983
+ - a definition of a non-constexpr variable with consteval-only type
6984
 
6985
+ whose innermost enclosing non-block scope is `F`’s function parameter
6986
+ scope.
6987
+
6988
+ [*Example 14*:
6989
 
6990
  ``` cpp
6991
  consteval int id(int i) { return i; }
6992
  constexpr char id(char c) { return c; }
6993
 
 
7017
 
7018
  int x = 0;
7019
 
7020
  template<class T>
7021
  constexpr T h(T t = id(x)) { // h<int> is not an immediate function
7022
+ // id(x) is not evaluated when parsing the default argument[dcl.fct.default,temp.inst]
7023
  return t;
7024
  }
7025
 
7026
  template<class T>
7027
+ constexpr T hh() { // hh<int> is an immediate function because of the invocation
7028
+ return h<T>(); // of the immediate function id in the default argument of h<int>
7029
  }
7030
 
7031
  int i = hh<int>(); // error: hh<int>() is an immediate-escalating expression
7032
  // outside of an immediate-escalating function
7033
 
 
7038
 
7039
  template<class T>
7040
  constexpr int k(int) { // k<int> is not an immediate function because A(42) is a
7041
  return A(42).y; // constant expression and thus not immediate-escalating
7042
  }
7043
+
7044
+ constexpr int l(int c) pre(c >= 2) {
7045
+ return (c % 2 == 0) ? c / 0 : c;
7046
+ }
7047
+
7048
+ const int i0 = l(0); // dynamic initialization; contract violation or undefined behavior
7049
+ const int i1 = l(1); // static initialization; value of 1 or contract violation at compile time
7050
+ const int i2 = l(2); // dynamic initialization; undefined behavior
7051
+ const int i3 = l(3); // static initialization; value of 3
7052
  ```
7053
 
7054
  — *end example*]
7055
 
7056
  An expression or conversion is *manifestly constant-evaluated* if it is:
 
7059
  - the condition of a constexpr if statement [[stmt.if]], or
7060
  - an immediate invocation, or
7061
  - the result of substitution into an atomic constraint expression to
7062
  determine whether it is satisfied [[temp.constr.atomic]], or
7063
  - the initializer of a variable that is usable in constant expressions
7064
+ or has constant initialization [[basic.start.static]].[^31]
7065
+ \[*Example 15*:
7066
  ``` cpp
7067
  template<bool> struct X {};
7068
  X<std::is_constant_evaluated()> x; // type X<true>
7069
  int y;
7070
  const int a = std::is_constant_evaluated() ? y : 1; // dynamic initialization to 1
 
7083
  int q = p + f(); // m is 17 for this call; initialized to 56
7084
  ```
7085
 
7086
  — *end example*]
7087
 
7088
+ [*Note 11*: Except for a *static_assert-message*, a manifestly
7089
+ constant-evaluated expression is evaluated even in an unevaluated
7090
+ operand [[term.unevaluated.operand]]. — *end note*]
7091
+
7092
+ The evaluation of an expression can introduce one or more *injected
7093
+ declarations*. The evaluation is said to *produce* the declarations.
7094
+
7095
+ [*Note 12*: An invocation of the library function template
7096
+ `std::meta::define_aggregate` produces an injected declaration
7097
+ [[meta.reflection.define.aggregate]]. — *end note*]
7098
+
7099
+ Each such declaration has
7100
+
7101
+ - an associated *synthesized point*, which follows the last
7102
+ non-synthesized program point in the translation unit containing that
7103
+ declaration, and
7104
+ - an associated *characteristic sequence* of values.
7105
+
7106
+ [*Note 13*: Special rules concerning reachability apply to synthesized
7107
+ points [[module.reach]]. — *end note*]
7108
+
7109
+ [*Note 14*: The program is ill-formed if injected declarations with
7110
+ different characteristic sequences define the same entity in different
7111
+ translation units [[basic.def.odr]]. — *end note*]
7112
+
7113
+ A member of an entity defined by an injected declaration shall not have
7114
+ a name reserved to the implementation [[lex.name]]; no diagnostic is
7115
+ required.
7116
+
7117
+ Let C be a *consteval-block-declaration*, the evaluation of whose
7118
+ corresponding expression produces an injected declaration for an entity
7119
+ E. The program is ill-formed if either
7120
+
7121
+ - C is enclosed by a scope associated with E or
7122
+ - letting P be a point whose immediate scope is that to which E belongs,
7123
+ there is a function parameter scope or class scope that encloses
7124
+ exactly one of C or P.
7125
+
7126
+ [*Example 16*:
7127
+
7128
+ ``` cpp
7129
+ struct S0 {
7130
+ consteval {
7131
+ std::meta::define_aggregate(^^S0, {}); // error: scope associated with S0 encloses the consteval block
7132
+ }
7133
+ };
7134
+
7135
+ struct S1;
7136
+ consteval { std::meta::define_aggregate(^^S1, {}); } // OK
7137
+
7138
+ template <std::meta::info R> consteval void tfn1() {
7139
+ std::meta::define_aggregate(R, {});
7140
+ }
7141
+
7142
+ struct S2;
7143
+ consteval { tfn1<^^S2>(); } // OK
7144
+
7145
+ template <std::meta::info R> consteval void tfn2() {
7146
+ consteval { std::meta::define_aggregate(R, {}); }
7147
+ }
7148
+
7149
+ struct S3;
7150
+ consteval { tfn2<^^S3>(); }
7151
+ // error: function parameter scope of tfn2<^^ S3> intervenes between the declaration of S3
7152
+ // and the consteval block that produces the injected declaration
7153
+
7154
+ template <typename> struct TCls {
7155
+ struct S4;
7156
+ static void sfn() requires ([] {
7157
+ consteval { std::meta::define_aggregate(^^S4, {}); }
7158
+ return true;
7159
+ }()) { }
7160
+ };
7161
+
7162
+ consteval { TCls<void>::sfn(); } // error: TCls<void>::S4 is not enclosed by requires-clause lambda
7163
+
7164
+ struct S5;
7165
+ struct Cls {
7166
+ consteval { std::meta::define_aggregate(^^S5, {}); } // error: S5 is not enclosed by class Cls
7167
+ };
7168
+
7169
+ struct S6;
7170
+ consteval { // #1
7171
+ struct S7; // local class
7172
+
7173
+ std::meta::define_aggregate(^^S7, {}); // error: consteval block #1 does not enclose itself,
7174
+ // but encloses S7
7175
+
7176
+ struct S8; // local class
7177
+ consteval { // #2
7178
+ std::meta::define_aggregate(^^S6, {}); // error: consteval block #1 encloses
7179
+ // consteval block #2 but not S6
7180
+
7181
+ std::meta::define_aggregate(^^S8, {}); // OK, consteval block #1 encloses both #2 and S8
7182
+ }
7183
+ }
7184
+ ```
7185
+
7186
+ — *end example*]
7187
+
7188
+ The *evaluation context* is a set of program points that determines the
7189
+ behavior of certain functions used for reflection [[meta.reflection]].
7190
+ During the evaluation V of an expression E as a core constant
7191
+ expression, the evaluation context of an evaluation X
7192
+ [[intro.execution]] consists of the following points:
7193
+
7194
+ - The program point EVAL-PT(L), where L is the point at which E appears,
7195
+ and where EVAL-PT(P), for a point P, is a point R determined as
7196
+ follows:
7197
+ - If a potentially-evaluated subexpression [[intro.execution]] of a
7198
+ default member initializer I appears at P, and a (possibly
7199
+ aggregate) initialization during V is using I, then R is EVAL-PT(Q)
7200
+ where Q is the point at which that initialization appears.
7201
+ - Otherwise, if a potentially-evaluated subexpression of a default
7202
+ argument [[dcl.fct.default]] appears at P, and an invocation of a
7203
+ function [[expr.call]] during V is using that default argument, then
7204
+ R is EVAL-PT(Q) where Q is the point at which that invocation
7205
+ appears.
7206
+ - Otherwise, R is P.
7207
+ - Each synthesized point corresponding to an injected declaration
7208
+ produced by any evaluation sequenced before X [[intro.execution]].
7209
 
7210
  An expression or conversion is *potentially constant evaluated* if it
7211
  is:
7212
 
7213
  - a manifestly constant-evaluated expression,
7214
  - a potentially-evaluated expression [[basic.def.odr]],
7215
+ - an immediate subexpression of a *braced-init-list*,[^32]
7216
  - an expression of the form `&` *cast-expression* that occurs within a
7217
+ templated entity,[^33] or
7218
  - a potentially-evaluated subexpression [[intro.execution]] of one of
7219
  the above.
7220
 
7221
  A function or variable is *needed for constant evaluation* if it is:
7222
 
 
7224
  that is potentially constant evaluated, or
7225
  - a potentially-constant variable named by a potentially constant
7226
  evaluated expression.
7227
 
7228
  <!-- Link reference definitions -->
7229
+ [\lastcorechapter]: #\lastcorechapter
7230
  [allocator.members]: mem.md#allocator.members
7231
  [bad.alloc]: support.md#bad.alloc
7232
  [bad.cast]: support.md#bad.cast
7233
  [bad.typeid]: support.md#bad.typeid
7234
  [basic.align]: basic.md#basic.align
7235
  [basic.compound]: basic.md#basic.compound
7236
+ [basic.contract]: basic.md#basic.contract
7237
+ [basic.contract.eval]: basic.md#basic.contract.eval
7238
+ [basic.contract.general]: basic.md#basic.contract.general
7239
  [basic.def.odr]: basic.md#basic.def.odr
7240
  [basic.fundamental]: basic.md#basic.fundamental
7241
  [basic.indet]: basic.md#basic.indet
7242
  [basic.life]: basic.md#basic.life
7243
  [basic.lookup]: basic.md#basic.lookup
7244
  [basic.lookup.argdep]: basic.md#basic.lookup.argdep
7245
  [basic.lookup.general]: basic.md#basic.lookup.general
7246
  [basic.lookup.qual]: basic.md#basic.lookup.qual
7247
  [basic.lookup.unqual]: basic.md#basic.lookup.unqual
7248
  [basic.lval]: #basic.lval
7249
+ [basic.namespace]: dcl.md#basic.namespace
7250
  [basic.pre]: basic.md#basic.pre
7251
  [basic.scope.block]: basic.md#basic.scope.block
7252
  [basic.scope.class]: basic.md#basic.scope.class
7253
+ [basic.scope.contract]: basic.md#basic.scope.contract
7254
  [basic.scope.lambda]: basic.md#basic.scope.lambda
7255
+ [basic.splice]: basic.md#basic.splice
7256
  [basic.start.main]: basic.md#basic.start.main
7257
  [basic.start.static]: basic.md#basic.start.static
7258
  [basic.stc.dynamic]: basic.md#basic.stc.dynamic
7259
  [basic.stc.dynamic.allocation]: basic.md#basic.stc.dynamic.allocation
7260
  [basic.stc.dynamic.deallocation]: basic.md#basic.stc.dynamic.deallocation
7261
  [basic.stc.static]: basic.md#basic.stc.static
7262
  [basic.stc.thread]: basic.md#basic.stc.thread
7263
  [basic.type.qualifier]: basic.md#basic.type.qualifier
7264
+ [basic.types.general]: basic.md#basic.types.general
7265
  [class]: class.md#class
7266
  [class.abstract]: class.md#class.abstract
7267
  [class.access]: class.md#class.access
7268
  [class.access.base]: class.md#class.access.base
7269
+ [class.access.general]: class.md#class.access.general
7270
  [class.base.init]: class.md#class.base.init
7271
  [class.bit]: class.md#class.bit
7272
  [class.cdtor]: class.md#class.cdtor
7273
  [class.conv]: class.md#class.conv
7274
  [class.conv.fct]: class.md#class.conv.fct
 
7279
  [class.derived]: class.md#class.derived
7280
  [class.dtor]: class.md#class.dtor
7281
  [class.free]: class.md#class.free
7282
  [class.friend]: class.md#class.friend
7283
  [class.mem]: class.md#class.mem
7284
+ [class.mem.general]: class.md#class.mem.general
7285
  [class.member.lookup]: basic.md#class.member.lookup
 
7286
  [class.mfct.non.static]: class.md#class.mfct.non.static
7287
  [class.mi]: class.md#class.mi
7288
+ [class.pre]: class.md#class.pre
7289
  [class.prop]: class.md#class.prop
7290
  [class.spaceship]: class.md#class.spaceship
7291
  [class.static.mfct]: class.md#class.static.mfct
7292
  [class.temporary]: basic.md#class.temporary
7293
  [class.union]: class.md#class.union
 
7310
  [conv.prom]: #conv.prom
7311
  [conv.ptr]: #conv.ptr
7312
  [conv.qual]: #conv.qual
7313
  [conv.rank]: basic.md#conv.rank
7314
  [conv.rval]: #conv.rval
 
7315
  [cstdarg.syn]: support.md#cstdarg.syn
7316
  [cstddef.syn]: support.md#cstddef.syn
7317
+ [dcl]: dcl.md#dcl
7318
  [dcl.align]: dcl.md#dcl.align
7319
  [dcl.array]: dcl.md#dcl.array
7320
  [dcl.asm]: dcl.md#dcl.asm
7321
+ [dcl.attr.annotation]: dcl.md#dcl.attr.annotation
7322
  [dcl.constexpr]: dcl.md#dcl.constexpr
7323
+ [dcl.contract.func]: dcl.md#dcl.contract.func
7324
+ [dcl.contract.res]: dcl.md#dcl.contract.res
7325
  [dcl.decl]: dcl.md#dcl.decl
7326
  [dcl.enum]: dcl.md#dcl.enum
7327
  [dcl.fct]: dcl.md#dcl.fct
7328
  [dcl.fct.def]: dcl.md#dcl.fct.def
7329
  [dcl.fct.def.coroutine]: dcl.md#dcl.fct.def.coroutine
7330
  [dcl.fct.def.general]: dcl.md#dcl.fct.def.general
7331
  [dcl.fct.default]: dcl.md#dcl.fct.default
7332
  [dcl.init]: dcl.md#dcl.init
7333
  [dcl.init.aggr]: dcl.md#dcl.init.aggr
7334
+ [dcl.init.general]: dcl.md#dcl.init.general
7335
  [dcl.init.list]: dcl.md#dcl.init.list
7336
  [dcl.init.ref]: dcl.md#dcl.init.ref
7337
  [dcl.init.string]: dcl.md#dcl.init.string
7338
  [dcl.link]: dcl.md#dcl.link
7339
  [dcl.mptr]: dcl.md#dcl.mptr
7340
  [dcl.name]: dcl.md#dcl.name
7341
+ [dcl.pre]: dcl.md#dcl.pre
7342
  [dcl.ptr]: dcl.md#dcl.ptr
7343
  [dcl.ref]: dcl.md#dcl.ref
7344
  [dcl.spec.auto]: dcl.md#dcl.spec.auto
7345
+ [dcl.spec.auto.general]: dcl.md#dcl.spec.auto.general
7346
  [dcl.stc]: dcl.md#dcl.stc
7347
  [dcl.struct.bind]: dcl.md#dcl.struct.bind
7348
  [dcl.type]: dcl.md#dcl.type
7349
  [dcl.type.auto.deduct]: dcl.md#dcl.type.auto.deduct
7350
+ [dcl.type.class.deduct]: dcl.md#dcl.type.class.deduct
7351
  [dcl.type.cv]: dcl.md#dcl.type.cv
7352
  [dcl.type.decltype]: dcl.md#dcl.type.decltype
7353
  [dcl.type.elab]: dcl.md#dcl.type.elab
7354
  [dcl.type.simple]: dcl.md#dcl.type.simple
7355
  [defns.access]: intro.md#defns.access
7356
  [defns.nonconst.libcall]: intro.md#defns.nonconst.libcall
 
 
7357
  [depr.capture.this]: future.md#depr.capture.this
7358
  [depr.volatile.type]: future.md#depr.volatile.type
7359
  [except]: except.md#except
7360
+ [except.ctor]: except.md#except.ctor
7361
  [except.handle]: except.md#except.handle
7362
  [except.pre]: except.md#except.pre
7363
  [except.spec]: except.md#except.spec
7364
  [except.terminate]: except.md#except.terminate
7365
  [except.throw]: except.md#except.throw
7366
+ [exec]: exec.md#exec
7367
  [expr]: #expr
7368
  [expr.add]: #expr.add
7369
  [expr.alignof]: #expr.alignof
7370
  [expr.arith.conv]: #expr.arith.conv
7371
+ [expr.assign]: #expr.assign
7372
  [expr.await]: #expr.await
7373
  [expr.bit.and]: #expr.bit.and
7374
  [expr.call]: #expr.call
7375
  [expr.cast]: #expr.cast
7376
  [expr.comma]: #expr.comma
 
7393
  [expr.post.incr]: #expr.post.incr
7394
  [expr.pre]: #expr.pre
7395
  [expr.pre.incr]: #expr.pre.incr
7396
  [expr.prim]: #expr.prim
7397
  [expr.prim.fold]: #expr.prim.fold
7398
+ [expr.prim.grammar]: #expr.prim.grammar
7399
  [expr.prim.id]: #expr.prim.id
7400
  [expr.prim.id.dtor]: #expr.prim.id.dtor
7401
  [expr.prim.id.general]: #expr.prim.id.general
7402
  [expr.prim.id.qual]: #expr.prim.id.qual
7403
  [expr.prim.id.unqual]: #expr.prim.id.unqual
7404
  [expr.prim.lambda]: #expr.prim.lambda
7405
  [expr.prim.lambda.capture]: #expr.prim.lambda.capture
7406
  [expr.prim.lambda.closure]: #expr.prim.lambda.closure
7407
  [expr.prim.lambda.general]: #expr.prim.lambda.general
7408
  [expr.prim.literal]: #expr.prim.literal
7409
+ [expr.prim.pack.index]: #expr.prim.pack.index
7410
  [expr.prim.paren]: #expr.prim.paren
7411
  [expr.prim.req]: #expr.prim.req
7412
  [expr.prim.req.compound]: #expr.prim.req.compound
7413
  [expr.prim.req.general]: #expr.prim.req.general
7414
  [expr.prim.req.nested]: #expr.prim.req.nested
7415
  [expr.prim.req.simple]: #expr.prim.req.simple
7416
  [expr.prim.req.type]: #expr.prim.req.type
7417
+ [expr.prim.splice]: #expr.prim.splice
7418
  [expr.prim.this]: #expr.prim.this
7419
  [expr.prop]: #expr.prop
7420
  [expr.ref]: #expr.ref
7421
+ [expr.reflect]: #expr.reflect
7422
  [expr.reinterpret.cast]: #expr.reinterpret.cast
7423
  [expr.rel]: #expr.rel
7424
  [expr.shift]: #expr.shift
7425
  [expr.sizeof]: #expr.sizeof
7426
  [expr.spaceship]: #expr.spaceship
 
7443
  [intro.memory]: basic.md#intro.memory
7444
  [intro.object]: basic.md#intro.object
7445
  [lex.ext]: lex.md#lex.ext
7446
  [lex.icon]: lex.md#lex.icon
7447
  [lex.literal]: lex.md#lex.literal
7448
+ [lex.name]: lex.md#lex.name
7449
  [lex.string]: lex.md#lex.string
7450
  [library]: library.md#library
7451
  [meta.const.eval]: meta.md#meta.const.eval
7452
+ [meta.reflection]: meta.md#meta.reflection
7453
+ [meta.reflection.define.aggregate]: meta.md#meta.reflection.define.aggregate
7454
+ [module.reach]: module.md#module.reach
7455
+ [namespace.alias]: dcl.md#namespace.alias
7456
  [namespace.udecl]: dcl.md#namespace.udecl
7457
  [new.badlength]: support.md#new.badlength
7458
  [new.delete.array]: support.md#new.delete.array
7459
  [new.delete.placement]: support.md#new.delete.placement
7460
  [new.delete.single]: support.md#new.delete.single
7461
  [over]: over.md#over
7462
+ [over.assign]: over.md#over.assign
7463
  [over.best.ics]: over.md#over.best.ics
7464
  [over.built]: over.md#over.built
7465
  [over.call]: over.md#over.call
7466
  [over.call.func]: over.md#over.call.func
7467
  [over.ics.user]: over.md#over.ics.user
7468
  [over.literal]: over.md#over.literal
7469
  [over.match]: over.md#over.match
7470
  [over.match.class.deduct]: over.md#over.match.class.deduct
7471
+ [over.match.funcs]: over.md#over.match.funcs
7472
  [over.match.oper]: over.md#over.match.oper
7473
  [over.match.viable]: over.md#over.match.viable
7474
  [over.oper]: over.md#over.oper
7475
  [over.over]: over.md#over.over
7476
  [over.sub]: over.md#over.sub
7477
+ [propagation]: support.md#propagation
7478
  [replacement.functions]: library.md#replacement.functions
7479
  [special]: class.md#special
7480
  [std.modules]: library.md#std.modules
7481
+ [stmt]: stmt.md#stmt
7482
+ [stmt.contract.assert]: stmt.md#stmt.contract.assert
7483
  [stmt.goto]: stmt.md#stmt.goto
7484
  [stmt.if]: stmt.md#stmt.if
7485
  [stmt.iter]: stmt.md#stmt.iter
7486
  [stmt.jump]: stmt.md#stmt.jump
7487
  [stmt.pre]: stmt.md#stmt.pre
7488
  [stmt.return]: stmt.md#stmt.return
7489
  [stmt.return.coroutine]: stmt.md#stmt.return.coroutine
7490
  [stmt.switch]: stmt.md#stmt.switch
7491
+ [stmt.while]: stmt.md#stmt.while
7492
  [support.runtime]: support.md#support.runtime
7493
  [support.types.layout]: support.md#support.types.layout
7494
+ [temp.alias]: temp.md#temp.alias
7495
  [temp.arg]: temp.md#temp.arg
7496
  [temp.concept]: temp.md#temp.concept
7497
  [temp.constr.atomic]: temp.md#temp.constr.atomic
7498
  [temp.constr.constr]: temp.md#temp.constr.constr
7499
  [temp.constr.decl]: temp.md#temp.constr.decl
7500
+ [temp.deduct.general]: temp.md#temp.deduct.general
7501
  [temp.dep.constexpr]: temp.md#temp.dep.constexpr
7502
+ [temp.dep.type]: temp.md#temp.dep.type
7503
  [temp.expl.spec]: temp.md#temp.expl.spec
7504
  [temp.explicit]: temp.md#temp.explicit
7505
  [temp.mem]: temp.md#temp.mem
7506
  [temp.names]: temp.md#temp.names
7507
  [temp.over.link]: temp.md#temp.over.link
7508
  [temp.param]: temp.md#temp.param
7509
  [temp.pre]: temp.md#temp.pre
7510
  [temp.res]: temp.md#temp.res
7511
  [temp.spec.partial]: temp.md#temp.spec.partial
7512
+ [temp.type]: temp.md#temp.type
7513
  [temp.variadic]: temp.md#temp.variadic
7514
  [term.incomplete.type]: basic.md#term.incomplete.type
7515
  [term.object.representation]: basic.md#term.object.representation
7516
  [term.odr.use]: basic.md#term.odr.use
7517
+ [term.structural.type]: temp.md#term.structural.type
7518
  [term.unevaluated.operand]: #term.unevaluated.operand
 
7519
  [type.info]: support.md#type.info
7520
  [typeinfo.syn]: support.md#typeinfo.syn
7521
 
7522
  [^1]: The precedence of operators is not directly specified, but it can
7523
  be derived from the syntax.
 
7525
  [^2]: Overloaded operators are never assumed to be associative or
7526
  commutative.
7527
 
7528
  [^3]: The cast and assignment operators must still perform their
7529
  specific conversions as described in  [[expr.type.conv]],
7530
+ [[expr.cast]], [[expr.static.cast]] and  [[expr.assign]].
7531
 
7532
  [^4]: The intent of this list is to specify those circumstances in which
7533
  an object can or cannot be aliased.
7534
 
7535
  [^5]: For historical reasons, this conversion is called the
7536
  “lvalue-to-rvalue” conversion, even though that name does not
7537
  accurately reflect the taxonomy of expressions described in 
7538
  [[basic.lval]].
7539
 
7540
  [^6]: In C++ class and array prvalues can have cv-qualified types. This
7541
+ differs from C, in which non-lvalues never have cv-qualified types.
 
7542
 
7543
  [^7]: This conversion never applies to non-static member functions
7544
  because an lvalue that refers to a non-static member function cannot
7545
  be obtained.
7546
 
 
7556
 
7557
  [^9]: As a consequence, operands of type `bool`, `char8_t`, `char16_t`,
7558
  `char32_t`, `wchar_t`, or of enumeration type are converted to some
7559
  integral type.
7560
 
7561
+ [^10]: This is true even if the subscript operator is used in the
 
 
 
7562
  following common idiom: `&x[0]`.
7563
 
7564
+ [^11]: Note that `(*(E1))` is an lvalue.
7565
+
7566
  [^12]: If the class member access expression is evaluated, the
7567
  subexpression evaluation happens even if the result is unnecessary
7568
  to determine the value of the entire postfix expression, for example
7569
  if the *id-expression* denotes a static member.
7570
 
7571
+ [^13]: The most derived object [[intro.object]] pointed or referred to
 
 
7572
  by `v` can contain other `B` objects as base classes, but these are
7573
  ignored.
7574
 
7575
+ [^14]: The recommended name for such a class is `extended_type_info`.
7576
 
7577
+ [^15]: The types can have different cv-qualifiers, subject to the
 
 
 
7578
  overall restriction that a `reinterpret_cast` cannot cast away
7579
  constness.
7580
 
7581
+ [^16]: `T1` and `T2` can have different cv-qualifiers, subject to the
7582
  overall restriction that a `reinterpret_cast` cannot cast away
7583
  constness.
7584
 
7585
+ [^17]: This is sometimes referred to as a type pun when the result
7586
  refers to the same object as the source glvalue.
7587
 
7588
+ [^18]: `const_cast` is not limited to conversions that cast away a
7589
  const-qualifier.
7590
 
7591
+ [^19]: `sizeof``(``bool``)` is not required to be `1`.
7592
 
7593
+ [^20]: The actual size of a potentially-overlapping subobject can be
7594
  less than the result of applying `sizeof` to the subobject, due to
7595
  virtual base classes and less strict padding requirements on
7596
  potentially-overlapping subobjects.
7597
 
7598
+ [^21]: If the conversion function returns a signed integer type, the
7599
  second standard conversion converts to the unsigned type
7600
  `std::size_t` and thus thwarts any attempt to detect a negative
7601
  value afterwards.
7602
 
7603
+ [^22]: This can include evaluating a *new-initializer* and/or calling a
7604
  constructor.
7605
 
7606
+ [^23]: A *lambda-expression* with a *lambda-introducer* that consists of
7607
  empty square brackets can follow the `delete` keyword if the
7608
  *lambda-expression* is enclosed in parentheses.
7609
 
7610
+ [^24]: For nonzero-length arrays, this is the same as a pointer to the
 
 
 
7611
  first element of the array created by that *new-expression*.
7612
  Zero-length arrays do not have a first element.
7613
 
7614
+ [^25]: This is often called truncation towards zero.
7615
 
7616
+ [^26]: As specified in [[basic.compound]], an object that is not an
7617
  array element is considered to belong to a single-element array for
7618
  this purpose and a pointer past the last element of an array of n
7619
  elements is considered to be equivalent to a pointer to a
7620
  hypothetical array element n for this purpose.
7621
 
7622
+ [^27]: As specified in [[basic.compound]], an object that is not an
7623
  array element is considered to belong to a single-element array for
7624
  this purpose and a pointer past the last element of an array of n
7625
  elements is considered to be equivalent to a pointer to a
7626
  hypothetical array element n for this purpose.
7627
 
7628
+ [^28]: As specified in [[basic.compound]], an object that is not an
7629
  array element is considered to belong to a single-element array for
7630
  this purpose.
7631
 
7632
+ [^29]: Overload resolution [[over.match]] is applied as usual.
7633
 
7634
+ [^30]: This includes, for example, signed integer overflow [[expr.pre]],
7635
  certain pointer arithmetic [[expr.add]], division by zero
7636
  [[expr.mul]], or certain shift operations [[expr.shift]].
7637
 
7638
+ [^31]: Testing this condition can involve a trial evaluation of its
7639
+ initializer, with evaluations of contract assertions using the
7640
+ ignore evaluation semantic [[basic.contract.eval]], as described
7641
+ above.
7642
 
7643
+ [^32]: In some cases, constant evaluation is needed to determine whether
7644
  a narrowing conversion is performed [[dcl.init.list]].
7645
 
7646
+ [^33]: In some cases, constant evaluation is needed to determine whether
7647
  such an expression is value-dependent [[temp.dep.constexpr]].