From Jason Turner

[expr]

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

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp1zv6gor9/{from.md → to.md} +946 -597
tmp/tmp1zv6gor9/{from.md → to.md} RENAMED
@@ -38,10 +38,14 @@ If an expression initially has the type “reference to `T`” (
38
  [[dcl.ref]],  [[dcl.init.ref]]), the type is adjusted to `T` prior to
39
  any further analysis. The expression designates the object or function
40
  denoted by the reference, and the expression is an lvalue or an xvalue,
41
  depending on the expression.
42
 
 
 
 
 
43
  An expression is an xvalue if it is:
44
 
45
  - the result of calling a function, whether implicitly or explicitly,
46
  whose return type is an rvalue reference to object type,
47
  - a cast to an rvalue reference to object type,
@@ -69,14 +73,15 @@ A&& ar = static_cast<A&&>(a);
69
  The expressions `f()`, `f().m`, `static_cast<A&&>(a)`, and `a + a` are
70
  xvalues. The expression `ar` is an lvalue.
71
 
72
  In some contexts, *unevaluated operands* appear ([[expr.typeid]],
73
  [[expr.sizeof]], [[expr.unary.noexcept]], [[dcl.type.simple]]). An
74
- unevaluated operand is not evaluated. In an unevaluated operand, a
75
- non-static class member may be named ([[expr.prim]]) and naming of
76
- objects or functions does not, by itself, require that a definition be
77
- provided ([[basic.def.odr]]).
 
78
 
79
  Whenever a glvalue expression appears as an operand of an operator that
80
  expects a prvalue for that operand, the lvalue-to-rvalue (
81
  [[conv.lval]]), array-to-pointer ([[conv.array]]), or
82
  function-to-pointer ([[conv.func]]) standard conversions are applied to
@@ -125,27 +130,76 @@ defined as follows:
125
  In some contexts, an expression only appears for its side effects. Such
126
  an expression is called a *discarded-value expression*. The expression
127
  is evaluated and its value is discarded. The array-to-pointer (
128
  [[conv.array]]) and function-to-pointer ([[conv.func]]) standard
129
  conversions are not applied. The lvalue-to-rvalue conversion (
130
- [[conv.lval]]) is applied only if the expression is an lvalue of
131
- volatile-qualified type and it has one of the following forms:
132
 
 
133
  - *id-expression* ([[expr.prim.general]]),
134
  - subscripting ([[expr.sub]]),
135
  - class member access ([[expr.ref]]),
136
  - indirection ([[expr.unary.op]]),
137
  - pointer-to-member operation ([[expr.mptr.oper]]),
138
  - conditional expression ([[expr.cond]]) where both the second and the
139
- third operands are one of the above, or
140
  - comma expression ([[expr.comma]]) where the right operand is one of
141
- the above.
 
 
 
 
 
142
 
143
  The values of the floating operands and the results of floating
144
  expressions may be represented in greater precision and range than that
145
  required by the type; the types are not changed thereby.[^3]
146
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  ## Primary expressions <a id="expr.prim">[[expr.prim]]</a>
148
 
149
  ### General <a id="expr.prim.general">[[expr.prim.general]]</a>
150
 
151
  ``` bnf
@@ -251,42 +305,40 @@ The result is an lvalue if the entity is a function, variable, or data
251
  member and a prvalue otherwise.
252
 
253
  ``` bnf
254
  qualified-id:
255
  nested-name-specifier 'template'ₒₚₜ unqualified-id
256
- '::' identifier
257
- '::' operator-function-id
258
- '::' literal-operator-id
259
- '::' template-id
260
  ```
261
 
262
  ``` bnf
263
  nested-name-specifier:
264
- '::'ₒₚₜ type-name '::'
265
- '::'ₒₚₜ namespace-name '::'
 
266
  decltype-specifier '::'
267
  nested-name-specifier identifier '::'
268
  nested-name-specifier 'template'ₒₚₜ simple-template-id '::'
269
  ```
270
 
 
 
 
271
  A *nested-name-specifier* that denotes a class, optionally followed by
272
  the keyword `template` ([[temp.names]]), and then followed by the name
273
  of a member of either that class ([[class.mem]]) or one of its base
274
  classes (Clause  [[class.derived]]), is a *qualified-id*; 
275
  [[class.qual]] describes name lookup for class members that appear in
276
  *qualified-ids*. The result is the member. The type of the result is the
277
  type of the member. The result is an lvalue if the member is a static
278
  member function or a data member and a prvalue otherwise. a class member
279
  can be referred to using a *qualified-id* at any point in its potential
280
- scope ([[basic.scope.class]]). Where *class-name* `::` *class-name* is
281
- used, and the two *class-name*s refer to the same class, this notation
282
- names the constructor ([[class.ctor]]). Where *class-name* `::~`
283
- *class-name* is used, the two *class-name*s shall refer to the same
284
- class; this notation names the destructor ([[class.dtor]]). The form
285
- *\textasciitilde* *decltype-specifier* also denotes the destructor, but
286
- it shall not be used as the *unqualified-id* in a *qualified-id*. a
287
- *typedef-name* that names a class is a *class-name* ([[class.name]]).
288
 
289
  A `::`, or a *nested-name-specifier* that names a namespace (
290
  [[basic.namespace]]), in either case followed by the name of a member of
291
  that namespace (or the name of a member of a namespace made visible by a
292
  *using-directive*) is a *qualified-id*;  [[namespace.qual]] describes
@@ -311,14 +363,10 @@ member function of a class can only be used:
311
 
312
  - as part of a class member access ([[expr.ref]]) in which the object
313
  expression refers to the member’s class[^4] or a class derived from
314
  that class, or
315
  - to form a pointer to member ([[expr.unary.op]]), or
316
- - in a *mem-initializer* for a constructor for that class or for a class
317
- derived from that class ([[class.base.init]]), or
318
- - in a *brace-or-equal-initializer* for a non-static data member of that
319
- class or of a class derived from that class ([[class.base.init]]), or
320
  - if that *id-expression* denotes a non-static data member and it
321
  appears in an unevaluated operand.
322
  ``` cpp
323
  struct S {
324
  int m;
@@ -372,39 +420,54 @@ capture-list:
372
  capture-list ',' capture '...'ₒₚₜ
373
  ```
374
 
375
  ``` bnf
376
  capture:
 
 
 
 
 
 
377
  identifier
378
  '&' identifier
379
  'this'
380
  ```
381
 
 
 
 
 
 
 
382
  ``` bnf
383
  lambda-declarator:
384
  '(' parameter-declaration-clause ')' 'mutable'ₒₚₜ
385
  exception-specificationₒₚₜ attribute-specifier-seqₒₚₜ trailing-return-typeₒₚₜ
386
  ```
387
 
388
  The evaluation of a *lambda-expression* results in a prvalue temporary (
389
  [[class.temporary]]). This temporary is called the *closure object*. A
390
  *lambda-expression* shall not appear in an unevaluated operand (Clause 
391
- [[expr]]). A closure object behaves like a function object (
392
- [[function.objects]]).
 
 
 
393
 
394
  The type of the *lambda-expression* (which is also the type of the
395
  closure object) is a unique, unnamed non-union class type — called the
396
  *closure type* — whose properties are described below. This class type
397
- is not an aggregate ([[dcl.init.aggr]]). The closure type is declared
398
- in the smallest block scope, class scope, or namespace scope that
399
- contains the corresponding *lambda-expression*. This determines the set
400
- of namespaces and classes associated with the closure type (
401
- [[basic.lookup.argdep]]). The parameter types of a *lambda-declarator*
402
- do not affect these associated namespaces and classes. An implementation
403
- may define the closure type differently from what is described below
404
- provided this does not alter the observable behavior of the program
405
- other than by changing:
406
 
407
  - the size and/or alignment of the closure type,
408
  - whether the closure type is trivially copyable (Clause  [[class]]),
409
  - whether the closure type is a standard-layout class (Clause 
410
  [[class]]), or
@@ -412,52 +475,145 @@ other than by changing:
412
 
413
  An implementation shall not add members of rvalue reference type to the
414
  closure type.
415
 
416
  If a *lambda-expression* does not include a *lambda-declarator*, it is
417
- as if the *lambda-declarator* were `()`. If a *lambda-expression* does
418
- not include a *trailing-return-type*, it is as if the
419
- *trailing-return-type* denotes the following type:
420
-
421
- - if the *compound-statement* is of the form
422
- ``` bnf
423
- '{' attribute-specifier-seqₒₚₜ 'return' expression ';' '}'
424
- ```
425
-
426
- the type of the returned expression after lvalue-to-rvalue
427
- conversion ([[conv.lval]]), array-to-pointer conversion (
428
- [[conv.array]]), and function-to-pointer conversion ([[conv.func]]);
429
- - otherwise, `void`.
430
 
431
  ``` cpp
432
  auto x1 = [](int i){ return i; }; // OK: return type is int
433
- auto x2 = []{ return { 1, 2 }; }; // error: the return type is void (a
434
- // braced-init-list is not an expression)
 
435
  ```
436
 
437
- The closure type for a *lambda-expression* has a public `inline`
438
- function call operator ([[over.call]]) whose parameters and return type
439
- are described by the *lambda-expression*’s
440
  *parameter-declaration-clause* and *trailing-return-type* respectively.
441
- This function call operator is declared `const` (
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
442
  [[class.mfct.non-static]]) if and only if the *lambda-expression*’s
443
  *parameter-declaration-clause* is not followed by `mutable`. It is
444
- neither virtual nor declared `volatile`. Default arguments (
445
- [[dcl.fct.default]]) shall not be specified in the
446
- *parameter-declaration-clause* of a *lambda-declarator*. Any
447
- *exception-specification* specified on a *lambda-expression* applies to
448
- the corresponding function call operator. An *attribute-specifier-seq*
449
- in a *lambda-declarator* appertains to the type of the corresponding
450
- function call operator. Names referenced in the *lambda-declarator* are
451
- looked up in the context in which the *lambda-expression* appears.
452
-
453
- The closure type for a *lambda-expression* with no *lambda-capture* has
454
- a public non-virtual non-explicit const conversion function to pointer
455
- to function having the same parameter and return types as the closure
456
- type’s function call operator. The value returned by this conversion
457
- function shall be the address of a function that, when invoked, has the
458
- same effect as invoking the closure type’s function call operator.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
459
 
460
  The *lambda-expression*’s *compound-statement* yields the
461
  *function-body* ([[dcl.fct.def]]) of the function call operator, but
462
  for purposes of name lookup ([[basic.lookup]]), determining the type
463
  and value of `this` ([[class.this]]) and transforming *id-expression*s
@@ -477,16 +633,21 @@ struct S1 {
477
  };
478
  }
479
  };
480
  ```
481
 
482
- If a *lambda-capture* includes a *capture-default* that is `&`, the
483
- identifiers in the *lambda-capture* shall not be preceded by `&`. If a
484
- *lambda-capture* includes a *capture-default* that is `=`, the
485
- *lambda-capture* shall not contain `this` and each identifier it
486
- contains shall be preceded by `&`. An identifier or `this` shall not
487
- appear more than once in a *lambda-capture*.
 
 
 
 
 
488
 
489
  ``` cpp
490
  struct S2 { void f(int i); };
491
  void S2::f(int i) {
492
  [&, i]{ }; // OK
@@ -495,40 +656,89 @@ void S2::f(int i) {
495
  [i, i]{ }; // error: i repeated
496
  }
497
  ```
498
 
499
  A *lambda-expression* whose smallest enclosing scope is a block scope (
500
- [[basic.scope.local]]) is a *local lambda expression*; any other
501
- *lambda-expression* shall not have a *capture-list* in its
502
- *lambda-introducer*. The *reaching scope* of a local lambda expression
503
- is the set of enclosing scopes up to and including the innermost
504
- enclosing function and its parameters. This reaching scope includes any
505
- intervening *lambda-expression*s.
506
 
507
- The *identifiers* in a *capture-list* are looked up using the usual
508
  rules for unqualified name lookup ([[basic.lookup.unqual]]); each such
509
- lookup shall find a variable with automatic storage duration declared in
510
- the reaching scope of the local lambda expression. An entity (i.e. a
511
- variable or `this`) is said to be *explicitly captured* if it appears in
512
- the *lambda-expression*’s *capture-list*.
513
-
514
- If a *lambda-expression* has an associated *capture-default* and its
515
- *compound-statement* odr-uses ([[basic.def.odr]]) `this` or a variable
516
- with automatic storage duration and the odr-used entity is not
517
- explicitly captured, then the odr-used entity is said to be *implicitly
518
- captured*; such entities shall be declared within the reaching scope of
519
- the lambda expression. The implicit capture of an entity by a nested
520
- *lambda-expression* can cause its implicit capture by the containing
521
- *lambda-expression* (see below). Implicit odr-uses of `this` can result
522
- in implicit capture.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
523
 
524
  An entity is *captured* if it is captured explicitly or implicitly. An
525
  entity captured by a *lambda-expression* is odr-used (
526
  [[basic.def.odr]]) in the scope containing the *lambda-expression*. If
527
  `this` is captured by a local lambda expression, its nearest enclosing
528
  function shall be a non-static member function. If a *lambda-expression*
529
- odr-uses ([[basic.def.odr]]) `this` or a variable with automatic
 
530
  storage duration from its reaching scope, that entity shall be captured
531
  by the *lambda-expression*. If a *lambda-expression* captures an entity
532
  and that entity is not defined or captured in the immediately enclosing
533
  lambda expression or function, the program is ill-formed.
534
 
@@ -578,22 +788,25 @@ void f2() {
578
  }
579
  ```
580
 
581
  An entity is *captured by copy* if it is implicitly captured and the
582
  *capture-default* is `=` or if it is explicitly captured with a capture
583
- that does not include an `&`. For each entity captured by copy, an
584
- unnamed non-static data member is declared in the closure type. The
585
- declaration order of these members is unspecified. The type of such a
586
- data member is the type of the corresponding captured entity if the
587
- entity is not a reference to an object, or the referenced type
588
- otherwise. If the captured entity is a reference to a function, the
589
- corresponding data member is also a reference to a function.
 
 
590
 
591
  An entity is *captured by reference* if it is implicitly or explicitly
592
  captured but not captured by copy. It is unspecified whether additional
593
  unnamed non-static data members are declared in the closure type for
594
- entities captured by reference.
 
595
 
596
  If a *lambda-expression* `m2` captures an entity and that entity is
597
  captured by an immediately enclosing *lambda-expression* `m1`, then
598
  `m2`’s capture is transformed as follows:
599
 
@@ -618,30 +831,30 @@ auto m1 = [a, &b, &c]() mutable {
618
  a = 2; b = 2; c = 2;
619
  m1();
620
  std::cout << a << b << c;
621
  ```
622
 
623
- Every *id-expression* that is an odr-use ([[basic.def.odr]]) of an
624
- entity captured by copy is transformed into an access to the
625
- corresponding unnamed data member of the closure type. An
626
- *id-expression* that is not an odr-use refers to the original entity,
627
- never to a member of the closure type. Furthermore, such an
628
- *id-expression* does not cause the implicit capture of the entity. If
629
- `this` is captured, each odr-use of `this` is transformed into an access
630
- to the corresponding unnamed data member of the closure type, cast (
631
- [[expr.cast]]) to the type of `this`. The cast ensures that the
632
- transformed expression is a prvalue.
633
 
634
  ``` cpp
635
  void f(const int*);
636
  void g() {
637
  const int N = 10;
638
  [=] {
639
  int arr[N]; // OK: not an odr-use, refers to automatic variable
640
  f(&N); // OK: causes N to be captured; &N points to the
641
  // corresponding member of the closure type
642
- }
643
  }
644
  ```
645
 
646
  Every occurrence of `decltype((x))` where `x` is a possibly
647
  parenthesized *id-expression* that names an entity of automatic storage
@@ -673,24 +886,27 @@ implicitly defined.
673
  The closure type associated with a *lambda-expression* has an
674
  implicitly-declared destructor ([[class.dtor]]).
675
 
676
  When the *lambda-expression* is evaluated, the entities that are
677
  captured by copy are used to direct-initialize each corresponding
678
- non-static data member of the resulting closure object. (For array
679
- members, the array elements are direct-initialized in increasing
680
- subscript order.) These initializations are performed in the
681
- (unspecified) order in which the non-static data members are declared.
682
- This ensures that the destructions will occur in the reverse order of
683
- the constructions.
 
 
684
 
685
  If an entity is implicitly or explicitly captured by reference, invoking
686
  the function call operator of the corresponding *lambda-expression*
687
  after the lifetime of the entity has ended is likely to result in
688
  undefined behavior.
689
 
690
- A *capture* followed by an ellipsis is a pack expansion (
691
- [[temp.variadic]]).
 
692
 
693
  ``` cpp
694
  template<class... Args>
695
  void f(Args... args) {
696
  auto lm = [&, args...] { return g(args...); };
@@ -744,64 +960,67 @@ The `>` token following the in a `dynamic_cast`, `static_cast`,
744
  `>{>}` token by two consecutive `>` tokens ([[temp.names]]).
745
 
746
  ### Subscripting <a id="expr.sub">[[expr.sub]]</a>
747
 
748
  A postfix expression followed by an expression in square brackets is a
749
- postfix expression. One of the expressions shall have the type “pointer
750
- to `T`” and the other shall have unscoped enumeration or integral type.
751
- The result is an lvalue of type “`T`.” The type “`T`” shall be a
752
  completely-defined object type.[^5] The expression `E1[E2]` is identical
753
  (by definition) to `*((E1)+(E2))` see  [[expr.unary]] and  [[expr.add]]
754
- for details of `*` and `+` and  [[dcl.array]] for details of arrays.
 
 
755
 
756
  A *braced-init-list* shall not be used with the built-in subscript
757
  operator.
758
 
759
  ### Function call <a id="expr.call">[[expr.call]]</a>
760
 
761
- There are two kinds of function call: ordinary function call and member
762
- function[^6] ([[class.mfct]]) call. A function call is a postfix
763
- expression followed by parentheses containing a possibly empty,
764
- comma-separated list of expressions which constitute the arguments to
765
- the function. For an ordinary function call, the postfix expression
766
- shall be either an lvalue that refers to a function (in which case the
767
- function-to-pointer standard conversion ([[conv.func]]) is suppressed
768
- on the postfix expression), or it shall have pointer to function type.
769
- Calling a function through an expression whose function type has a
770
- language linkage that is different from the language linkage of the
771
- function type of the called function’s definition is undefined (
772
- [[dcl.link]]). For a member function call, the postfix expression shall
773
- be an implicit ([[class.mfct.non-static]],  [[class.static]]) or
774
- explicit class member access ([[expr.ref]]) whose *id-expression* is a
775
- function member name, or a pointer-to-member expression (
776
- [[expr.mptr.oper]]) selecting a function member; the call is as a member
777
- of the class object referred to by the object expression. In the case of
778
- an implicit class member access, the implied object is the one pointed
779
- to by `this`. a member function call of the form `f()` is interpreted as
780
- `(*this).f()` (see  [[class.mfct.non-static]]). If a function or member
781
- function name is used, the name can be overloaded (Clause  [[over]]), in
782
- which case the appropriate function shall be selected according to the
783
- rules in  [[over.match]]. If the selected function is non-virtual, or if
784
- the *id-expression* in the class member access expression is a
 
785
  *qualified-id*, that function is called. Otherwise, its final
786
  overrider ([[class.virtual]]) in the dynamic type of the object
787
- expression is called. the dynamic type is the type of the object
788
- referred to by the current value of the object expression.
789
- [[class.cdtor]] describes the behavior of virtual function calls when
790
- the object expression refers to an object under construction or
791
- destruction.
792
 
793
  If a function or member function name is used, and name lookup (
794
  [[basic.lookup]]) does not find a declaration of that name, the program
795
  is ill-formed. No function is implicitly declared by such a call.
796
 
797
  If the *postfix-expression* designates a destructor ([[class.dtor]]),
798
  the type of the function call expression is `void`; otherwise, the type
799
  of the function call expression is the return type of the statically
800
  chosen function (i.e., ignoring the `virtual` keyword), even if the type
801
- of the function actually called is different. This type shall be an
802
- object type, a reference type or the type `void`.
803
 
804
  When a function is called, each parameter ([[dcl.fct]]) shall be
805
  initialized ([[dcl.init]],  [[class.copy]],  [[class.ctor]]) with its
806
  corresponding argument. Such initializations are indeterminately
807
  sequenced with respect to each other ([[intro.execution]]) If the
@@ -874,16 +1093,16 @@ enumeration type that is subject to the integral promotions (
874
  [[conv.prom]]), or a floating point type that is subject to the floating
875
  point promotion ([[conv.fpprom]]), the value of the argument is
876
  converted to the promoted type before the call. These promotions are
877
  referred to as the *default argument promotions*.
878
 
879
- The evaluations of the postfix expression and of the argument
880
- expressions are all unsequenced relative to one another. All side
881
- effects of argument expression evaluations are sequenced before the
882
- function is entered (see  [[intro.execution]]).
883
 
884
- Recursive calls are permitted, except to the function named `main` (
885
  [[basic.start.main]]).
886
 
887
  A function call is an lvalue if the result type is an lvalue reference
888
  type or an rvalue reference to function type, an xvalue if the result
889
  type is an rvalue reference to object type, and a prvalue otherwise.
@@ -923,14 +1142,15 @@ temporary variable `t`, with the result being the value of `t` as a
923
  prvalue.
924
 
925
  The expression `T()`, where `T` is a *simple-type-specifier* or
926
  *typename-specifier* for a non-array complete object type or the
927
  (possibly cv-qualified) `void` type, creates a prvalue of the specified
928
- type,which is value-initialized ([[dcl.init]]; no initialization is
929
- done for the `void()` case). if `T` is a non-class type that is
930
- cv-qualified, the *cv-qualifier*s are ignored when determining the type
931
- of the resulting prvalue ([[basic.lval]]).
 
932
 
933
  Similarly, a *simple-type-specifier* or *typename-specifier* followed by
934
  a *braced-init-list* creates a temporary object of the specified type
935
  direct-list-initialized ([[dcl.init.list]]) with the specified
936
  *braced-init-list*, and its value is that temporary object as a prvalue.
@@ -960,19 +1180,19 @@ shall designate the same scalar type.
960
  ### Class member access <a id="expr.ref">[[expr.ref]]</a>
961
 
962
  A postfix expression followed by a dot `.` or an arrow `->`, optionally
963
  followed by the keyword `template` ([[temp.names]]), and then followed
964
  by an *id-expression*, is a postfix expression. The postfix expression
965
- before the dot or arrow is evaluated;[^7] the result of that evaluation,
966
  together with the *id-expression*, determines the result of the entire
967
  postfix expression.
968
 
969
  For the first option (dot) the first expression shall have complete
970
  class type. For the second option (arrow) the first expression shall
971
  have pointer to complete class type. The expression `E1->E2` is
972
  converted to the equivalent form `(*(E1)).E2`; the remainder of
973
- [[expr.ref]] will address only the first option (dot).[^8] In either
974
  case, the *id-expression* shall name a member of the class or of one of
975
  its base classes. because the name of a class is inserted in its class
976
  scope (Clause  [[class]]), the name of a class is also considered a
977
  nested member of that class. [[basic.lookup.classref]] describes how
978
  names are looked up after the `.` and `->` operators.
@@ -992,19 +1212,19 @@ rules applies.
992
  `E1.E2` is an lvalue; the expression designates the named member of
993
  the class. The type of `E1.E2` is `T`.
994
  - If `E2` is a non-static data member and the type of `E1` is “*cq1 vq1*
995
  `X`”, and the type of `E2` is “*cq2 vq2* `T`”, the expression
996
  designates the named member of the object designated by the first
997
- expression. If `E1` is an lvalue, then `E1.E2` is an lvalue; if `E1`
998
- is an xvalue, then `E1.E2` is an xvalue; otherwise, it is a prvalue.
999
- Let the notation *vq12* stand for the “union” of *vq1* and *vq2*; that
1000
- is, if *vq1* or *vq2* is `volatile`, then *vq12* is `volatile`.
1001
- Similarly, let the notation *cq12* stand for the “union” of *cq1* and
1002
- *cq2*; that is, if *cq1* or *cq2* is `const`, then *cq12* is `const`.
1003
- If `E2` is declared to be a `mutable` member, then the type of `E1.E2`
1004
- is “*vq12* `T`”. If `E2` is not declared to be a `mutable` member,
1005
- then the type of `E1.E2` is “*cq12* *vq12* `T`”.
1006
  - If `E2` is a (possibly overloaded) member function, function overload
1007
  resolution ([[over.match]]) is used to determine whether `E1.E2`
1008
  refers to a static or a non-static member function.
1009
  - If it refers to a static member function and the type of `E2` is
1010
  “function of parameter-type-list returning `T`”, then `E1.E2` is an
@@ -1077,11 +1297,11 @@ result is the null pointer value of type `T`.
1077
  If `T` is “pointer to *cv1* `B`” and `v` has type “pointer to *cv2* `D`”
1078
  such that `B` is a base class of `D`, the result is a pointer to the
1079
  unique `B` subobject of the `D` object pointed to by `v`. Similarly, if
1080
  `T` is “reference to *cv1* `B`” and `v` has type *cv2* `D` such that `B`
1081
  is a base class of `D`, the result is the unique `B` subobject of the
1082
- `D` object referred to by `v`. [^9] The result is an lvalue if `T` is an
1083
  lvalue reference, or an xvalue if `T` is an rvalue reference. In both
1084
  the pointer and reference cases, the program is ill-formed if *cv2* has
1085
  greater cv-qualification than *cv1* or if `B` is an inaccessible or
1086
  ambiguous base class of `D`.
1087
 
@@ -1091,11 +1311,11 @@ struct D : B { };
1091
  void foo(D* dp) {
1092
  B* bp = dynamic_cast<B*>(dp); // equivalent to B* bp = dp;
1093
  }
1094
  ```
1095
 
1096
- Otherwise, `v` shall be a pointer to or an lvalue of a polymorphic
1097
  type ([[class.virtual]]).
1098
 
1099
  If `T` is “pointer to *cv* `void`,” then the result is a pointer to the
1100
  most derived object pointed to by `v`. Otherwise, a run-time check is
1101
  applied to see if the object pointed or referred to by `v` can be
@@ -1115,12 +1335,13 @@ check logically executes as follows:
1115
  result points (refers) to the `C` subobject of the most derived
1116
  object.
1117
  - Otherwise, the run-time check *fails*.
1118
 
1119
  The value of a failed cast to pointer type is the null pointer value of
1120
- the required result type. A failed cast to reference type throws
1121
- `std::bad_cast` ([[bad.cast]]).
 
1122
 
1123
  ``` cpp
1124
  class A { virtual void f(); };
1125
  class B { virtual void g(); };
1126
  class D : public virtual A, private B { };
@@ -1154,22 +1375,23 @@ object under construction or destruction.
1154
 
1155
  The result of a `typeid` expression is an lvalue of static type `const`
1156
  `std::type_info` ([[type.info]]) and dynamic type `const`
1157
  `std::type_info` or `const` *name* where *name* is an
1158
  *implementation-defined* class publicly derived from `std :: type_info`
1159
- which preserves the behavior described in  [[type.info]].[^10] The
1160
  lifetime of the object referred to by the lvalue extends to the end of
1161
  the program. Whether or not the destructor is called for the
1162
  `std::type_info` object at the end of the program is unspecified.
1163
 
1164
  When `typeid` is applied to a glvalue expression whose type is a
1165
  polymorphic class type ([[class.virtual]]), the result refers to a
1166
  `std::type_info` object representing the type of the most derived
1167
  object ([[intro.object]]) (that is, the dynamic type) to which the
1168
  glvalue refers. If the glvalue expression is obtained by applying the
1169
- unary `*` operator to a pointer[^11] and the pointer is a null pointer
1170
- value ([[conv.ptr]]), the `typeid` expression throws the
 
1171
  `std::bad_typeid` exception ([[bad.typeid]]).
1172
 
1173
  When `typeid` is applied to an expression other than a glvalue of a
1174
  polymorphic class type, the result refers to a `std::type_info` object
1175
  representing the static type of the expression. Lvalue-to-rvalue (
@@ -1185,12 +1407,13 @@ type of the *type-id* is a reference to a possibly *cv*-qualified type,
1185
  the result of the `typeid` expression refers to a `std::type_info`
1186
  object representing the *cv*-unqualified referenced type. If the type of
1187
  the *type-id* is a class type or a reference to a class type, the class
1188
  shall be completely-defined.
1189
 
1190
- The top-level cv-qualifiers of the glvalue expression or the *type-id*
1191
- that is the operand of `typeid` are always ignored.
 
1192
 
1193
  ``` cpp
1194
  class D { /* ... */ };
1195
  D d1;
1196
  const D d2;
@@ -1225,30 +1448,34 @@ and `B` is neither a virtual base class of `D` nor a base class of a
1225
  virtual base class of `D`. The result has type “*cv2* `D`.” An xvalue of
1226
  type “*cv1* `B`” may be cast to type “rvalue reference to *cv2* `D`”
1227
  with the same constraints as for an lvalue of type “*cv1* `B`.” If the
1228
  object of type “*cv1* `B`” is actually a subobject of an object of type
1229
  `D`, the result refers to the enclosing object of type `D`. Otherwise,
1230
- the result of the cast is undefined.
1231
 
1232
  ``` cpp
1233
  struct B { };
1234
  struct D : public B { };
1235
  D d;
1236
  B &br = d;
1237
 
1238
  static_cast<D&>(br); // produces lvalue to the original d object
1239
  ```
1240
 
1241
- A glvalue of type “*cv1* `T1`” can be cast to type “rvalue reference to
1242
- *cv2* `T2`” if “*cv2* `T2`” is reference-compatible with “*cv1* `T1`” (
1243
- [[dcl.init.ref]]). The result refers to the object or the specified base
1244
- class subobject thereof. If `T2` is an inaccessible (Clause 
 
 
 
 
1245
  [[class.access]]) or ambiguous ([[class.member.lookup]]) base class of
1246
  `T1`, a program that necessitates such a cast is ill-formed.
1247
 
1248
- Otherwise, an expression `e` can be explicitly converted to a type `T`
1249
- using a `static_cast` of the form `static_cast<T>(e)` if the declaration
1250
  `T t(e);` is well-formed, for some invented temporary variable `t` (
1251
  [[dcl.init]]). The effect of such an explicit conversion is the same as
1252
  performing the declaration and initialization and then using the
1253
  temporary variable as the result of the conversion. The expression `e`
1254
  is used as a glvalue if and only if the initialization uses it as a
@@ -1288,24 +1515,27 @@ are applied to the operand. Such a `static_cast` is subject to the
1288
  restriction that the explicit conversion does not cast away constness (
1289
  [[expr.const.cast]]), and the following additional rules for specific
1290
  cases:
1291
 
1292
  A value of a scoped enumeration type ([[dcl.enum]]) can be explicitly
1293
- converted to an integral type. The value is unchanged if the original
1294
- value can be represented by the specified type. Otherwise, the resulting
1295
- value is unspecified. A value of a scoped enumeration type can also be
1296
- explicitly converted to a floating-point type; the result is the same as
1297
- that of converting from the original value to the floating-point type.
 
 
 
1298
 
1299
  A value of integral or enumeration type can be explicitly converted to
1300
  an enumeration type. The value is unchanged if the original value is
1301
  within the range of the enumeration values ([[dcl.enum]]). Otherwise,
1302
  the resulting value is unspecified (and might not be in that range). A
1303
- value of floating-point type can also be converted to an enumeration
1304
- type. The resulting value is the same as converting the original value
1305
- to the underlying type of the enumeration ([[conv.fpint]]), and
1306
- subsequently to the enumeration type.
1307
 
1308
  A prvalue of type “pointer to *cv1* `B`,” where `B` is a class type, can
1309
  be converted to a prvalue of type “pointer to *cv2* `D`,” where `D` is a
1310
  class derived (Clause  [[class.derived]]) from `B`, if a valid standard
1311
  conversion from “pointer to `D`” to “pointer to `B`” exists (
@@ -1314,34 +1544,38 @@ cv-qualification than, *cv1*, and `B` is neither a virtual base class of
1314
  `D` nor a base class of a virtual base class of `D`. The null pointer
1315
  value ([[conv.ptr]]) is converted to the null pointer value of the
1316
  destination type. If the prvalue of type “pointer to *cv1* `B`” points
1317
  to a `B` that is actually a subobject of an object of type `D`, the
1318
  resulting pointer points to the enclosing object of type `D`. Otherwise,
1319
- the result of the cast is undefined.
1320
 
1321
  A prvalue of type “pointer to member of `D` of type *cv1* `T`” can be
1322
  converted to a prvalue of type “pointer to member of `B`” of type *cv2*
1323
  `T`, where `B` is a base class (Clause  [[class.derived]]) of `D`, if a
1324
  valid standard conversion from “pointer to member of `B` of type `T`” to
1325
  “pointer to member of `D` of type `T`” exists ([[conv.mem]]), and *cv2*
1326
  is the same cv-qualification as, or greater cv-qualification than,
1327
- *cv1*.[^12] The null member pointer value ([[conv.mem]]) is converted
1328
  to the null member pointer value of the destination type. If class `B`
1329
  contains the original member, or is a base or derived class of the class
1330
  containing the original member, the resulting pointer to member points
1331
- to the original member. Otherwise, the result of the cast is undefined.
1332
- although class `B` need not contain the original member, the dynamic
1333
- type of the object on which the pointer to member is dereferenced must
1334
- contain the original member; see  [[expr.mptr.oper]].
1335
 
1336
  A prvalue of type “pointer to *cv1* `void`” can be converted to a
1337
  prvalue of type “pointer to *cv2* `T`,” where `T` is an object type and
1338
  *cv2* is the same cv-qualification as, or greater cv-qualification than,
1339
  *cv1*. The null pointer value is converted to the null pointer value of
1340
- the destination type. A value of type pointer to object converted to
1341
- “pointer to *cv* `void` and back, possibly with different
1342
- cv-qualification, shall have its original value.
 
 
 
 
1343
 
1344
  ``` cpp
1345
  T* p1 = new T;
1346
  const T* p2 = static_cast<const T*>(static_cast<void*>(p1));
1347
  bool b = p1 == p2; // b will have the value true.
@@ -1394,20 +1628,17 @@ prvalue of type “pointer to `T1`” to the type “pointer to `T2`” (where
1394
  the original pointer value, the result of such a pointer conversion is
1395
  unspecified. see also  [[conv.ptr]] for more details of pointer
1396
  conversions.
1397
 
1398
  An object pointer can be explicitly converted to an object pointer of a
1399
- different type.[^13] When a prvalue `v` of type pointer to `T1`” is
1400
- converted to the type “pointer to cv `T2`”, the result is
1401
- `static_cast<cv T2*>(static_cast<cv void*>(v))` if both `T1` and `T2`
1402
- are standard-layout types ([[basic.types]]) and the alignment
1403
- requirements of `T2` are no stricter than those of `T1`, or if either
1404
- type is `void`. Converting a prvalue of type “pointer to `T1` to the
1405
- type pointer to `T2`” (where `T1` and `T2` are object types and where
1406
- the alignment requirements of `T2` are no stricter than those of `T1`)
1407
- and back to its original type yields the original pointer value. The
1408
- result of any other such pointer conversion is unspecified.
1409
 
1410
  Converting a function pointer to an object pointer type or vice versa is
1411
  conditionally-supported. The meaning of such a conversion is
1412
  *implementation-defined*, except that if an implementation supports
1413
  conversions in both directions, converting a prvalue of one type to the
@@ -1421,11 +1652,11 @@ pointer constant of integral type is not necessarily converted to a null
1421
  pointer value.
1422
 
1423
  A prvalue of type “pointer to member of `X` of type `T1`” can be
1424
  explicitly converted to a prvalue of a different type “pointer to member
1425
  of `Y` of type `T2`” if `T1` and `T2` are both function types or both
1426
- object types.[^14] The null member pointer value ([[conv.mem]]) is
1427
  converted to the null member pointer value of the destination type. The
1428
  result of this conversion is unspecified, except in the following cases:
1429
 
1430
  - converting a prvalue of type “pointer to member function” to a
1431
  different pointer to member function type and back to its original
@@ -1434,22 +1665,20 @@ result of this conversion is unspecified, except in the following cases:
1434
  `T1`” to the type “pointer to data member of `Y` of type `T2`” (where
1435
  the alignment requirements of `T2` are no stricter than those of `T1`)
1436
  and back to its original type yields the original pointer to member
1437
  value.
1438
 
1439
- An lvalue expression of type `T1` can be cast to the type “reference to
1440
  `T2`” if an expression of type “pointer to `T1`” can be explicitly
1441
- converted to the type “pointer to `T2`” using a `reinterpret_cast`. That
1442
- is, a reference cast `reinterpret_cast<T&>(x)` has the same effect as
1443
- the conversion `*reinterpret_cast<T*>(&x)` with the built-in `&` and `*`
1444
- operators (and similarly for `reinterpret_cast<T&&>(x)`). The result
1445
- refers to the same object as the source lvalue, but with a different
1446
- type. The result is an lvalue for an lvalue reference type or an rvalue
1447
- reference to function type and an xvalue for an rvalue reference to
1448
- object type. No temporary is created, no copy is made, and
1449
- constructors ([[class.ctor]]) or conversion functions ([[class.conv]])
1450
- are not called.[^15]
1451
 
1452
  ### Const cast <a id="expr.const.cast">[[expr.const.cast]]</a>
1453
 
1454
  The result of the expression `const_cast<T>(v)` is of type `T`. If `T`
1455
  is an lvalue reference to object type, the result is an lvalue; if `T`
@@ -1501,11 +1730,11 @@ value of the destination type. The null member pointer value (
1501
  [[conv.mem]]) is converted to the null member pointer value of the
1502
  destination type.
1503
 
1504
  Depending on the type of the object, a write operation through the
1505
  pointer, lvalue or pointer to data member resulting from a `const_cast`
1506
- that casts away a const-qualifier[^16] may produce undefined behavior (
1507
  [[dcl.type.cv]]).
1508
 
1509
  The following rules define the process known as *casting away
1510
  constness*. In these rules `Tn ` and `Xn ` represent types. For two
1511
  pointer types:
@@ -1568,15 +1797,15 @@ unary-operator: one of
1568
 
1569
  The unary `*` operator performs *indirection*: the expression to which
1570
  it is applied shall be a pointer to an object type, or a pointer to a
1571
  function type and the result is an lvalue referring to the object or
1572
  function to which the expression points. If the type of the expression
1573
- is “pointer to `T`,” the type of the result is “`T`.” a pointer to an
1574
- incomplete type (other than *cv* `void`) can be dereferenced. The lvalue
1575
- thus obtained can be used in limited ways (to initialize a reference,
1576
- for example); this lvalue must not be converted to a prvalue, see 
1577
- [[conv.lval]].
1578
 
1579
  The result of each of the following unary operators is a prvalue.
1580
 
1581
  The result of the unary `&` operator is a pointer to its operand. The
1582
  operand shall be an lvalue or a *qualified-id*. If the operand is a
@@ -1608,14 +1837,14 @@ from a *qualified-id* for a non-static member function to the type
1608
  “pointer to member function” as there is from an lvalue of function type
1609
  to the type “pointer to function” ([[conv.func]]). Nor is
1610
  `&unqualified-id` a pointer to member, even within the scope of the
1611
  *unqualified-id*’s class.
1612
 
1613
- The address of an object of incomplete type can be taken, but if the
1614
- complete type of that object is a class type that declares `operator&()`
1615
- as a member function, then the behavior is undefined (and no diagnostic
1616
- is required). The operand of `&` shall not be a bit-field.
1617
 
1618
  The address of an overloaded function (Clause  [[over]]) can be taken
1619
  only in a context that uniquely determines which version of the
1620
  overloaded function is referred to (see  [[over.over]]). since the
1621
  context might determine whether the operand is a static or non-static
@@ -1670,27 +1899,27 @@ The `sizeof` operator yields the number of bytes in the object
1670
  representation of its operand. The operand is either an expression,
1671
  which is an unevaluated operand (Clause  [[expr]]), or a parenthesized
1672
  *type-id*. The `sizeof` operator shall not be applied to an expression
1673
  that has function or incomplete type, to an enumeration type whose
1674
  underlying type is not fixed before all its enumerators have been
1675
- declared, to the parenthesized name of such types, or to an lvalue that
1676
  designates a bit-field. `sizeof(char)`, `sizeof(signed char)` and
1677
  `sizeof(unsigned char)` are `1`. The result of `sizeof` applied to any
1678
  other fundamental type ([[basic.fundamental]]) is
1679
  *implementation-defined*. in particular, `sizeof(bool)`,
1680
  `sizeof(char16_t)`, `sizeof(char32_t)`, and `sizeof(wchar_t)` are
1681
- implementation-defined.[^17] See  [[intro.memory]] for the definition of
1682
  *byte* and  [[basic.types]] for the definition of *object
1683
  representation*.
1684
 
1685
  When applied to a reference or a reference type, the result is the size
1686
  of the referenced type. When applied to a class, the result is the
1687
  number of bytes in an object of that class including any padding
1688
  required for placing objects of that type in an array. The size of a
1689
  most derived class shall be greater than zero ([[intro.object]]). The
1690
  result of applying `sizeof` to a base class subobject is the size of the
1691
- base class type.[^18] When applied to an array, the result is the total
1692
  number of bytes in the array. This implies that the size of an array of
1693
  *n* elements is *n* times the size of an element.
1694
 
1695
  The `sizeof` operator can be applied to a pointer to a function, but
1696
  shall not be applied directly to a function.
@@ -1829,35 +2058,43 @@ denotes an array type), the *new-expression* yields a pointer to the
1829
  initial element (if any) of the array. both `new int` and `new int[10]`
1830
  have type `int*` and the type of `new int[i][10]` is `int (*)[10]` The
1831
  *attribute-specifier-seq* in a *noptr-new-declarator* appertains to the
1832
  associated array type.
1833
 
1834
- Every *constant-expression* in a *noptr-new-declarator* shall be an
1835
- integral constant expression ([[expr.const]]) and evaluate to a
1836
- strictly positive value. The *expression* in a *noptr-new-declarator*
1837
- shall be of integral type, unscoped enumeration type, or a class type
1838
- for which a single non-explicit conversion function to integral or
1839
- unscoped enumeration type exists ([[class.conv]]). If the expression is
1840
- of class type, the expression is converted by calling that conversion
1841
- function, and the result of the conversion is used in place of the
1842
- original expression. given the definition `int n = 42`,
1843
- `new float[n][5]` is well-formed (because `n` is the *expression* of a
1844
- *noptr-new-declarator*), but `new float[5][n]` is ill-formed (because
1845
- `n` is not a constant expression).
1846
 
1847
- When the value of the *expression* in a *noptr-new-declarator* is zero,
1848
- the allocation function is called to allocate an array with no elements.
1849
- If the value of that *expression* is less than zero or such that the
1850
- size of the allocated object would exceed the implementation-defined
1851
- limit, or if the *new-initializer* is a *braced-init-list* for which the
1852
- number of *initializer-clause*s exceeds the number of elements to
1853
- initialize, no storage is obtained and the *new-expression* terminates
1854
- by throwing an exception of a type that would match a handler (
1855
- [[except.handle]]) of type `std::bad_array_new_length` (
1856
- [[new.badlength]]).
1857
 
1858
- A *new-expression* obtains storage for the object by calling an
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1859
  *allocation function* ([[basic.stc.dynamic.allocation]]). If the
1860
  *new-expression* terminates by throwing an exception, it may release
1861
  storage by calling a deallocation function (
1862
  [[basic.stc.dynamic.deallocation]]). If the allocated type is a
1863
  non-array type, the allocation function’s name is `operator new` and the
@@ -1875,24 +2112,76 @@ allocation function’s name is looked up in the global scope. Otherwise,
1875
  if the allocated type is a class type `T` or array thereof, the
1876
  allocation function’s name is looked up in the scope of `T`. If this
1877
  lookup fails to find the name, or if the allocated type is not a class
1878
  type, the allocation function’s name is looked up in the global scope.
1879
 
1880
- A *new-expression* passes the amount of space requested to the
1881
- allocation function as the first argument of type `std::size_t`. That
1882
- argument shall be no less than the size of the object being created; it
1883
- may be greater than the size of the object being created only if the
1884
- object is an array. For arrays of `char` and `unsigned char`, the
1885
- difference between the result of the *new-expression* and the address
1886
- returned by the allocation function shall be an integral multiple of the
1887
- strictest fundamental alignment requirement ([[basic.align]]) of any
1888
- object type whose size is no greater than the size of the array being
1889
- created. Because allocation functions are assumed to return pointers to
1890
- storage that is appropriately aligned for objects of any type with
1891
- fundamental alignment, this constraint on array allocation overhead
1892
- permits the common idiom of allocating character arrays into which
1893
- objects of other types will later be placed.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1894
 
1895
  The *new-placement* syntax is used to supply additional arguments to an
1896
  allocation function. If used, overload resolution is performed on a
1897
  function call created by assembling an argument list consisting of the
1898
  amount of space requested (the first argument) and the expressions in
@@ -1937,12 +2226,12 @@ necessarily be the same as that of the block if the object is an array.
1937
 
1938
  A *new-expression* that creates an object of type `T` initializes that
1939
  object as follows:
1940
 
1941
  - If the *new-initializer* is omitted, the object is
1942
- default-initialized ([[dcl.init]]); if no initialization is
1943
- performed, the object has indeterminate value.
1944
  - Otherwise, the *new-initializer* is interpreted according to the
1945
  initialization rules of  [[dcl.init]] for direct-initialization.
1946
 
1947
  The invocation of the allocation function is indeterminately sequenced
1948
  with respect to the evaluations of expressions in the *new-initializer*.
@@ -1952,23 +2241,24 @@ expressions in the *new-initializer* are evaluated if the allocation
1952
  function returns the null pointer or exits using an exception.
1953
 
1954
  If the *new-expression* creates an object or an array of objects of
1955
  class type, access and ambiguity control are done for the allocation
1956
  function, the deallocation function ([[class.free]]), and the
1957
- constructor ([[class.ctor]]). If the new expression creates an array of
1958
- objects of class type, access and ambiguity control are done for the
1959
- destructor ([[class.dtor]]).
1960
 
1961
  If any part of the object initialization described above[^19] terminates
1962
- by throwing an exception and a suitable deallocation function can be
1963
- found, the deallocation function is called to free the memory in which
1964
- the object was being constructed, after which the exception continues to
1965
- propagate in the context of the *new-expression*. If no unambiguous
1966
- matching deallocation function can be found, propagating the exception
1967
- does not cause the object’s memory to be freed. This is appropriate when
1968
- the called allocation function does not allocate memory; otherwise, it
1969
- is likely to result in a memory leak.
 
1970
 
1971
  If the *new-expression* begins with a unary `::` operator, the
1972
  deallocation function’s name is looked up in the global scope.
1973
  Otherwise, if the allocated type is a class type `T` or an array
1974
  thereof, the deallocation function’s name is looked up in the scope of
@@ -1977,19 +2267,19 @@ not a class type or array thereof, the deallocation function’s name is
1977
  looked up in the global scope.
1978
 
1979
  A declaration of a placement deallocation function matches the
1980
  declaration of a placement allocation function if it has the same number
1981
  of parameters and, after parameter transformations ([[dcl.fct]]), all
1982
- parameter types except the first are identical. Any non-placement
1983
- deallocation function matches a non-placement allocation function. If
1984
- the lookup finds a single matching deallocation function, that function
1985
- will be called; otherwise, no deallocation function will be called. If
1986
- the lookup finds the two-parameter form of a usual deallocation
1987
- function ([[basic.stc.dynamic.deallocation]]) and that function,
1988
- considered as a placement deallocation function, would have been
1989
- selected as a match for the allocation function, the program is
1990
- ill-formed.
1991
 
1992
  ``` cpp
1993
  struct S {
1994
  // Placement allocation function:
1995
  static void* operator new(std::size_t, std::size_t);
@@ -2026,13 +2316,14 @@ delete-expression:
2026
  ```
2027
 
2028
  The first alternative is for non-array objects, and the second is for
2029
  arrays. Whenever the `delete` keyword is immediately followed by empty
2030
  square brackets, it shall be interpreted as the second alternative.[^20]
2031
- The operand shall have a pointer to object type, or a class type having
2032
- a single non-explicit conversion function ([[class.conv.fct]]) to a
2033
- pointer to object type. The result has type `void`.[^21]
 
2034
 
2035
  If the operand has a class type, the operand is converted to a pointer
2036
  type by calling the above-mentioned conversion function, and the
2037
  converted operand is used in place of the original operand for the
2038
  remainder of this section. In the first alternative (*delete object*),
@@ -2071,41 +2362,74 @@ any) for the object or the elements of the array being deleted. In the
2071
  case of an array, the elements will be destroyed in order of decreasing
2072
  address (that is, in reverse order of the completion of their
2073
  constructor; see  [[class.base.init]]).
2074
 
2075
  If the value of the operand of the *delete-expression* is not a null
2076
- pointer value, the *delete-expression* will call a *deallocation
2077
- function* ([[basic.stc.dynamic.deallocation]]). Otherwise, it is
2078
- unspecified whether the deallocation function will be called. The
2079
- deallocation function is called regardless of whether the destructor for
2080
- the object or some element of the array throws an exception.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2081
 
2082
  An implementation provides default definitions of the global
2083
  deallocation functions `operator delete()` for non-arrays (
2084
  [[new.delete.single]]) and `operator delete[]()` for arrays (
2085
  [[new.delete.array]]). A C++ program can provide alternative definitions
2086
  of these functions ([[replacement.functions]]), and/or class-specific
2087
  versions ([[class.free]]).
2088
 
2089
  When the keyword `delete` in a *delete-expression* is preceded by the
2090
- unary `::` operator, the global deallocation function is used to
2091
- deallocate the storage.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2092
 
2093
  Access and ambiguity control are done for both the deallocation function
2094
  and the destructor ([[class.dtor]],  [[class.free]]).
2095
 
2096
  ### Alignof <a id="expr.alignof">[[expr.alignof]]</a>
2097
 
2098
  An `alignof` expression yields the alignment requirement of its operand
2099
  type. The operand shall be a *type-id* representing a complete object
2100
- type or an array thereof or a reference to a complete object type.
2101
 
2102
  The result is an integral constant of type `std::size_t`.
2103
 
2104
- When `alignof` is applied to a reference type, the result shall be the
2105
  alignment of the referenced type. When `alignof` is applied to an array
2106
- type, the result shall be the alignment of the element type.
2107
 
2108
  ### `noexcept` operator <a id="expr.unary.noexcept">[[expr.unary.noexcept]]</a>
2109
 
2110
  The `noexcept` operator determines whether the evaluation of its
2111
  operand, which is an unevaluated operand (Clause  [[expr]]), can throw
@@ -2115,24 +2439,24 @@ an exception ([[except.throw]]).
2115
  noexcept-expression:
2116
  'noexcept' '(' expression ')'
2117
  ```
2118
 
2119
  The result of the `noexcept` operator is a constant of type `bool` and
2120
- is an rvalue.
2121
 
2122
  The result of the `noexcept` operator is `false` if in a
2123
  potentially-evaluated context the *expression* would contain
2124
 
2125
- - a potentially evaluated call[^23] to a function, member function,
2126
  function pointer, or member function pointer that does not have a
2127
  non-throwing *exception-specification* ([[except.spec]]), unless the
2128
  call is a constant expression ([[expr.const]]),
2129
- - a potentially evaluated *throw-expression* ([[except.throw]]),
2130
- - a potentially evaluated `dynamic_cast` expression
2131
  `dynamic_cast<T>(v)`, where `T` is a reference type, that requires a
2132
  run-time check ([[expr.dynamic.cast]]), or
2133
- - a potentially evaluated `typeid` expression ([[expr.typeid]]) applied
2134
  to a glvalue expression whose type is a polymorphic class type (
2135
  [[class.virtual]]).
2136
 
2137
  Otherwise, the result is `true`.
2138
 
@@ -2140,12 +2464,12 @@ Otherwise, the result is `true`.
2140
 
2141
  The result of the expression `(T)` *cast-expression* is of type `T`. The
2142
  result is an lvalue if `T` is an lvalue reference type or an rvalue
2143
  reference to function type and an xvalue if `T` is an rvalue reference
2144
  to object type; otherwise the result is a prvalue. if `T` is a non-class
2145
- type that is *cv-qualified*, the *cv-qualifiers* are ignored when
2146
- determining the type of the resulting prvalue; see  [[basic.lval]].
2147
 
2148
  An explicit type conversion can be expressed using functional notation (
2149
  [[expr.type.conv]]), a type conversion operator (`dynamic_cast`,
2150
  `static_cast`, `reinterpret_cast`, `const_cast`), or the *cast*
2151
  notation.
@@ -2220,21 +2544,20 @@ pm-expression:
2220
  pm-expression '.*' cast-expression
2221
  pm-expression '->*' cast-expression
2222
  ```
2223
 
2224
  The binary operator `.*` binds its second operand, which shall be of
2225
- type “pointer to member of `T`” (where `T` is a completely-defined class
2226
- type) to its first operand, which shall be of class `T` or of a class of
2227
- which `T` is an unambiguous and accessible base class. The result is an
2228
- object or a function of the type specified by the second operand.
2229
 
2230
  The binary operator `->*` binds its second operand, which shall be of
2231
- type “pointer to member of `T`” (where `T` is a completely-defined class
2232
- type) to its first operand, which shall be of type “pointer to `T` or
2233
- “pointer to a class of which `T` is an unambiguous and accessible base
2234
- class.” The expression `E1->*E2` is converted into the equivalent form
2235
- `(*(E1)).*E2`.
2236
 
2237
  Abbreviating *pm-expression*`.*`*cast-expression* as `E1.*E2`, `E1` is
2238
  called the *object expression*. If the dynamic type of `E1` does not
2239
  contain the member to which `E2` refers, the behavior is undefined.
2240
 
@@ -2270,12 +2593,12 @@ pointed to by `ptr_to_obj`. In a `.*` expression whose object expression
2270
  is an rvalue, the program is ill-formed if the second operand is a
2271
  pointer to member function with *ref-qualifier* `&`. In a `.*`
2272
  expression whose object expression is an lvalue, the program is
2273
  ill-formed if the second operand is a pointer to member function with
2274
  *ref-qualifier* `&&`. The result of a `.*` expression whose second
2275
- operand is a pointer to a data member is of the same value category (
2276
- [[basic.lval]]) as its first operand. The result of a `.*` expression
2277
  whose second operand is a pointer to a member function is a prvalue. If
2278
  the second operand is the null pointer to member value ([[conv.mem]]),
2279
  the behavior is undefined.
2280
 
2281
  ## Multiplicative operators <a id="expr.mul">[[expr.mul]]</a>
@@ -2299,13 +2622,13 @@ The binary `*` operator indicates multiplication.
2299
 
2300
  The binary `/` operator yields the quotient, and the binary `%` operator
2301
  yields the remainder from the division of the first expression by the
2302
  second. If the second operand of `/` or `%` is zero the behavior is
2303
  undefined. For integral operands the `/` operator yields the algebraic
2304
- quotient with any fractional part discarded;[^24] if the quotient `a/b`
2305
  is representable in the type of the result, `(a/b)*b + a%b` is equal to
2306
- `a`.
2307
 
2308
  ## Additive operators <a id="expr.add">[[expr.add]]</a>
2309
 
2310
  The additive operators `+` and `-` group left-to-right. The usual
2311
  arithmetic conversions are performed for operands of arithmetic or
@@ -2375,11 +2698,17 @@ to the last element of the same array object, the expression
2375
  `-((P)-((Q)+1))`, and has the value zero if the expression `P` points
2376
  one past the last element of the array object, even though the
2377
  expression `(Q)+1` does not point to an element of the array object.
2378
  Unless both pointers point to elements of the same array object, or one
2379
  past the last element of the array object, the behavior is
2380
- undefined.[^25]
 
 
 
 
 
 
2381
 
2382
  If the value 0 is added to or subtracted from a pointer value, the
2383
  result compares equal to the original pointer value. If two pointers
2384
  point to the same object or both point one past the end of the same
2385
  array or both are null, and the two pointers are subtracted, the result
@@ -2405,12 +2734,14 @@ left operand.
2405
  The value of `E1 << E2` is `E1` left-shifted `E2` bit positions; vacated
2406
  bits are zero-filled. If `E1` has an unsigned type, the value of the
2407
  result is $\mathrm{E1}\times2^\mathrm{E2}$, reduced modulo one more than
2408
  the maximum value representable in the result type. Otherwise, if `E1`
2409
  has a signed type and non-negative value, and
2410
- $\mathrm{E1}\times2^\mathrm{E2}$ is representable in the result type,
2411
- then that is the resulting value; otherwise, the behavior is undefined.
 
 
2412
 
2413
  The value of `E1 >> E2` is `E1` right-shifted `E2` bit positions. If
2414
  `E1` has an unsigned type or if `E1` has a signed type and a
2415
  non-negative value, the value of the result is the integral part of the
2416
  quotient of $\mathrm{E1}/2^\mathrm{E2}$. If `E1` has a signed type and a
@@ -2428,79 +2759,42 @@ relational-expression:
2428
  relational-expression '>' shift-expression
2429
  relational-expression '<=' shift-expression
2430
  relational-expression '>=' shift-expression
2431
  ```
2432
 
2433
- The operands shall have arithmetic, enumeration, or pointer type, or
2434
- type `std::nullptr_t`. The operators `<` (less than), `>` (greater
2435
- than), `<=` (less than or equal to), and `>=` (greater than or equal to)
2436
- all yield `false` or `true`. The type of the result is `bool`.
2437
 
2438
  The usual arithmetic conversions are performed on operands of arithmetic
2439
- or enumeration type. Pointer conversions ([[conv.ptr]]) and
2440
- qualification conversions ([[conv.qual]]) are performed on pointer
2441
- operands (or on a pointer operand and a null pointer constant, or on two
2442
- null pointer constants, at least one of which is non-integral) to bring
2443
- them to their *composite pointer type*. If one operand is a null pointer
2444
- constant, the composite pointer type is `std::nullptr_t` if the other
2445
- operand is also a null pointer constant or, if the other operand is a
2446
- pointer, the type of the other operand. Otherwise, if one of the
2447
- operands has type “pointer to *cv1* `void`,” then the other has type
2448
- “pointer to *cv2* *T*” and the composite pointer type is “pointer to
2449
- *cv12* `void`,” where *cv12* is the union of *cv1* and *cv2*. Otherwise,
2450
- the composite pointer type is a pointer type similar ([[conv.qual]]) to
2451
- the type of one of the operands, with a cv-qualification signature (
2452
- [[conv.qual]]) that is the union of the cv-qualification signatures of
2453
- the operand types. this implies that any pointer can be compared to a
2454
- null pointer constant and that any object pointer can be compared to a
2455
- pointer to (possibly cv-qualified) `void`.
2456
 
2457
- ``` cpp
2458
- void *p;
2459
- const int *q;
2460
- int **pi;
2461
- const int *const *pci;
2462
- void ct() {
2463
- p <= q; // Both converted to const void* before comparison
2464
- pi <= pci; // Both converted to const int *const * before comparison
2465
- }
2466
- ```
2467
 
2468
- Pointers to objects or functions of the same type (after pointer
2469
- conversions) can be compared, with a result defined as follows:
 
 
 
 
 
 
 
 
 
2470
 
2471
- - If two pointers `p` and `q` of the same type point to the same object
2472
- or function, or both point one past the end of the same array, or are
2473
- both null, then `p<=q` and `p>=q` both yield `true` and `p<q` and
2474
- `p>q` both yield `false`.
2475
- - If two pointers `p` and `q` of the same type point to different
2476
- objects that are not members of the same object or elements of the
2477
- same array or to different functions, or if only one of them is null,
2478
- the results of `p<q`, `p>q`, `p<=q`, and `p>=q` are unspecified.
2479
- - If two pointers point to non-static data members of the same object,
2480
- or to subobjects or array elements of such members, recursively, the
2481
- pointer to the later declared member compares greater provided the two
2482
- members have the same access control (Clause  [[class.access]]) and
2483
- provided their class is not a union.
2484
- - If two pointers point to non-static data members of the same object
2485
- with different access control (Clause  [[class.access]]) the result is
2486
- unspecified.
2487
- - If two pointers point to non-static data members of the same union
2488
- object, they compare equal (after conversion to `void*`, if
2489
- necessary). If two pointers point to elements of the same array or one
2490
- beyond the end of the array, the pointer to the object with the higher
2491
- subscript compares higher.
2492
- - Other pointer comparisons are unspecified.
2493
-
2494
- Pointers to `void` (after pointer conversions) can be compared, with a
2495
- result defined as follows: If both pointers represent the same address
2496
- or are both the null pointer value, the result is `true` if the operator
2497
- is `<=` or `>=` and `false` otherwise; otherwise the result is
2498
- unspecified.
2499
-
2500
- If two operands of type `std::nullptr_t` are compared, the result is
2501
- `true` if the operator is `<=` or `>=`, and `false` otherwise.
2502
 
2503
  If both operands (after conversions) are of arithmetic or enumeration
2504
  type, each of the operators shall yield `true` if the specified
2505
  relationship is true and `false` if it is false.
2506
 
@@ -2511,36 +2805,54 @@ equality-expression:
2511
  relational-expression
2512
  equality-expression '==' relational-expression
2513
  equality-expression '!=' relational-expression
2514
  ```
2515
 
2516
- The `==` (equal to) and the `!=` (not equal to) operators have the same
2517
- semantic restrictions, conversions, and result type as the relational
2518
- operators except for their lower precedence and truth-value result.
2519
- `a<b == c<d` is `true` whenever `a<b` and `c<d` have the same
2520
- truth-value. Pointers of the same type (after pointer conversions) can
2521
- be compared for equality. Two pointers of the same type compare equal if
2522
- and only if they are both null, both point to the same function, or both
2523
- represent the same address ([[basic.compound]]).
2524
 
2525
- In addition, pointers to members can be compared, or a pointer to member
2526
- and a null pointer constant. Pointer to member conversions (
2527
- [[conv.mem]]) and qualification conversions ([[conv.qual]]) are
2528
- performed to bring them to a common type. If one operand is a null
2529
- pointer constant, the common type is the type of the other operand.
2530
- Otherwise, the common type is a pointer to member type similar (
2531
- [[conv.qual]]) to the type of one of the operands, with a
2532
- cv-qualification signature ([[conv.qual]]) that is the union of the
2533
- cv-qualification signatures of the operand types. this implies that any
2534
- pointer to member can be compared to a null pointer constant. If both
2535
- operands are null, they compare equal. Otherwise if only one is null,
2536
- they compare unequal. Otherwise if either is a pointer to a virtual
2537
- member function, the result is unspecified. Otherwise they compare equal
2538
- if and only if they would refer to the same member of the same most
2539
- derived object ([[intro.object]]) or the same subobject if they were
2540
- dereferenced with a hypothetical object of the associated class type.
2541
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2542
  ``` cpp
2543
  struct B {
2544
  int f();
2545
  };
2546
  struct L : B { };
@@ -2551,17 +2863,26 @@ int (B::*pb)() = &B::f;
2551
  int (L::*pl)() = pb;
2552
  int (R::*pr)() = pb;
2553
  int (D::*pdl)() = pl;
2554
  int (D::*pdr)() = pr;
2555
  bool x = (pdl == pdr); // false
 
2556
  ```
2557
 
2558
- If two operands of type `std::nullptr_t` are compared, the result is
2559
- `true` if the operator is `==`, and `false` otherwise.
2560
 
2561
- Each of the operators shall yield `true` if the specified relationship
2562
- is true and `false` if it is false.
 
 
 
 
 
 
 
 
2563
 
2564
  ## Bitwise AND operator <a id="expr.bit.and">[[expr.bit.and]]</a>
2565
 
2566
  ``` bnf
2567
  and-expression:
@@ -2604,11 +2925,11 @@ logical-and-expression:
2604
  inclusive-or-expression
2605
  logical-and-expression '&&' inclusive-or-expression
2606
  ```
2607
 
2608
  The `&&` operator groups left-to-right. The operands are both
2609
- contextually converted to type `bool` (Clause  [[conv]]). The result is
2610
  `true` if both operands are `true` and `false` otherwise. Unlike `&`,
2611
  `&&` guarantees left-to-right evaluation: the second operand is not
2612
  evaluated if the first operand is `false`.
2613
 
2614
  The result is a `bool`. If the second expression is evaluated, every
@@ -2650,19 +2971,16 @@ of the second expression, otherwise that of the third expression. Only
2650
  one of the second and third expressions is evaluated. Every value
2651
  computation and side effect associated with the first expression is
2652
  sequenced before every value computation and side effect associated with
2653
  the second or third expression.
2654
 
2655
- If either the second or the third operand has type `void`, then the
2656
- lvalue-to-rvalue ([[conv.lval]]), array-to-pointer ([[conv.array]]),
2657
- and function-to-pointer ([[conv.func]]) standard conversions are
2658
- performed on the second and third operands, and one of the following
2659
- shall hold:
2660
 
2661
- - The second or the third operand (but not both) is a
2662
- *throw-expression* ([[except.throw]]); the result is of the type of
2663
- the other and is a prvalue.
2664
  - Both the second and the third operands have type `void`; the result is
2665
  of type `void` and is a prvalue. This includes the case where both
2666
  operands are *throw-expression*s.
2667
 
2668
  Otherwise, if the second and third operand have different types and
@@ -2678,11 +2996,11 @@ expression `E2` of type `T2` is defined as follows:
2678
  reference to `T2`”, subject to the constraint that in the conversion
2679
  the reference must bind directly ([[dcl.init.ref]]) to an lvalue.
2680
  - If `E2` is an xvalue: `E1` can be converted to match `E2` if `E1` can
2681
  be implicitly converted to the type “rvalue reference to `T2`”,
2682
  subject to the constraint that the reference must bind directly.
2683
- - If `E2` is an rvalue or if neither of the conversions above can be
2684
  done and at least one of the operands has (possibly cv-qualified)
2685
  class type:
2686
  - if `E1` and `E2` have class type, and the underlying class types are
2687
  the same or one is a base class of the other: `E1` can be converted
2688
  to match `E2` if the class of `T2` is the same type as, or a base
@@ -2698,18 +3016,18 @@ expression `E2` of type `T2` is defined as follows:
2698
  match `E2` if `E1` can be implicitly converted to the type that
2699
  expression `E2` would have if `E2` were converted to a prvalue (or
2700
  the type it has, if `E2` is a prvalue).
2701
 
2702
  Using this process, it is determined whether the second operand can be
2703
- converted to match the third operand, and whether the third operand
2704
- can be converted to match the second operand. If both can be
2705
- converted, or one can be converted but the conversion is ambiguous,
2706
- the program is ill-formed. If neither can be converted, the operands
2707
- are left unchanged and further checking is performed as described
2708
- below. If exactly one conversion is possible, that conversion is
2709
- applied to the chosen operand and the converted operand is used in
2710
- place of the original operand for the remainder of this section.
2711
 
2712
  If the second and third operands are glvalues of the same value category
2713
  and have the same type, the result is of that type and value category
2714
  and it is a bit-field if the second or the third operand is a bit-field,
2715
  or if both are bit-fields.
@@ -2734,23 +3052,22 @@ of the following shall hold:
2734
  the second operand or the third operand depending on the value of the
2735
  first operand.
2736
  - The second and third operands have arithmetic or enumeration type; the
2737
  usual arithmetic conversions are performed to bring them to a common
2738
  type, and the result is of that type.
2739
- - The second and third operands have pointer type, or one has pointer
2740
- type and the other is a null pointer constant, or both are null
2741
- pointer constants, at least one of which is non-integral; pointer
2742
- conversions ([[conv.ptr]]) and qualification conversions (
2743
  [[conv.qual]]) are performed to bring them to their composite pointer
2744
- type ([[expr.rel]]). The result is of the composite pointer type.
2745
- - The second and third operands have pointer to member type, or one has
2746
- pointer to member type and the other is a null pointer constant;
2747
- pointer to member conversions ([[conv.mem]]) and qualification
2748
- conversions ([[conv.qual]]) are performed to bring them to a common
2749
- type, whose cv-qualification shall match the cv-qualification of
2750
- either the second or the third operand. The result is of the common
2751
- type.
 
2752
 
2753
  ## Assignment and compound assignment operators <a id="expr.ass">[[expr.ass]]</a>
2754
 
2755
  The assignment operator (`=`) and the compound assignment operators all
2756
  group right-to-left. All require a modifiable lvalue as their left
@@ -2811,16 +3128,16 @@ may be aliased in general. See  [[basic.lval]].
2811
 
2812
  A *braced-init-list* may appear on the right-hand side of
2813
 
2814
  - an assignment to a scalar, in which case the initializer list shall
2815
  have at most a single element. The meaning of `x={v}`, where `T` is
2816
- the scalar type of the expression `x`, is that of `x=T(v)` except that
2817
- no narrowing conversion ([[dcl.init.list]]) is allowed. The meaning
2818
- of `x={}` is `x=T()`.
2819
- - an assignment defined by a user-defined assignment operator, in which
2820
- case the initializer list is passed as the argument to the operator
2821
- function.
2822
 
2823
  ``` cpp
2824
  complex<double> z;
2825
  z = { 1,2 }; // meaning z.operator=({1,2\)}
2826
  z += { 1, 2 }; // meaning z.operator+=({1,2\)}
@@ -2839,16 +3156,18 @@ expression:
2839
  expression ',' assignment-expression
2840
  ```
2841
 
2842
  A pair of expressions separated by a comma is evaluated left-to-right;
2843
  the left expression is a discarded-value expression (Clause 
2844
- [[expr]]).[^26] Every value computation and side effect associated with
2845
  the left expression is sequenced before every value computation and side
2846
  effect associated with the right expression. The type and value of the
2847
  result are the type and value of the right operand; the result is of the
2848
  same value category as its right operand, and is a bit-field if its
2849
- right operand is a glvalue and a bit-field.
 
 
2850
 
2851
  In contexts where comma is given a special meaning, in lists of
2852
  arguments to functions ([[expr.call]]) and lists of initializers (
2853
  [[dcl.init]]) the comma operator as described in Clause  [[expr]] can
2854
  appear only in parentheses.
@@ -2871,126 +3190,147 @@ during translation.
2871
  ``` bnf
2872
  constant-expression:
2873
  conditional-expression
2874
  ```
2875
 
2876
- A *conditional-expression* is a *core constant expression* unless it
2877
- involves one of the following as a potentially evaluated subexpression (
2878
- [[basic.def.odr]]), but subexpressions of logical AND (
2879
- [[expr.log.and]]), logical OR ([[expr.log.or]]), and conditional (
2880
- [[expr.cond]]) operations that are not evaluated are not considered An
2881
- overloaded operator invokes a function.:
2882
 
2883
- - `this` ([[expr.prim]]) unless it appears as the *postfix-expression*
2884
- in a class member access expression, including the result of the
2885
- implicit transformation in the body of a non-static member function (
2886
- [[class.mfct.non-static]]);
2887
  - an invocation of a function other than a `constexpr` constructor for a
2888
- literal class or a `constexpr` function Overload resolution (
 
2889
  [[over.match]]) is applied as usual ;
2890
  - an invocation of an undefined `constexpr` function or an undefined
2891
- `constexpr` constructor outside the definition of a `constexpr`
2892
- function or a `constexpr` constructor;
2893
- - an invocation of a `constexpr` function with arguments that, when
2894
- substituted by function invocation substitution ([[dcl.constexpr]]),
2895
- do not produce a constant expression;
2896
- ``` cpp
2897
- constexpr const int* addr(const int& ir) { return &ir; } // OK
2898
- static const int x = 5;
2899
- constexpr const int* xp = addr(x); // OK: (const int*)&(const int&)x is an
2900
- // address constant expression
2901
- constexpr const int* tp = addr(5); // error, initializer for constexpr variable not a constant
2902
- // expression; (const int*)&(const int&)5 is not a constant
2903
- // expression because it takes the address of a temporary
2904
- ```
2905
- - an invocation of a `constexpr` constructor with arguments that, when
2906
- substituted by function invocation substitution ([[dcl.constexpr]]),
2907
- do not produce all constant expressions for the constructor calls and
2908
- full-expressions in the *mem-initializer*s;
2909
- ``` cpp
2910
- int x; // not constant
2911
- struct A {
2912
- constexpr A(bool b) : m(b?42:x) { }
2913
- int m;
2914
- };
2915
- constexpr int v = A(true).m; // OK: constructor call initializes
2916
- // m with the value 42 after substitution
2917
- constexpr int w = A(false).m; // error: initializer for m is
2918
- // x, which is non-constant
2919
- ```
2920
- - an invocation of a `constexpr` function or a `constexpr` constructor
2921
- that would exceed the implementation-defined recursion limits (see
2922
  Annex  [[implimits]]);
2923
- - a result that is not mathematically defined or not in the range of
2924
- representable values for its type;
 
 
2925
  - a *lambda-expression* ([[expr.prim.lambda]]);
2926
  - an lvalue-to-rvalue conversion ([[conv.lval]]) unless it is applied
2927
  to
2928
- - a glvalue of integral or enumeration type that refers to a
2929
- non-volatile const object with a preceding initialization,
2930
- initialized with a constant expression, or
2931
- - a glvalue of literal type that refers to a non-volatile object
2932
- defined with `constexpr`, or that refers to a sub-object of such an
2933
- object, or
2934
- - a glvalue of literal type that refers to a non-volatile temporary
2935
- object whose lifetime has not ended, initialized with a constant
2936
- expression;
2937
- - an lvalue-to-rvalue conversion ([[conv.lval]]) that is applied to a
2938
- glvalue that refers to a non-active member of a union or a subobject
2939
- thereof;
 
2940
  - an *id-expression* that refers to a variable or data member of
2941
- reference type unless the reference has a preceding initialization,
2942
- initialized with a constant expression;
 
 
 
 
 
 
 
 
2943
  - a dynamic cast ([[expr.dynamic.cast]]);
2944
  - a `reinterpret_cast` ([[expr.reinterpret.cast]]);
2945
  - a pseudo-destructor call ([[expr.pseudo]]);
2946
- - increment or decrement operations ([[expr.post.incr]],
2947
- [[expr.pre.incr]]);
2948
- - a typeid expression ([[expr.typeid]]) whose operand is of a
 
 
2949
  polymorphic class type;
2950
  - a *new-expression* ([[expr.new]]);
2951
  - a *delete-expression* ([[expr.delete]]);
2952
- - a subtraction ([[expr.add]]) where both operands are pointers;
2953
  - a relational ([[expr.rel]]) or equality ([[expr.eq]]) operator where
2954
- the result is unspecified;
2955
- - an assignment or a compound assignment ([[expr.ass]]); or
2956
  - a *throw-expression* ([[except.throw]]).
2957
 
2958
- A *literal constant expression* is a prvalue core constant expression of
2959
- literal type, but not pointer type. An *integral constant expression* is
2960
- a literal constant expression of integral or unscoped enumeration type.
2961
- Such expressions may be used as array bounds ([[dcl.array]],
2962
- [[expr.new]]), as bit-field lengths ([[class.bit]]), as enumerator
2963
- initializers if the underlying type is not fixed ([[dcl.enum]]), as
2964
- null pointer constants ([[conv.ptr]]), and as alignments (
2965
- [[dcl.align]]). A *converted constant expression* of type `T` is a
2966
- literal constant expression, implicitly converted to type `T`, where the
2967
- implicit conversion (if any) is permitted in a literal constant
2968
- expression and the implicit conversion sequence contains only
2969
- user-defined conversions, lvalue-to-rvalue conversions ([[conv.lval]]),
2970
- integral promotions ([[conv.prom]]), and integral conversions (
2971
- [[conv.integral]]) other than narrowing conversions (
2972
- [[dcl.init.list]]). such expressions may be used as case expressions (
2973
- [[stmt.switch]]), as enumerator initializers if the underlying type is
2974
- fixed ([[dcl.enum]]), and as integral or enumeration non-type template
2975
- arguments ([[temp.arg]]). A *reference constant expression* is an
2976
- lvalue core constant expression that designates an object with static
2977
- storage duration or a function. An *address constant expression* is a
2978
- prvalue core constant expression of pointer type that evaluates to the
2979
- address of an object with static storage duration, to the address of a
2980
- function, or to a null pointer value, or a prvalue core constant
2981
- expression of type `std::nullptr_t`. Collectively, literal constant
2982
- expressions, reference constant expressions, and address constant
2983
- expressions are called *constant expressions*.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2984
 
2985
- Although in some contexts constant expressions must be evaluated during
2986
- program translation, others may be evaluated during program execution.
2987
  Since this International Standard imposes no restrictions on the
2988
  accuracy of floating-point operations, it is unspecified whether the
2989
  evaluation of a floating-point expression during translation yields the
2990
  same result as the evaluation of the same expression (or the same
2991
- operations on the same values) during program execution.[^27]
2992
 
2993
  ``` cpp
2994
  bool f() {
2995
  char array[1 + int(1 + 0.2 - 0.1 - 0.1)]; // Must be evaluated during translation
2996
  int size = 1 + int(1 + 0.2 - 0.1 - 0.1); // May be evaluated at runtime
@@ -2999,20 +3339,20 @@ bool f() {
2999
  ```
3000
 
3001
  It is unspecified whether the value of `f()` will be `true` or `false`.
3002
 
3003
  If an expression of literal class type is used in a context where an
3004
- integral constant expression is required, then that class type shall
3005
- have a single non-explicit conversion function to an integral or
3006
- unscoped enumeration type and that conversion function shall be
3007
  `constexpr`.
3008
 
3009
  ``` cpp
3010
  struct A {
3011
  constexpr A(int i) : val(i) { }
3012
- constexpr operator int() { return val; }
3013
- constexpr operator long() { return 43; }
3014
  private:
3015
  int val;
3016
  };
3017
  template<int> struct X { };
3018
  constexpr A a = 42;
@@ -3032,12 +3372,12 @@ int ary[a]; // error: ambiguous conversion
3032
  [basic.lookup.argdep]: basic.md#basic.lookup.argdep
3033
  [basic.lookup.classref]: basic.md#basic.lookup.classref
3034
  [basic.lookup.unqual]: basic.md#basic.lookup.unqual
3035
  [basic.lval]: basic.md#basic.lval
3036
  [basic.namespace]: dcl.md#basic.namespace
 
3037
  [basic.scope.class]: basic.md#basic.scope.class
3038
- [basic.scope.local]: basic.md#basic.scope.local
3039
  [basic.start.main]: basic.md#basic.start.main
3040
  [basic.stc.dynamic]: basic.md#basic.stc.dynamic
3041
  [basic.stc.dynamic.allocation]: basic.md#basic.stc.dynamic.allocation
3042
  [basic.stc.dynamic.deallocation]: basic.md#basic.stc.dynamic.deallocation
3043
  [basic.stc.dynamic.safety]: basic.md#basic.stc.dynamic.safety
@@ -3080,16 +3420,16 @@ int ary[a]; // error: ambiguous conversion
3080
  [conv.prom]: conv.md#conv.prom
3081
  [conv.ptr]: conv.md#conv.ptr
3082
  [conv.qual]: conv.md#conv.qual
3083
  [dcl.align]: dcl.md#dcl.align
3084
  [dcl.array]: dcl.md#dcl.array
3085
- [dcl.constexpr]: dcl.md#dcl.constexpr
3086
  [dcl.dcl]: dcl.md#dcl.dcl
3087
  [dcl.enum]: dcl.md#dcl.enum
3088
  [dcl.fct]: dcl.md#dcl.fct
3089
  [dcl.fct.def]: dcl.md#dcl.fct.def
3090
  [dcl.fct.def.delete]: dcl.md#dcl.fct.def.delete
 
3091
  [dcl.fct.default]: dcl.md#dcl.fct.default
3092
  [dcl.init]: dcl.md#dcl.init
3093
  [dcl.init.aggr]: dcl.md#dcl.init.aggr
3094
  [dcl.init.list]: dcl.md#dcl.init.list
3095
  [dcl.init.ref]: dcl.md#dcl.init.ref
@@ -3159,20 +3499,22 @@ int ary[a]; // error: ambiguous conversion
3159
  [new.delete.single]: language.md#new.delete.single
3160
  [over]: over.md#over
3161
  [over.ass]: over.md#over.ass
3162
  [over.built]: over.md#over.built
3163
  [over.call]: over.md#over.call
 
3164
  [over.literal]: over.md#over.literal
3165
  [over.match]: over.md#over.match
3166
  [over.match.oper]: over.md#over.match.oper
3167
  [over.oper]: over.md#over.oper
3168
  [over.over]: over.md#over.over
3169
  [replacement.functions]: library.md#replacement.functions
3170
  [stmt.switch]: stmt.md#stmt.switch
3171
  [support.runtime]: language.md#support.runtime
3172
  [support.types]: language.md#support.types
3173
  [temp.arg]: temp.md#temp.arg
 
3174
  [temp.names]: temp.md#temp.names
3175
  [temp.res]: temp.md#temp.res
3176
  [temp.variadic]: temp.md#temp.variadic
3177
  [type.info]: language.md#type.info
3178
 
@@ -3191,53 +3533,55 @@ int ary[a]; // error: ambiguous conversion
3191
  `(*this)` ([[class.mfct.non-static]]).
3192
 
3193
  [^5]: This is true even if the subscript operator is used in the
3194
  following common idiom: `&x[0]`.
3195
 
3196
- [^6]: A static member function ([[class.static]]) is an ordinary
3197
- function.
3198
-
3199
- [^7]: If the class member access expression is evaluated, the
3200
  subexpression evaluation happens even if the result is unnecessary
3201
  to determine the value of the entire postfix expression, for example
3202
  if the *id-expression* denotes a static member.
3203
 
3204
- [^8]: Note that `(*(E1))` is an lvalue.
3205
 
3206
- [^9]: The most derived object ([[intro.object]]) pointed or referred to
3207
  by `v` can contain other `B` objects as base classes, but these are
3208
  ignored.
3209
 
3210
- [^10]: The recommended name for such a class is `extended_type_info`.
3211
 
3212
- [^11]: If `p` is an expression of pointer type, then `*p`, `(*p)`,
3213
  `*(p)`, `((*p))`, `*((p))`, and so on all meet this requirement.
3214
 
3215
- [^12]: Function types (including those used in pointer to member
3216
  function types) are never cv-qualified; see  [[dcl.fct]].
3217
 
3218
- [^13]: The types may have different cv-qualifiers, subject to the
3219
  overall restriction that a `reinterpret_cast` cannot cast away
3220
  constness.
3221
 
3222
- [^14]: `T1` and `T2` may have different cv-qualifiers, subject to the
3223
  overall restriction that a `reinterpret_cast` cannot cast away
3224
  constness.
3225
 
3226
- [^15]: This is sometimes referred to as a *type pun*.
3227
 
3228
- [^16]: `const_cast`
3229
 
3230
  is not limited to conversions that cast away a const-qualifier.
3231
 
3232
- [^17]: `sizeof(bool)` is not required to be `1`.
3233
 
3234
- [^18]: The actual size of a base class subobject may be less than the
3235
  result of applying `sizeof` to the subobject, due to virtual base
3236
  classes and less strict padding requirements on base class
3237
  subobjects.
3238
 
 
 
 
 
 
3239
  [^19]: This may include evaluating a *new-initializer* and/or calling a
3240
  constructor.
3241
 
3242
  [^20]: A lambda expression with a *lambda-introducer* that consists of
3243
  empty square brackets can follow the `delete` keyword if the lambda
@@ -3248,16 +3592,21 @@ int ary[a]; // error: ambiguous conversion
3248
 
3249
  [^22]: For non-zero-length arrays, this is the same as a pointer to the
3250
  first element of the array created by that *new-expression*.
3251
  Zero-length arrays do not have a first element.
3252
 
3253
- [^23]: This includes implicit calls such as the call to an allocation
 
 
 
 
 
3254
  function in a *new-expression*.
3255
 
3256
- [^24]: This is often called truncation towards zero.
3257
 
3258
- [^25]: Another way to approach pointer arithmetic is first to convert
3259
  the pointer(s) to character pointer(s): In this scheme the integral
3260
  value of the expression added to or subtracted from the converted
3261
  pointer is first multiplied by the size of the object originally
3262
  pointed to, and the resulting pointer is converted back to the
3263
  original type. For pointer subtraction, the result of the difference
@@ -3267,13 +3616,13 @@ int ary[a]; // error: ambiguous conversion
3267
  When viewed in this way, an implementation need only provide one
3268
  extra byte (which might overlap another object in the program) just
3269
  after the end of the object in order to satisfy the “one past the
3270
  last element” requirements.
3271
 
3272
- [^26]: However, an invocation of an overloaded comma operator is an
3273
  ordinary function call; hence, the evaluations of its argument
3274
  expressions are unsequenced relative to one another (see
3275
  [[intro.execution]]).
3276
 
3277
- [^27]: Nonetheless, implementations are encouraged to provide consistent
3278
- results, irrespective of whether the evaluation was actually
3279
- performed during translation or during program execution.
 
38
  [[dcl.ref]],  [[dcl.init.ref]]), the type is adjusted to `T` prior to
39
  any further analysis. The expression designates the object or function
40
  denoted by the reference, and the expression is an lvalue or an xvalue,
41
  depending on the expression.
42
 
43
+ If a prvalue initially has the type “cv `T`,” where `T` is a
44
+ cv-unqualified non-class, non-array type, the type of the expression is
45
+ adjusted to `T` prior to any further analysis.
46
+
47
  An expression is an xvalue if it is:
48
 
49
  - the result of calling a function, whether implicitly or explicitly,
50
  whose return type is an rvalue reference to object type,
51
  - a cast to an rvalue reference to object type,
 
73
  The expressions `f()`, `f().m`, `static_cast<A&&>(a)`, and `a + a` are
74
  xvalues. The expression `ar` is an lvalue.
75
 
76
  In some contexts, *unevaluated operands* appear ([[expr.typeid]],
77
  [[expr.sizeof]], [[expr.unary.noexcept]], [[dcl.type.simple]]). An
78
+ unevaluated operand is not evaluated. An unevaluated operand is
79
+ considered a full-expression. In an unevaluated operand, a non-static
80
+ class member may be named ([[expr.prim]]) and naming of objects or
81
+ functions does not, by itself, require that a definition be provided (
82
+ [[basic.def.odr]]).
83
 
84
  Whenever a glvalue expression appears as an operand of an operator that
85
  expects a prvalue for that operand, the lvalue-to-rvalue (
86
  [[conv.lval]]), array-to-pointer ([[conv.array]]), or
87
  function-to-pointer ([[conv.func]]) standard conversions are applied to
 
130
  In some contexts, an expression only appears for its side effects. Such
131
  an expression is called a *discarded-value expression*. The expression
132
  is evaluated and its value is discarded. The array-to-pointer (
133
  [[conv.array]]) and function-to-pointer ([[conv.func]]) standard
134
  conversions are not applied. The lvalue-to-rvalue conversion (
135
+ [[conv.lval]]) is applied if and only if the expression is a glvalue of
136
+ volatile-qualified type and it is one of the following:
137
 
138
+ - `(` *expression* `)`, where *expression* is one of these expressions,
139
  - *id-expression* ([[expr.prim.general]]),
140
  - subscripting ([[expr.sub]]),
141
  - class member access ([[expr.ref]]),
142
  - indirection ([[expr.unary.op]]),
143
  - pointer-to-member operation ([[expr.mptr.oper]]),
144
  - conditional expression ([[expr.cond]]) where both the second and the
145
+ third operands are one of these expressions, or
146
  - comma expression ([[expr.comma]]) where the right operand is one of
147
+ these expressions.
148
+
149
+ Using an overloaded operator causes a function call; the above covers
150
+ only operators with built-in meaning. If the lvalue is of class type, it
151
+ must have a volatile copy constructor to initialize the temporary that
152
+ is the result of the lvalue-to-rvalue conversion.
153
 
154
  The values of the floating operands and the results of floating
155
  expressions may be represented in greater precision and range than that
156
  required by the type; the types are not changed thereby.[^3]
157
 
158
+ The *cv-combined type* of two types `T1` and `T2` is a type `T3` similar
159
+ to `T1` whose cv-qualification signature ([[conv.qual]]) is:
160
+
161
+ - for every j > 0, cv$_{3,j}$ is the union of cv$_{1,j}$ and cv$_{2,j}$;
162
+ - if the resulting cv$_{3,j}$ is different from cv$_{1,j}$ or
163
+ cv$_{2,j}$, then `const` is added to every cv$_{3,k}$ for 0 < k < j.
164
+
165
+ Given similar types `T1` and `T2`, this construction ensures that both
166
+ can be converted to `T3`. The *composite pointer type* of two operands
167
+ `p1` and `p2` having types `T1` and `T2`, respectively, where at least
168
+ one is a pointer or pointer to member type or `std::nullptr_t`, is:
169
+
170
+ - if both `p1` and `p2` are null pointer constants, `std::nullptr_t`;
171
+ - if either `p1` or `p2` is a null pointer constant, `T2` or `T1`,
172
+ respectively;
173
+ - if `T1` or `T2` is “pointer to *cv1* `void`” and the other type is
174
+ “pointer to *cv2* T”, “pointer to *cv12* `void`”, where *cv12* is the
175
+ union of *cv1* and *cv2*;
176
+ - if `T1` is “pointer to *cv1* `C1`” and `T2` is “pointer to *cv2*
177
+ `C2`”, where `C1` is reference-related to `C2` or `C2` is
178
+ reference-related to `C1` ([[dcl.init.ref]]), the cv-combined type of
179
+ `T1` and `T2` or the cv-combined type of `T2` and `T1`, respectively;
180
+ - if `T1` is “pointer to member of `C1` of type *cv1* `U1`” and `T2` is
181
+ “pointer to member of `C2` of type *cv2* `U2`” where `C1` is
182
+ reference-related to `C2` or `C2` is reference-related to `C1` (
183
+ [[dcl.init.ref]]), the cv-combined type of `T2` and `T1` or the
184
+ cv-combined type of `T1` and `T2`, respectively;
185
+ - if `T1` and `T2` are similar multi-level mixed pointer and pointer to
186
+ member types ([[conv.qual]]), the cv-combined type of `T1` and `T2`;
187
+ - otherwise, a program that necessitates the determination of a
188
+ composite pointer type is ill-formed.
189
+
190
+ ``` cpp
191
+ typedef void *p;
192
+ typedef const int *q;
193
+ typedef int **pi;
194
+ typedef const int **pci;
195
+ ```
196
+
197
+ The composite pointer type of `p` and `q` is “pointer to `const void`”;
198
+ the composite pointer type of `pi` and `pci` is “pointer to `const`
199
+ pointer to `const int`”.
200
+
201
  ## Primary expressions <a id="expr.prim">[[expr.prim]]</a>
202
 
203
  ### General <a id="expr.prim.general">[[expr.prim.general]]</a>
204
 
205
  ``` bnf
 
305
  member and a prvalue otherwise.
306
 
307
  ``` bnf
308
  qualified-id:
309
  nested-name-specifier 'template'ₒₚₜ unqualified-id
 
 
 
 
310
  ```
311
 
312
  ``` bnf
313
  nested-name-specifier:
314
+ '::'
315
+ type-name '::'
316
+ namespace-name '::'
317
  decltype-specifier '::'
318
  nested-name-specifier identifier '::'
319
  nested-name-specifier 'template'ₒₚₜ simple-template-id '::'
320
  ```
321
 
322
+ The type denoted by a *decltype-specifier* in a *nested-name-specifier*
323
+ shall be a class or enumeration type.
324
+
325
  A *nested-name-specifier* that denotes a class, optionally followed by
326
  the keyword `template` ([[temp.names]]), and then followed by the name
327
  of a member of either that class ([[class.mem]]) or one of its base
328
  classes (Clause  [[class.derived]]), is a *qualified-id*; 
329
  [[class.qual]] describes name lookup for class members that appear in
330
  *qualified-ids*. The result is the member. The type of the result is the
331
  type of the member. The result is an lvalue if the member is a static
332
  member function or a data member and a prvalue otherwise. a class member
333
  can be referred to using a *qualified-id* at any point in its potential
334
+ scope ([[basic.scope.class]]). Where *class-name* `::~` *class-name* is
335
+ used, the two *class-name*s shall refer to the same class; this notation
336
+ names the destructor ([[class.dtor]]). The form
337
+ `~` *decltype-specifier* also denotes the destructor, but it shall not
338
+ be used as the *unqualified-id* in a *qualified-id*. a *typedef-name*
339
+ that names a class is a *class-name* ([[class.name]]).
 
 
340
 
341
  A `::`, or a *nested-name-specifier* that names a namespace (
342
  [[basic.namespace]]), in either case followed by the name of a member of
343
  that namespace (or the name of a member of a namespace made visible by a
344
  *using-directive*) is a *qualified-id*;  [[namespace.qual]] describes
 
363
 
364
  - as part of a class member access ([[expr.ref]]) in which the object
365
  expression refers to the member’s class[^4] or a class derived from
366
  that class, or
367
  - to form a pointer to member ([[expr.unary.op]]), or
 
 
 
 
368
  - if that *id-expression* denotes a non-static data member and it
369
  appears in an unevaluated operand.
370
  ``` cpp
371
  struct S {
372
  int m;
 
420
  capture-list ',' capture '...'ₒₚₜ
421
  ```
422
 
423
  ``` bnf
424
  capture:
425
+ simple-capture
426
+ init-capture
427
+ ```
428
+
429
+ ``` bnf
430
+ simple-capture:
431
  identifier
432
  '&' identifier
433
  'this'
434
  ```
435
 
436
+ ``` bnf
437
+ init-capture:
438
+ identifier initializer
439
+ '&' identifier initializer
440
+ ```
441
+
442
  ``` bnf
443
  lambda-declarator:
444
  '(' parameter-declaration-clause ')' 'mutable'ₒₚₜ
445
  exception-specificationₒₚₜ attribute-specifier-seqₒₚₜ trailing-return-typeₒₚₜ
446
  ```
447
 
448
  The evaluation of a *lambda-expression* results in a prvalue temporary (
449
  [[class.temporary]]). This temporary is called the *closure object*. A
450
  *lambda-expression* shall not appear in an unevaluated operand (Clause 
451
+ [[expr]]), in a *template-argument*, in an *alias-declaration*, in a
452
+ typedef declaration, or in the declaration of a function or function
453
+ template outside its function body and default arguments. The intention
454
+ is to prevent lambdas from appearing in a signature. A closure object
455
+ behaves like a function object ([[function.objects]]).
456
 
457
  The type of the *lambda-expression* (which is also the type of the
458
  closure object) is a unique, unnamed non-union class type — called the
459
  *closure type* — whose properties are described below. This class type
460
+ is neither an aggregate ([[dcl.init.aggr]]) nor a literal type (
461
+ [[basic.types]]). The closure type is declared in the smallest block
462
+ scope, class scope, or namespace scope that contains the corresponding
463
+ *lambda-expression*. This determines the set of namespaces and classes
464
+ associated with the closure type ([[basic.lookup.argdep]]). The
465
+ parameter types of a *lambda-declarator* do not affect these associated
466
+ namespaces and classes. An implementation may define the closure type
467
+ differently from what is described below provided this does not alter
468
+ the observable behavior of the program other than by changing:
469
 
470
  - the size and/or alignment of the closure type,
471
  - whether the closure type is trivially copyable (Clause  [[class]]),
472
  - whether the closure type is a standard-layout class (Clause 
473
  [[class]]), or
 
475
 
476
  An implementation shall not add members of rvalue reference type to the
477
  closure type.
478
 
479
  If a *lambda-expression* does not include a *lambda-declarator*, it is
480
+ as if the *lambda-declarator* were `()`. The lambda return type is
481
+ `auto`, which is replaced by the *trailing-return-type* if provided
482
+ and/or deduced from `return` statements as described in 
483
+ [[dcl.spec.auto]].
 
 
 
 
 
 
 
 
 
484
 
485
  ``` cpp
486
  auto x1 = [](int i){ return i; }; // OK: return type is int
487
+ auto x2 = []{ return { 1, 2 }; }; // error: deducing return type from braced-init-list
488
+ int j;
489
+ auto x3 = []()->auto&& { return j; }; // OK: return type is int&
490
  ```
491
 
492
+ The closure type for a non-generic *lambda-expression* has a public
493
+ inline function call operator ([[over.call]]) whose parameters and
494
+ return type are described by the *lambda-expression*’s
495
  *parameter-declaration-clause* and *trailing-return-type* respectively.
496
+ For a generic lambda, the closure type has a public inline function call
497
+ operator member template ([[temp.mem]]) whose *template-parameter-list*
498
+ consists of one invented type *template-parameter* for each occurrence
499
+ of `auto` in the lambda’s *parameter-declaration-clause*, in order of
500
+ appearance. The invented type *template-parameter* is a parameter pack
501
+ if the corresponding *parameter-declaration* declares a function
502
+ parameter pack ([[dcl.fct]]). The return type and function parameters
503
+ of the function call operator template are derived from the
504
+ *lambda-expression*'s *trailing-return-type* and
505
+ *parameter-declaration-clause* by replacing each occurrence of `auto` in
506
+ the *decl-specifier*s of the *parameter-declaration-clause* with the
507
+ name of the corresponding invented *template-parameter*.
508
+
509
+ ``` cpp
510
+ auto glambda = [](auto a, auto&& b) { return a < b; };
511
+ bool b = glambda(3, 3.14); // OK
512
+ auto vglambda = [](auto printer) {
513
+ return [=](auto&& ... ts) { // OK: ts is a function parameter pack
514
+ printer(std::forward<decltype(ts)>(ts)...);
515
+
516
+ return [=]() {
517
+ printer(ts ...);
518
+ };
519
+ };
520
+ };
521
+ auto p = vglambda( [](auto v1, auto v2, auto v3)
522
+ { std::cout << v1 << v2 << v3; } );
523
+ auto q = p(1, 'a', 3.14); // OK: outputs 1a3.14
524
+ q(); // OK: outputs 1a3.14
525
+ ```
526
+
527
+ This function call operator or operator template is declared `const` (
528
  [[class.mfct.non-static]]) if and only if the *lambda-expression*’s
529
  *parameter-declaration-clause* is not followed by `mutable`. It is
530
+ neither virtual nor declared `volatile`. Any *exception-specification*
531
+ specified on a *lambda-expression* applies to the corresponding function
532
+ call operator or operator template. An *attribute-specifier-seq* in a
533
+ *lambda-declarator* appertains to the type of the corresponding function
534
+ call operator or operator template. Names referenced in the
535
+ *lambda-declarator* are looked up in the context in which the
536
+ *lambda-expression* appears.
537
+
538
+ The closure type for a non-generic *lambda-expression* with no
539
+ *lambda-capture* has a public non-virtual non-explicit const conversion
540
+ function to pointer to function with C++language linkage ([[dcl.link]])
541
+ having the same parameter and return types as the closure type’s
542
+ function call operator. The value returned by this conversion function
543
+ shall be the address of a function that, when invoked, has the same
544
+ effect as invoking the closure type’s function call operator. For a
545
+ generic lambda with no *lambda-capture*, the closure type has a public
546
+ non-virtual non-explicit const conversion function template to pointer
547
+ to function. The conversion function template has the same invented
548
+ *template-parameter-list*, and the pointer to function has the same
549
+ parameter types, as the function call operator template. The return type
550
+ of the pointer to function shall behave as if it were a
551
+ *decltype-specifier* denoting the return type of the corresponding
552
+ function call operator template specialization. If the generic lambda
553
+ has no *trailing-return-type* or the *trailing-return-type* contains a
554
+ placeholder type, return type deduction of the corresponding function
555
+ call operator template specialization has to be done. The corresponding
556
+ specialization is that instantiation of the function call operator
557
+ template with the same template arguments as those deduced for the
558
+ conversion function template. Consider the following:
559
+
560
+ ``` cpp
561
+ auto glambda = [](auto a) { return a; };
562
+ int (*fp)(int) = glambda;
563
+ ```
564
+
565
+ The behavior of the conversion function of `glambda` above is like that
566
+ of the following conversion function:
567
+
568
+ ``` cpp
569
+ struct Closure {
570
+ template<class T> auto operator()(T t) const { ... }
571
+ template<class T> static auto lambda_call_operator_invoker(T a) {
572
+ // forwards execution to operator()(a) and therefore has
573
+ // the same return type deduced
574
+ ...
575
+ }
576
+ template<class T> using fptr_t =
577
+ decltype(lambda_call_operator_invoker(declval<T>())) (*)(T);
578
+
579
+ template<class T> operator fptr_t<T>() const
580
+ { return &lambda_call_operator_invoker; }
581
+ };
582
+ ```
583
+
584
+ ``` cpp
585
+ void f1(int (*)(int)) { }
586
+ void f2(char (*)(int)) { }
587
+
588
+ void g(int (*)(int)) { } // #1
589
+ void g(char (*)(char)) { } // #2
590
+
591
+ void h(int (*)(int)) { } // #3
592
+ void h(char (*)(int)) { } // #4
593
+
594
+ auto glambda = [](auto a) { return a; };
595
+ f1(glambda); // OK
596
+ f2(glambda); // error: ID is not convertible
597
+ g(glambda); // error: ambiguous
598
+ h(glambda); // OK: calls #3 since it is convertible from ID
599
+ int& (*fpi)(int*) = [](auto* a) -> auto& { return *a; }; // OK
600
+ ```
601
+
602
+ The value returned by any given specialization of this conversion
603
+ function template shall be the address of a function that, when invoked,
604
+ has the same effect as invoking the generic lambda’s corresponding
605
+ function call operator template specialization. This will result in the
606
+ implicit instantiation of the generic lambda’s body. The instantiated
607
+ generic lambda’s return type and parameter types shall match the return
608
+ type and parameter types of the pointer to function.
609
+
610
+ ``` cpp
611
+ auto GL = [](auto a) { std::cout << a; return a; };
612
+ int (*GL_int)(int) = GL; // OK: through conversion function template
613
+ GL_int(3); // OK: same as GL(3)
614
+ ```
615
 
616
  The *lambda-expression*’s *compound-statement* yields the
617
  *function-body* ([[dcl.fct.def]]) of the function call operator, but
618
  for purposes of name lookup ([[basic.lookup]]), determining the type
619
  and value of `this` ([[class.this]]) and transforming *id-expression*s
 
633
  };
634
  }
635
  };
636
  ```
637
 
638
+ Further, a variable `__func__` is implicitly defined at the beginning of
639
+ the *compound-statement* of the *lambda-expression*, with semantics as
640
+ described in  [[dcl.fct.def.general]].
641
+
642
+ If a *lambda-capture* includes a *capture-default* that is `&`, no
643
+ identifier in a *simple-capture* of that *lambda-capture* shall be
644
+ preceded by `&`. If a *lambda-capture* includes a *capture-default* that
645
+ is `=`, each *simple-capture* of that *lambda-capture* shall be of the
646
+ form “`&` *identifier*”. Ignoring appearances in *initializer*s of
647
+ *init-capture*s, an identifier or `this` shall not appear more than once
648
+ in a *lambda-capture*.
649
 
650
  ``` cpp
651
  struct S2 { void f(int i); };
652
  void S2::f(int i) {
653
  [&, i]{ }; // OK
 
656
  [i, i]{ }; // error: i repeated
657
  }
658
  ```
659
 
660
  A *lambda-expression* whose smallest enclosing scope is a block scope (
661
+ [[basic.scope.block]]) is a *local lambda expression*; any other
662
+ *lambda-expression* shall not have a *capture-default* or
663
+ *simple-capture* in its *lambda-introducer*. The *reaching scope* of a
664
+ local lambda expression is the set of enclosing scopes up to and
665
+ including the innermost enclosing function and its parameters. This
666
+ reaching scope includes any intervening *lambda-expression*s.
667
 
668
+ The *identifier* in a *simple-capture* is looked up using the usual
669
  rules for unqualified name lookup ([[basic.lookup.unqual]]); each such
670
+ lookup shall find an entity. An entity that is designated by a
671
+ *simple-capture* is said to be *explicitly captured*, and shall be
672
+ `this` or a variable with automatic storage duration declared in the
673
+ reaching scope of the local lambda expression.
674
+
675
+ An *init-capture* behaves as if it declares and explicitly captures a
676
+ variable of the form “`auto` *init-capture* `;` whose declarative
677
+ region is the *lambda-expression*’s *compound-statement*, except that:
678
+
679
+ - if the capture is by copy (see below), the non-static data member
680
+ declared for the capture and the variable are treated as two different
681
+ ways of referring to the same object, which has the lifetime of the
682
+ non-static data member, and no additional copy and destruction is
683
+ performed, and
684
+ - if the capture is by reference, the variable’s lifetime ends when the
685
+ closure object’s lifetime ends.
686
+
687
+ This enables an *init-capture* like “`x = std::move(x)`”; the second
688
+ “`x`” must bind to a declaration in the surrounding context.
689
+
690
+ ``` cpp
691
+ int x = 4;
692
+ auto y = [&r = x, x = x+1]()->int {
693
+ r += 2;
694
+ return x+2;
695
+ }(); // Updates ::x to 6, and initializes y to 7.
696
+ ```
697
+
698
+ A *lambda-expression* with an associated *capture-default* that does not
699
+ explicitly capture `this` or a variable with automatic storage duration
700
+ (this excludes any *id-expression* that has been found to refer to an
701
+ *init-capture*'s associated non-static data member), is said to
702
+ *implicitly capture* the entity (i.e., `this` or a variable) if the
703
+ *compound-statement*:
704
+
705
+ - odr-uses ([[basic.def.odr]]) the entity, or
706
+ - names the entity in a potentially-evaluated expression (
707
+ [[basic.def.odr]]) where the enclosing full-expression depends on a
708
+ generic lambda parameter declared within the reaching scope of the
709
+ *lambda-expression*.
710
+
711
+ ``` cpp
712
+ void f(int, const int (&)[2] = {}) { } // #1
713
+ void f(const int&, const int (&)[1]) { } // #2
714
+ void test() {
715
+ const int x = 17;
716
+ auto g = [](auto a) {
717
+ f(x); // OK: calls #1, does not capture x
718
+ };
719
+
720
+ auto g2 = [=](auto a) {
721
+ int selector[sizeof(a) == 1 ? 1 : 2]{};
722
+ f(x, selector); // OK: is a dependent expression, so captures x
723
+ };
724
+ }
725
+ ```
726
+
727
+ All such implicitly captured entities shall be declared within the
728
+ reaching scope of the lambda expression. The implicit capture of an
729
+ entity by a nested *lambda-expression* can cause its implicit capture by
730
+ the containing *lambda-expression* (see below). Implicit odr-uses of
731
+ `this` can result in implicit capture.
732
 
733
  An entity is *captured* if it is captured explicitly or implicitly. An
734
  entity captured by a *lambda-expression* is odr-used (
735
  [[basic.def.odr]]) in the scope containing the *lambda-expression*. If
736
  `this` is captured by a local lambda expression, its nearest enclosing
737
  function shall be a non-static member function. If a *lambda-expression*
738
+ or an instantiation of the function call operator template of a generic
739
+ lambda odr-uses ([[basic.def.odr]]) `this` or a variable with automatic
740
  storage duration from its reaching scope, that entity shall be captured
741
  by the *lambda-expression*. If a *lambda-expression* captures an entity
742
  and that entity is not defined or captured in the immediately enclosing
743
  lambda expression or function, the program is ill-formed.
744
 
 
788
  }
789
  ```
790
 
791
  An entity is *captured by copy* if it is implicitly captured and the
792
  *capture-default* is `=` or if it is explicitly captured with a capture
793
+ that is not of the form `&` *identifier* or `&` *identifier*
794
+ *initializer*. For each entity captured by copy, an unnamed non-static
795
+ data member is declared in the closure type. The declaration order of
796
+ these members is unspecified. The type of such a data member is the type
797
+ of the corresponding captured entity if the entity is not a reference to
798
+ an object, or the referenced type otherwise. If the captured entity is a
799
+ reference to a function, the corresponding data member is also a
800
+ reference to a function. A member of an anonymous union shall not be
801
+ captured by copy.
802
 
803
  An entity is *captured by reference* if it is implicitly or explicitly
804
  captured but not captured by copy. It is unspecified whether additional
805
  unnamed non-static data members are declared in the closure type for
806
+ entities captured by reference. A member of an anonymous union shall not
807
+ be captured by reference.
808
 
809
  If a *lambda-expression* `m2` captures an entity and that entity is
810
  captured by an immediately enclosing *lambda-expression* `m1`, then
811
  `m2`’s capture is transformed as follows:
812
 
 
831
  a = 2; b = 2; c = 2;
832
  m1();
833
  std::cout << a << b << c;
834
  ```
835
 
836
+ Every *id-expression* within the *compound-statement* of a
837
+ *lambda-expression* that is an odr-use ([[basic.def.odr]]) of an entity
838
+ captured by copy is transformed into an access to the corresponding
839
+ unnamed data member of the closure type. An *id-expression* that is not
840
+ an odr-use refers to the original entity, never to a member of the
841
+ closure type. Furthermore, such an *id-expression* does not cause the
842
+ implicit capture of the entity. If `this` is captured, each odr-use of
843
+ `this` is transformed into an access to the corresponding unnamed data
844
+ member of the closure type, cast ([[expr.cast]]) to the type of `this`.
845
+ The cast ensures that the transformed expression is a prvalue.
846
 
847
  ``` cpp
848
  void f(const int*);
849
  void g() {
850
  const int N = 10;
851
  [=] {
852
  int arr[N]; // OK: not an odr-use, refers to automatic variable
853
  f(&N); // OK: causes N to be captured; &N points to the
854
  // corresponding member of the closure type
855
+ };
856
  }
857
  ```
858
 
859
  Every occurrence of `decltype((x))` where `x` is a possibly
860
  parenthesized *id-expression* that names an entity of automatic storage
 
886
  The closure type associated with a *lambda-expression* has an
887
  implicitly-declared destructor ([[class.dtor]]).
888
 
889
  When the *lambda-expression* is evaluated, the entities that are
890
  captured by copy are used to direct-initialize each corresponding
891
+ non-static data member of the resulting closure object, and the
892
+ non-static data members corresponding to the *init-capture*s are
893
+ initialized as indicated by the corresponding *initializer* (which may
894
+ be copy- or direct-initialization). (For array members, the array
895
+ elements are direct-initialized in increasing subscript order.) These
896
+ initializations are performed in the (unspecified) order in which the
897
+ non-static data members are declared. This ensures that the destructions
898
+ will occur in the reverse order of the constructions.
899
 
900
  If an entity is implicitly or explicitly captured by reference, invoking
901
  the function call operator of the corresponding *lambda-expression*
902
  after the lifetime of the entity has ended is likely to result in
903
  undefined behavior.
904
 
905
+ A *simple-capture* followed by an ellipsis is a pack expansion (
906
+ [[temp.variadic]]). An *init-capture* followed by an ellipsis is
907
+ ill-formed.
908
 
909
  ``` cpp
910
  template<class... Args>
911
  void f(Args... args) {
912
  auto lm = [&, args...] { return g(args...); };
 
960
  `>{>}` token by two consecutive `>` tokens ([[temp.names]]).
961
 
962
  ### Subscripting <a id="expr.sub">[[expr.sub]]</a>
963
 
964
  A postfix expression followed by an expression in square brackets is a
965
+ postfix expression. One of the expressions shall have the type “array of
966
+ `T`” or “pointer to `T`” and the other shall have unscoped enumeration
967
+ or integral type. The result is of type “`T`.” The type “`T`” shall be a
968
  completely-defined object type.[^5] The expression `E1[E2]` is identical
969
  (by definition) to `*((E1)+(E2))` see  [[expr.unary]] and  [[expr.add]]
970
+ for details of `*` and `+` and  [[dcl.array]] for details of arrays. ,
971
+ except that in the case of an array operand, the result is an lvalue if
972
+ that operand is an lvalue and an xvalue otherwise.
973
 
974
  A *braced-init-list* shall not be used with the built-in subscript
975
  operator.
976
 
977
  ### Function call <a id="expr.call">[[expr.call]]</a>
978
 
979
+ A function call is a postfix expression followed by parentheses
980
+ containing a possibly empty, comma-separated list of
981
+ *initializer-clause*s which constitute the arguments to the function.
982
+ The postfix expression shall have function type or pointer to function
983
+ type. For a call to a non-member function or to a static member
984
+ function, the postfix expression shall be either an lvalue that refers
985
+ to a function (in which case the function-to-pointer standard
986
+ conversion ([[conv.func]]) is suppressed on the postfix expression), or
987
+ it shall have pointer to function type. Calling a function through an
988
+ expression whose function type has a language linkage that is different
989
+ from the language linkage of the function type of the called function’s
990
+ definition is undefined ([[dcl.link]]). For a call to a non-static
991
+ member function, the postfix expression shall be an implicit (
992
+ [[class.mfct.non-static]],  [[class.static]]) or explicit class member
993
+ access ([[expr.ref]]) whose *id-expression* is a function member name,
994
+ or a pointer-to-member expression ([[expr.mptr.oper]]) selecting a
995
+ function member; the call is as a member of the class object referred to
996
+ by the object expression. In the case of an implicit class member
997
+ access, the implied object is the one pointed to by `this`. a member
998
+ function call of the form `f()` is interpreted as `(*this).f()` (see 
999
+ [[class.mfct.non-static]]). If a function or member function name is
1000
+ used, the name can be overloaded (Clause  [[over]]), in which case the
1001
+ appropriate function shall be selected according to the rules in 
1002
+ [[over.match]]. If the selected function is non-virtual, or if the
1003
+ *id-expression* in the class member access expression is a
1004
  *qualified-id*, that function is called. Otherwise, its final
1005
  overrider ([[class.virtual]]) in the dynamic type of the object
1006
+ expression is called; such a call is referred to as a *virtual function
1007
+ call*. the dynamic type is the type of the object referred to by the
1008
+ current value of the object expression. [[class.cdtor]] describes the
1009
+ behavior of virtual function calls when the object expression refers to
1010
+ an object under construction or destruction.
1011
 
1012
  If a function or member function name is used, and name lookup (
1013
  [[basic.lookup]]) does not find a declaration of that name, the program
1014
  is ill-formed. No function is implicitly declared by such a call.
1015
 
1016
  If the *postfix-expression* designates a destructor ([[class.dtor]]),
1017
  the type of the function call expression is `void`; otherwise, the type
1018
  of the function call expression is the return type of the statically
1019
  chosen function (i.e., ignoring the `virtual` keyword), even if the type
1020
+ of the function actually called is different. This return type shall be
1021
+ an object type, a reference type or cv `void`.
1022
 
1023
  When a function is called, each parameter ([[dcl.fct]]) shall be
1024
  initialized ([[dcl.init]],  [[class.copy]],  [[class.ctor]]) with its
1025
  corresponding argument. Such initializations are indeterminately
1026
  sequenced with respect to each other ([[intro.execution]]) If the
 
1093
  [[conv.prom]]), or a floating point type that is subject to the floating
1094
  point promotion ([[conv.fpprom]]), the value of the argument is
1095
  converted to the promoted type before the call. These promotions are
1096
  referred to as the *default argument promotions*.
1097
 
1098
+ The evaluations of the postfix expression and of the arguments are all
1099
+ unsequenced relative to one another. All side effects of argument
1100
+ evaluations are sequenced before the function is entered (see 
1101
+ [[intro.execution]]).
1102
 
1103
+ Recursive calls are permitted, except to the `main` function (
1104
  [[basic.start.main]]).
1105
 
1106
  A function call is an lvalue if the result type is an lvalue reference
1107
  type or an rvalue reference to function type, an xvalue if the result
1108
  type is an rvalue reference to object type, and a prvalue otherwise.
 
1142
  prvalue.
1143
 
1144
  The expression `T()`, where `T` is a *simple-type-specifier* or
1145
  *typename-specifier* for a non-array complete object type or the
1146
  (possibly cv-qualified) `void` type, creates a prvalue of the specified
1147
+ type, whose value is that produced by value-initializing ([[dcl.init]])
1148
+ an object of type `T`; no initialization is done for the `void()` case.
1149
+ if `T` is a non-class type that is cv-qualified, the *cv-qualifier*s are
1150
+ discarded when determining the type of the resulting prvalue (Clause 
1151
+ [[expr]]).
1152
 
1153
  Similarly, a *simple-type-specifier* or *typename-specifier* followed by
1154
  a *braced-init-list* creates a temporary object of the specified type
1155
  direct-list-initialized ([[dcl.init.list]]) with the specified
1156
  *braced-init-list*, and its value is that temporary object as a prvalue.
 
1180
  ### Class member access <a id="expr.ref">[[expr.ref]]</a>
1181
 
1182
  A postfix expression followed by a dot `.` or an arrow `->`, optionally
1183
  followed by the keyword `template` ([[temp.names]]), and then followed
1184
  by an *id-expression*, is a postfix expression. The postfix expression
1185
+ before the dot or arrow is evaluated;[^6] the result of that evaluation,
1186
  together with the *id-expression*, determines the result of the entire
1187
  postfix expression.
1188
 
1189
  For the first option (dot) the first expression shall have complete
1190
  class type. For the second option (arrow) the first expression shall
1191
  have pointer to complete class type. The expression `E1->E2` is
1192
  converted to the equivalent form `(*(E1)).E2`; the remainder of
1193
+ [[expr.ref]] will address only the first option (dot).[^7] In either
1194
  case, the *id-expression* shall name a member of the class or of one of
1195
  its base classes. because the name of a class is inserted in its class
1196
  scope (Clause  [[class]]), the name of a class is also considered a
1197
  nested member of that class. [[basic.lookup.classref]] describes how
1198
  names are looked up after the `.` and `->` operators.
 
1212
  `E1.E2` is an lvalue; the expression designates the named member of
1213
  the class. The type of `E1.E2` is `T`.
1214
  - If `E2` is a non-static data member and the type of `E1` is “*cq1 vq1*
1215
  `X`”, and the type of `E2` is “*cq2 vq2* `T`”, the expression
1216
  designates the named member of the object designated by the first
1217
+ expression. If `E1` is an lvalue, then `E1.E2` is an lvalue; otherwise
1218
+ `E1.E2` is an xvalue. Let the notation *vq12* stand for the “union” of
1219
+ *vq1* and *vq2*; that is, if *vq1* or *vq2* is `volatile`, then *vq12*
1220
+ is `volatile`. Similarly, let the notation *cq12* stand for the
1221
+ “union” of *cq1* and *cq2*; that is, if *cq1* or *cq2* is `const`,
1222
+ then *cq12* is `const`. If `E2` is declared to be a `mutable` member,
1223
+ then the type of `E1.E2` is “*vq12* `T`”. If `E2` is not declared to
1224
+ be a `mutable` member, then the type of `E1.E2` is “*cq12* *vq12*
1225
+ `T`”.
1226
  - If `E2` is a (possibly overloaded) member function, function overload
1227
  resolution ([[over.match]]) is used to determine whether `E1.E2`
1228
  refers to a static or a non-static member function.
1229
  - If it refers to a static member function and the type of `E2` is
1230
  “function of parameter-type-list returning `T`”, then `E1.E2` is an
 
1297
  If `T` is “pointer to *cv1* `B`” and `v` has type “pointer to *cv2* `D`”
1298
  such that `B` is a base class of `D`, the result is a pointer to the
1299
  unique `B` subobject of the `D` object pointed to by `v`. Similarly, if
1300
  `T` is “reference to *cv1* `B`” and `v` has type *cv2* `D` such that `B`
1301
  is a base class of `D`, the result is the unique `B` subobject of the
1302
+ `D` object referred to by `v`. [^8] The result is an lvalue if `T` is an
1303
  lvalue reference, or an xvalue if `T` is an rvalue reference. In both
1304
  the pointer and reference cases, the program is ill-formed if *cv2* has
1305
  greater cv-qualification than *cv1* or if `B` is an inaccessible or
1306
  ambiguous base class of `D`.
1307
 
 
1311
  void foo(D* dp) {
1312
  B* bp = dynamic_cast<B*>(dp); // equivalent to B* bp = dp;
1313
  }
1314
  ```
1315
 
1316
+ Otherwise, `v` shall be a pointer to or a glvalue of a polymorphic
1317
  type ([[class.virtual]]).
1318
 
1319
  If `T` is “pointer to *cv* `void`,” then the result is a pointer to the
1320
  most derived object pointed to by `v`. Otherwise, a run-time check is
1321
  applied to see if the object pointed or referred to by `v` can be
 
1335
  result points (refers) to the `C` subobject of the most derived
1336
  object.
1337
  - Otherwise, the run-time check *fails*.
1338
 
1339
  The value of a failed cast to pointer type is the null pointer value of
1340
+ the required result type. A failed cast to reference type throws an
1341
+ exception ([[except.throw]]) of a type that would match a handler (
1342
+ [[except.handle]]) of type `std::bad_cast` ([[bad.cast]]).
1343
 
1344
  ``` cpp
1345
  class A { virtual void f(); };
1346
  class B { virtual void g(); };
1347
  class D : public virtual A, private B { };
 
1375
 
1376
  The result of a `typeid` expression is an lvalue of static type `const`
1377
  `std::type_info` ([[type.info]]) and dynamic type `const`
1378
  `std::type_info` or `const` *name* where *name* is an
1379
  *implementation-defined* class publicly derived from `std :: type_info`
1380
+ which preserves the behavior described in  [[type.info]].[^9] The
1381
  lifetime of the object referred to by the lvalue extends to the end of
1382
  the program. Whether or not the destructor is called for the
1383
  `std::type_info` object at the end of the program is unspecified.
1384
 
1385
  When `typeid` is applied to a glvalue expression whose type is a
1386
  polymorphic class type ([[class.virtual]]), the result refers to a
1387
  `std::type_info` object representing the type of the most derived
1388
  object ([[intro.object]]) (that is, the dynamic type) to which the
1389
  glvalue refers. If the glvalue expression is obtained by applying the
1390
+ unary `*` operator to a pointer[^10] and the pointer is a null pointer
1391
+ value ([[conv.ptr]]), the `typeid` expression throws an exception (
1392
+ [[except.throw]]) of a type that would match a handler of type
1393
  `std::bad_typeid` exception ([[bad.typeid]]).
1394
 
1395
  When `typeid` is applied to an expression other than a glvalue of a
1396
  polymorphic class type, the result refers to a `std::type_info` object
1397
  representing the static type of the expression. Lvalue-to-rvalue (
 
1407
  the result of the `typeid` expression refers to a `std::type_info`
1408
  object representing the *cv*-unqualified referenced type. If the type of
1409
  the *type-id* is a class type or a reference to a class type, the class
1410
  shall be completely-defined.
1411
 
1412
+ If the type of the expression or *type-id* is a cv-qualified type, the
1413
+ result of the `typeid` expression refers to a `std::type_info` object
1414
+ representing the cv-unqualified type.
1415
 
1416
  ``` cpp
1417
  class D { /* ... */ };
1418
  D d1;
1419
  const D d2;
 
1448
  virtual base class of `D`. The result has type “*cv2* `D`.” An xvalue of
1449
  type “*cv1* `B`” may be cast to type “rvalue reference to *cv2* `D`”
1450
  with the same constraints as for an lvalue of type “*cv1* `B`.” If the
1451
  object of type “*cv1* `B`” is actually a subobject of an object of type
1452
  `D`, the result refers to the enclosing object of type `D`. Otherwise,
1453
+ the behavior is undefined.
1454
 
1455
  ``` cpp
1456
  struct B { };
1457
  struct D : public B { };
1458
  D d;
1459
  B &br = d;
1460
 
1461
  static_cast<D&>(br); // produces lvalue to the original d object
1462
  ```
1463
 
1464
+ A glvalue, class prvalue, or array prvalue of type “*cv1* `T1`” can be
1465
+ cast to type “rvalue reference to *cv2* `T2`” if “*cv2* `T2`” is
1466
+ reference-compatible with “*cv1* `T1`” ([[dcl.init.ref]]). If the value
1467
+ is not a bit-field, the result refers to the object or the specified
1468
+ base class subobject thereof; otherwise, the lvalue-to-rvalue
1469
+ conversion ([[conv.lval]]) is applied to the bit-field and the
1470
+ resulting prvalue is used as the *expression* of the `static_cast` for
1471
+ the remainder of this section. If `T2` is an inaccessible (Clause 
1472
  [[class.access]]) or ambiguous ([[class.member.lookup]]) base class of
1473
  `T1`, a program that necessitates such a cast is ill-formed.
1474
 
1475
+ An expression `e` can be explicitly converted to a type `T` using a
1476
+ `static_cast` of the form `static_cast<T>(e)` if the declaration
1477
  `T t(e);` is well-formed, for some invented temporary variable `t` (
1478
  [[dcl.init]]). The effect of such an explicit conversion is the same as
1479
  performing the declaration and initialization and then using the
1480
  temporary variable as the result of the conversion. The expression `e`
1481
  is used as a glvalue if and only if the initialization uses it as a
 
1515
  restriction that the explicit conversion does not cast away constness (
1516
  [[expr.const.cast]]), and the following additional rules for specific
1517
  cases:
1518
 
1519
  A value of a scoped enumeration type ([[dcl.enum]]) can be explicitly
1520
+ converted to an integral type. When that type is cv `bool`, the
1521
+ resulting value is `false` if the original value is zero and `true` for
1522
+ all other values. For the remaining integral types, the value is
1523
+ unchanged if the original value can be represented by the specified
1524
+ type. Otherwise, the resulting value is unspecified. A value of a scoped
1525
+ enumeration type can also be explicitly converted to a floating-point
1526
+ type; the result is the same as that of converting from the original
1527
+ value to the floating-point type.
1528
 
1529
  A value of integral or enumeration type can be explicitly converted to
1530
  an enumeration type. The value is unchanged if the original value is
1531
  within the range of the enumeration values ([[dcl.enum]]). Otherwise,
1532
  the resulting value is unspecified (and might not be in that range). A
1533
+ value of floating-point type can also be explicitly converted to an
1534
+ enumeration type. The resulting value is the same as converting the
1535
+ original value to the underlying type of the enumeration (
1536
+ [[conv.fpint]]), and subsequently to the enumeration type.
1537
 
1538
  A prvalue of type “pointer to *cv1* `B`,” where `B` is a class type, can
1539
  be converted to a prvalue of type “pointer to *cv2* `D`,” where `D` is a
1540
  class derived (Clause  [[class.derived]]) from `B`, if a valid standard
1541
  conversion from “pointer to `D`” to “pointer to `B`” exists (
 
1544
  `D` nor a base class of a virtual base class of `D`. The null pointer
1545
  value ([[conv.ptr]]) is converted to the null pointer value of the
1546
  destination type. If the prvalue of type “pointer to *cv1* `B`” points
1547
  to a `B` that is actually a subobject of an object of type `D`, the
1548
  resulting pointer points to the enclosing object of type `D`. Otherwise,
1549
+ the behavior is undefined.
1550
 
1551
  A prvalue of type “pointer to member of `D` of type *cv1* `T`” can be
1552
  converted to a prvalue of type “pointer to member of `B`” of type *cv2*
1553
  `T`, where `B` is a base class (Clause  [[class.derived]]) of `D`, if a
1554
  valid standard conversion from “pointer to member of `B` of type `T`” to
1555
  “pointer to member of `D` of type `T`” exists ([[conv.mem]]), and *cv2*
1556
  is the same cv-qualification as, or greater cv-qualification than,
1557
+ *cv1*.[^11] The null member pointer value ([[conv.mem]]) is converted
1558
  to the null member pointer value of the destination type. If class `B`
1559
  contains the original member, or is a base or derived class of the class
1560
  containing the original member, the resulting pointer to member points
1561
+ to the original member. Otherwise, the behavior is undefined. although
1562
+ class `B` need not contain the original member, the dynamic type of the
1563
+ object with which indirection through the pointer to member is performed
1564
+ must contain the original member; see  [[expr.mptr.oper]].
1565
 
1566
  A prvalue of type “pointer to *cv1* `void`” can be converted to a
1567
  prvalue of type “pointer to *cv2* `T`,” where `T` is an object type and
1568
  *cv2* is the same cv-qualification as, or greater cv-qualification than,
1569
  *cv1*. The null pointer value is converted to the null pointer value of
1570
+ the destination type. If the original pointer value represents the
1571
+ address `A` of a byte in memory and `A` satisfies the alignment
1572
+ requirement of `T`, then the resulting pointer value represents the same
1573
+ address as the original pointer value, that is, `A`. The result of any
1574
+ other such pointer conversion is unspecified. A value of type pointer to
1575
+ object converted to “pointer to *cv* `void`” and back, possibly with
1576
+ different cv-qualification, shall have its original value.
1577
 
1578
  ``` cpp
1579
  T* p1 = new T;
1580
  const T* p2 = static_cast<const T*>(static_cast<void*>(p1));
1581
  bool b = p1 == p2; // b will have the value true.
 
1628
  the original pointer value, the result of such a pointer conversion is
1629
  unspecified. see also  [[conv.ptr]] for more details of pointer
1630
  conversions.
1631
 
1632
  An object pointer can be explicitly converted to an object pointer of a
1633
+ different type.[^12] When a prvalue `v` of object pointer type is
1634
+ converted to the object pointer type “pointer to cv `T`”, the result is
1635
+ `static_cast<cv T*>(static_cast<cv void*>(v))`. Converting a prvalue of
1636
+ type “pointer to `T1`” to the type “pointer to `T2`” (where `T1` and
1637
+ `T2` are object types and where the alignment requirements of `T2` are
1638
+ no stricter than those of `T1`) and back to its original type yields the
1639
+ original pointer value.
 
 
 
1640
 
1641
  Converting a function pointer to an object pointer type or vice versa is
1642
  conditionally-supported. The meaning of such a conversion is
1643
  *implementation-defined*, except that if an implementation supports
1644
  conversions in both directions, converting a prvalue of one type to the
 
1652
  pointer value.
1653
 
1654
  A prvalue of type “pointer to member of `X` of type `T1`” can be
1655
  explicitly converted to a prvalue of a different type “pointer to member
1656
  of `Y` of type `T2`” if `T1` and `T2` are both function types or both
1657
+ object types.[^13] The null member pointer value ([[conv.mem]]) is
1658
  converted to the null member pointer value of the destination type. The
1659
  result of this conversion is unspecified, except in the following cases:
1660
 
1661
  - converting a prvalue of type “pointer to member function” to a
1662
  different pointer to member function type and back to its original
 
1665
  `T1`” to the type “pointer to data member of `Y` of type `T2`” (where
1666
  the alignment requirements of `T2` are no stricter than those of `T1`)
1667
  and back to its original type yields the original pointer to member
1668
  value.
1669
 
1670
+ A glvalue expression of type `T1` can be cast to the type “reference to
1671
  `T2`” if an expression of type “pointer to `T1`” can be explicitly
1672
+ converted to the type “pointer to `T2`” using a `reinterpret_cast`. The
1673
+ result refers to the same object as the source glvalue, but with the
1674
+ specified type. That is, for lvalues, a reference cast
1675
+ `reinterpret_cast<T&>(x)` has the same effect as the conversion
1676
+ `*reinterpret_cast<T*>(&x)` with the built-in `&` and `*` operators (and
1677
+ similarly for `reinterpret_cast<T&&>(x)`). No temporary is created, no
1678
+ copy is made, and constructors ([[class.ctor]]) or conversion
1679
+ functions ([[class.conv]]) are not called.[^14]
 
 
1680
 
1681
  ### Const cast <a id="expr.const.cast">[[expr.const.cast]]</a>
1682
 
1683
  The result of the expression `const_cast<T>(v)` is of type `T`. If `T`
1684
  is an lvalue reference to object type, the result is an lvalue; if `T`
 
1730
  [[conv.mem]]) is converted to the null member pointer value of the
1731
  destination type.
1732
 
1733
  Depending on the type of the object, a write operation through the
1734
  pointer, lvalue or pointer to data member resulting from a `const_cast`
1735
+ that casts away a const-qualifier[^15] may produce undefined behavior (
1736
  [[dcl.type.cv]]).
1737
 
1738
  The following rules define the process known as *casting away
1739
  constness*. In these rules `Tn ` and `Xn ` represent types. For two
1740
  pointer types:
 
1797
 
1798
  The unary `*` operator performs *indirection*: the expression to which
1799
  it is applied shall be a pointer to an object type, or a pointer to a
1800
  function type and the result is an lvalue referring to the object or
1801
  function to which the expression points. If the type of the expression
1802
+ is “pointer to `T`,” the type of the result is “`T`.” indirection
1803
+ through a pointer to an incomplete type (other than *cv* `void`) is
1804
+ valid. The lvalue thus obtained can be used in limited ways (to
1805
+ initialize a reference, for example); this lvalue must not be converted
1806
+ to a prvalue, see  [[conv.lval]].
1807
 
1808
  The result of each of the following unary operators is a prvalue.
1809
 
1810
  The result of the unary `&` operator is a pointer to its operand. The
1811
  operand shall be an lvalue or a *qualified-id*. If the operand is a
 
1837
  “pointer to member function” as there is from an lvalue of function type
1838
  to the type “pointer to function” ([[conv.func]]). Nor is
1839
  `&unqualified-id` a pointer to member, even within the scope of the
1840
  *unqualified-id*’s class.
1841
 
1842
+ If `&` is applied to an lvalue of incomplete class type and the complete
1843
+ type declares `operator&()`, it is unspecified whether the operator has
1844
+ the built-in meaning or the operator function is called. The operand of
1845
+ `&` shall not be a bit-field.
1846
 
1847
  The address of an overloaded function (Clause  [[over]]) can be taken
1848
  only in a context that uniquely determines which version of the
1849
  overloaded function is referred to (see  [[over.over]]). since the
1850
  context might determine whether the operand is a static or non-static
 
1899
  representation of its operand. The operand is either an expression,
1900
  which is an unevaluated operand (Clause  [[expr]]), or a parenthesized
1901
  *type-id*. The `sizeof` operator shall not be applied to an expression
1902
  that has function or incomplete type, to an enumeration type whose
1903
  underlying type is not fixed before all its enumerators have been
1904
+ declared, to the parenthesized name of such types, or to a glvalue that
1905
  designates a bit-field. `sizeof(char)`, `sizeof(signed char)` and
1906
  `sizeof(unsigned char)` are `1`. The result of `sizeof` applied to any
1907
  other fundamental type ([[basic.fundamental]]) is
1908
  *implementation-defined*. in particular, `sizeof(bool)`,
1909
  `sizeof(char16_t)`, `sizeof(char32_t)`, and `sizeof(wchar_t)` are
1910
+ implementation-defined.[^16] See  [[intro.memory]] for the definition of
1911
  *byte* and  [[basic.types]] for the definition of *object
1912
  representation*.
1913
 
1914
  When applied to a reference or a reference type, the result is the size
1915
  of the referenced type. When applied to a class, the result is the
1916
  number of bytes in an object of that class including any padding
1917
  required for placing objects of that type in an array. The size of a
1918
  most derived class shall be greater than zero ([[intro.object]]). The
1919
  result of applying `sizeof` to a base class subobject is the size of the
1920
+ base class type.[^17] When applied to an array, the result is the total
1921
  number of bytes in the array. This implies that the size of an array of
1922
  *n* elements is *n* times the size of an element.
1923
 
1924
  The `sizeof` operator can be applied to a pointer to a function, but
1925
  shall not be applied directly to a function.
 
2058
  initial element (if any) of the array. both `new int` and `new int[10]`
2059
  have type `int*` and the type of `new int[i][10]` is `int (*)[10]` The
2060
  *attribute-specifier-seq* in a *noptr-new-declarator* appertains to the
2061
  associated array type.
2062
 
2063
+ Every *constant-expression* in a *noptr-new-declarator* shall be a
2064
+ converted constant expression ([[expr.const]]) of type `std::size_t`
2065
+ and shall evaluate to a strictly positive value. The *expression* in a
2066
+ *noptr-new-declarator*is implicitly converted to `std::size_t`. given
2067
+ the definition `int n = 42`, `new float[n][5]` is well-formed (because
2068
+ `n` is the *expression* of a *noptr-new-declarator*), but
2069
+ `new float[5][n]` is ill-formed (because `n` is not a constant
2070
+ expression).
 
 
 
 
2071
 
2072
+ The *expression* in a *noptr-new-declarator* is erroneous if:
 
 
 
 
 
 
 
 
 
2073
 
2074
+ - the expression is of non-class type and its value before converting to
2075
+ `std::size_t` is less than zero;
2076
+ - the expression is of class type and its value before application of
2077
+ the second standard conversion ([[over.ics.user]])[^18] is less than
2078
+ zero;
2079
+ - its value is such that the size of the allocated object would exceed
2080
+ the implementation-defined limit (annex  [[implimits]]); or
2081
+ - the *new-initializer* is a *braced-init-list* and the number of array
2082
+ elements for which initializers are provided (including the
2083
+ terminating `'\0'` in a string literal ([[lex.string]])) exceeds the
2084
+ number of elements to initialize.
2085
+
2086
+ If the *expression*, after converting to `std::size_t`, is a core
2087
+ constant expression and the expression is erroneous, the program is
2088
+ ill-formed. Otherwise, a *new-expression* with an erroneous expression
2089
+ does not call an allocation function and terminates by throwing an
2090
+ exception of a type that would match a handler ([[except.handle]]) of
2091
+ type `std::bad_array_new_length` ([[new.badlength]]). When the value of
2092
+ the *expression* is zero, the allocation function is called to allocate
2093
+ an array with no elements.
2094
+
2095
+ A *new-expression* may obtain storage for the object by calling an
2096
  *allocation function* ([[basic.stc.dynamic.allocation]]). If the
2097
  *new-expression* terminates by throwing an exception, it may release
2098
  storage by calling a deallocation function (
2099
  [[basic.stc.dynamic.deallocation]]). If the allocated type is a
2100
  non-array type, the allocation function’s name is `operator new` and the
 
2112
  if the allocated type is a class type `T` or array thereof, the
2113
  allocation function’s name is looked up in the scope of `T`. If this
2114
  lookup fails to find the name, or if the allocated type is not a class
2115
  type, the allocation function’s name is looked up in the global scope.
2116
 
2117
+ An implementation is allowed to omit a call to a replaceable global
2118
+ allocation function ([[new.delete.single]], [[new.delete.array]]). When
2119
+ it does so, the storage is instead provided by the implementation or
2120
+ provided by extending the allocation of another *new-expression*. The
2121
+ implementation may extend the allocation of a *new-expression* `e1` to
2122
+ provide storage for a *new-expression* `e2` if the following would be
2123
+ true were the allocation not extended:
2124
+
2125
+ - the evaluation of `e1` is sequenced before the evaluation of `e2`, and
2126
+ - `e2` is evaluated whenever `e1` obtains storage, and
2127
+ - both `e1` and `e2` invoke the same replaceable global allocation
2128
+ function, and
2129
+ - if the allocation function invoked by `e1` and `e2` is throwing, any
2130
+ exceptions thrown in the evaluation of either `e1` or `e2` would be
2131
+ first caught in the same handler, and
2132
+ - the pointer values produced by `e1` and `e2` are operands to evaluated
2133
+ *delete-expression*s, and
2134
+ - the evaluation of `e2` is sequenced before the evaluation of the
2135
+ *delete-expression* whose operand is the pointer value produced by
2136
+ `e1`.
2137
+
2138
+ ``` cpp
2139
+ void mergeable(int x) {
2140
+ // These allocations are safe for merging:
2141
+ std::unique_ptr<char[]> a{new (std::nothrow) char[8]};
2142
+ std::unique_ptr<char[]> b{new (std::nothrow) char[8]};
2143
+ std::unique_ptr<char[]> c{new (std::nothrow) char[x]};
2144
+
2145
+ g(a.get(), b.get(), c.get());
2146
+ }
2147
+
2148
+ void unmergeable(int x) {
2149
+ std::unique_ptr<char[]> a{new char[8]};
2150
+ try {
2151
+ // Merging this allocation would change its catch handler.
2152
+ std::unique_ptr<char[]> b{new char[x]};
2153
+ } catch (const std::bad_alloc& e) {
2154
+ std::cerr << "Allocation failed: " << e.what() << std::endl;
2155
+ throw;
2156
+ }
2157
+ }
2158
+ ```
2159
+
2160
+ When a *new-expression* calls an allocation function and that allocation
2161
+ has not been extended, the *new-expression* passes the amount of space
2162
+ requested to the allocation function as the first argument of type
2163
+ `std::size_t`. That argument shall be no less than the size of the
2164
+ object being created; it may be greater than the size of the object
2165
+ being created only if the object is an array. For arrays of `char` and
2166
+ `unsigned char`, the difference between the result of the
2167
+ *new-expression* and the address returned by the allocation function
2168
+ shall be an integral multiple of the strictest fundamental alignment
2169
+ requirement ([[basic.align]]) of any object type whose size is no
2170
+ greater than the size of the array being created. Because allocation
2171
+ functions are assumed to return pointers to storage that is
2172
+ appropriately aligned for objects of any type with fundamental
2173
+ alignment, this constraint on array allocation overhead permits the
2174
+ common idiom of allocating character arrays into which objects of other
2175
+ types will later be placed.
2176
+
2177
+ When a *new-expression* calls an allocation function and that allocation
2178
+ has been extended, the size argument to the allocation call shall be no
2179
+ greater than the sum of the sizes for the omitted calls as specified
2180
+ above, plus the size for the extended call had it not been extended,
2181
+ plus any padding necessary to align the allocated objects within the
2182
+ allocated memory.
2183
 
2184
  The *new-placement* syntax is used to supply additional arguments to an
2185
  allocation function. If used, overload resolution is performed on a
2186
  function call created by assembling an argument list consisting of the
2187
  amount of space requested (the first argument) and the expressions in
 
2226
 
2227
  A *new-expression* that creates an object of type `T` initializes that
2228
  object as follows:
2229
 
2230
  - If the *new-initializer* is omitted, the object is
2231
+ default-initialized ([[dcl.init]]). If no initialization is
2232
+ performed, the object has an indeterminate value.
2233
  - Otherwise, the *new-initializer* is interpreted according to the
2234
  initialization rules of  [[dcl.init]] for direct-initialization.
2235
 
2236
  The invocation of the allocation function is indeterminately sequenced
2237
  with respect to the evaluations of expressions in the *new-initializer*.
 
2241
  function returns the null pointer or exits using an exception.
2242
 
2243
  If the *new-expression* creates an object or an array of objects of
2244
  class type, access and ambiguity control are done for the allocation
2245
  function, the deallocation function ([[class.free]]), and the
2246
+ constructor ([[class.ctor]]). If the *new-expression* creates an array
2247
+ of objects of class type, the destructor is potentially invoked (
2248
+ [[class.dtor]]).
2249
 
2250
  If any part of the object initialization described above[^19] terminates
2251
+ by throwing an exception, storage has been obtained for the object, and
2252
+ a suitable deallocation function can be found, the deallocation function
2253
+ is called to free the memory in which the object was being constructed,
2254
+ after which the exception continues to propagate in the context of the
2255
+ *new-expression*. If no unambiguous matching deallocation function can
2256
+ be found, propagating the exception does not cause the object’s memory
2257
+ to be freed. This is appropriate when the called allocation function
2258
+ does not allocate memory; otherwise, it is likely to result in a memory
2259
+ leak.
2260
 
2261
  If the *new-expression* begins with a unary `::` operator, the
2262
  deallocation function’s name is looked up in the global scope.
2263
  Otherwise, if the allocated type is a class type `T` or an array
2264
  thereof, the deallocation function’s name is looked up in the scope of
 
2267
  looked up in the global scope.
2268
 
2269
  A declaration of a placement deallocation function matches the
2270
  declaration of a placement allocation function if it has the same number
2271
  of parameters and, after parameter transformations ([[dcl.fct]]), all
2272
+ parameter types except the first are identical. If the lookup finds a
2273
+ single matching deallocation function, that function will be called;
2274
+ otherwise, no deallocation function will be called. If the lookup finds
2275
+ the two-parameter form of a usual deallocation function (
2276
+ [[basic.stc.dynamic.deallocation]]) and that function, considered as a
2277
+ placement deallocation function, would have been selected as a match for
2278
+ the allocation function, the program is ill-formed. For a non-placement
2279
+ allocation function, the normal deallocation function lookup is used to
2280
+ find the matching deallocation function ([[expr.delete]])
2281
 
2282
  ``` cpp
2283
  struct S {
2284
  // Placement allocation function:
2285
  static void* operator new(std::size_t, std::size_t);
 
2316
  ```
2317
 
2318
  The first alternative is for non-array objects, and the second is for
2319
  arrays. Whenever the `delete` keyword is immediately followed by empty
2320
  square brackets, it shall be interpreted as the second alternative.[^20]
2321
+ The operand shall be of pointer to object type or of class type. If of
2322
+ class type, the operand is contextually implicitly converted (Clause 
2323
+ [[conv]]) to a pointer to object type.[^21] The *delete-expression*’s
2324
+ result has type `void`.
2325
 
2326
  If the operand has a class type, the operand is converted to a pointer
2327
  type by calling the above-mentioned conversion function, and the
2328
  converted operand is used in place of the original operand for the
2329
  remainder of this section. In the first alternative (*delete object*),
 
2362
  case of an array, the elements will be destroyed in order of decreasing
2363
  address (that is, in reverse order of the completion of their
2364
  constructor; see  [[class.base.init]]).
2365
 
2366
  If the value of the operand of the *delete-expression* is not a null
2367
+ pointer value, then:
2368
+
2369
+ - If the allocation call for the *new-expression* for the object to be
2370
+ deleted was not omitted and the allocation was not extended (
2371
+ [[expr.new]]), the *delete-expression* shall call a deallocation
2372
+ function ([[basic.stc.dynamic.deallocation]]). The value returned
2373
+ from the allocation call of the *new-expression* shall be passed as
2374
+ the first argument to the deallocation function.
2375
+ - Otherwise, if the allocation was extended or was provided by extending
2376
+ the allocation of another *new-expression*, and the
2377
+ *delete-expression* for every other pointer value produced by a
2378
+ *new-expression* that had storage provided by the extended
2379
+ *new-expression* has been evaluated, the *delete-expression* shall
2380
+ call a deallocation function. The value returned from the allocation
2381
+ call of the extended *new-expression* shall be passed as the first
2382
+ argument to the deallocation function.
2383
+ - Otherwise, the *delete-expression* will not call a *deallocation
2384
+ function* ([[basic.stc.dynamic.deallocation]]).
2385
+
2386
+ Otherwise, it is unspecified whether the deallocation function will be
2387
+ called. The deallocation function is called regardless of whether the
2388
+ destructor for the object or some element of the array throws an
2389
+ exception.
2390
 
2391
  An implementation provides default definitions of the global
2392
  deallocation functions `operator delete()` for non-arrays (
2393
  [[new.delete.single]]) and `operator delete[]()` for arrays (
2394
  [[new.delete.array]]). A C++ program can provide alternative definitions
2395
  of these functions ([[replacement.functions]]), and/or class-specific
2396
  versions ([[class.free]]).
2397
 
2398
  When the keyword `delete` in a *delete-expression* is preceded by the
2399
+ unary `::` operator, the deallocation function’s name is looked up in
2400
+ global scope. Otherwise, the lookup considers class-specific
2401
+ deallocation functions ([[class.free]]). If no class-specific
2402
+ deallocation function is found, the deallocation function’s name is
2403
+ looked up in global scope.
2404
+
2405
+ If the type is complete and if deallocation function lookup finds both a
2406
+ usual deallocation function with only a pointer parameter and a usual
2407
+ deallocation function with both a pointer parameter and a size
2408
+ parameter, then the selected deallocation function shall be the one with
2409
+ two parameters. Otherwise, the selected deallocation function shall be
2410
+ the function with one parameter.
2411
+
2412
+ When a *delete-expression* is executed, the selected deallocation
2413
+ function shall be called with the address of the block of storage to be
2414
+ reclaimed as its first argument and (if the two-parameter deallocation
2415
+ function is used) the size of the block as its second argument.[^23]
2416
 
2417
  Access and ambiguity control are done for both the deallocation function
2418
  and the destructor ([[class.dtor]],  [[class.free]]).
2419
 
2420
  ### Alignof <a id="expr.alignof">[[expr.alignof]]</a>
2421
 
2422
  An `alignof` expression yields the alignment requirement of its operand
2423
  type. The operand shall be a *type-id* representing a complete object
2424
+ type, or an array thereof, or a reference to one of those types.
2425
 
2426
  The result is an integral constant of type `std::size_t`.
2427
 
2428
+ When `alignof` is applied to a reference type, the result is the
2429
  alignment of the referenced type. When `alignof` is applied to an array
2430
+ type, the result is the alignment of the element type.
2431
 
2432
  ### `noexcept` operator <a id="expr.unary.noexcept">[[expr.unary.noexcept]]</a>
2433
 
2434
  The `noexcept` operator determines whether the evaluation of its
2435
  operand, which is an unevaluated operand (Clause  [[expr]]), can throw
 
2439
  noexcept-expression:
2440
  'noexcept' '(' expression ')'
2441
  ```
2442
 
2443
  The result of the `noexcept` operator is a constant of type `bool` and
2444
+ is a prvalue.
2445
 
2446
  The result of the `noexcept` operator is `false` if in a
2447
  potentially-evaluated context the *expression* would contain
2448
 
2449
+ - a potentially-evaluated call[^24] to a function, member function,
2450
  function pointer, or member function pointer that does not have a
2451
  non-throwing *exception-specification* ([[except.spec]]), unless the
2452
  call is a constant expression ([[expr.const]]),
2453
+ - a potentially-evaluated *throw-expression* ([[except.throw]]),
2454
+ - a potentially-evaluated `dynamic_cast` expression
2455
  `dynamic_cast<T>(v)`, where `T` is a reference type, that requires a
2456
  run-time check ([[expr.dynamic.cast]]), or
2457
+ - a potentially-evaluated `typeid` expression ([[expr.typeid]]) applied
2458
  to a glvalue expression whose type is a polymorphic class type (
2459
  [[class.virtual]]).
2460
 
2461
  Otherwise, the result is `true`.
2462
 
 
2464
 
2465
  The result of the expression `(T)` *cast-expression* is of type `T`. The
2466
  result is an lvalue if `T` is an lvalue reference type or an rvalue
2467
  reference to function type and an xvalue if `T` is an rvalue reference
2468
  to object type; otherwise the result is a prvalue. if `T` is a non-class
2469
+ type that is cv-qualified, the *cv-qualifiers* are discarded when
2470
+ determining the type of the resulting prvalue; see Clause  [[expr]].
2471
 
2472
  An explicit type conversion can be expressed using functional notation (
2473
  [[expr.type.conv]]), a type conversion operator (`dynamic_cast`,
2474
  `static_cast`, `reinterpret_cast`, `const_cast`), or the *cast*
2475
  notation.
 
2544
  pm-expression '.*' cast-expression
2545
  pm-expression '->*' cast-expression
2546
  ```
2547
 
2548
  The binary operator `.*` binds its second operand, which shall be of
2549
+ type “pointer to member of `T`” to its first operand, which shall be of
2550
+ class `T` or of a class of which `T` is an unambiguous and accessible
2551
+ base class. The result is an object or a function of the type specified
2552
+ by the second operand.
2553
 
2554
  The binary operator `->*` binds its second operand, which shall be of
2555
+ type “pointer to member of `T`” to its first operand, which shall be of
2556
+ type “pointer to `T`” or “pointer to a class of which `T` is an
2557
+ unambiguous and accessible base class.” The expression `E1->*E2` is
2558
+ converted into the equivalent form `(*(E1)).*E2`.
 
2559
 
2560
  Abbreviating *pm-expression*`.*`*cast-expression* as `E1.*E2`, `E1` is
2561
  called the *object expression*. If the dynamic type of `E1` does not
2562
  contain the member to which `E2` refers, the behavior is undefined.
2563
 
 
2593
  is an rvalue, the program is ill-formed if the second operand is a
2594
  pointer to member function with *ref-qualifier* `&`. In a `.*`
2595
  expression whose object expression is an lvalue, the program is
2596
  ill-formed if the second operand is a pointer to member function with
2597
  *ref-qualifier* `&&`. The result of a `.*` expression whose second
2598
+ operand is a pointer to a data member is an lvalue if the first operand
2599
+ is an lvalue and an xvalue otherwise. The result of a `.*` expression
2600
  whose second operand is a pointer to a member function is a prvalue. If
2601
  the second operand is the null pointer to member value ([[conv.mem]]),
2602
  the behavior is undefined.
2603
 
2604
  ## Multiplicative operators <a id="expr.mul">[[expr.mul]]</a>
 
2622
 
2623
  The binary `/` operator yields the quotient, and the binary `%` operator
2624
  yields the remainder from the division of the first expression by the
2625
  second. If the second operand of `/` or `%` is zero the behavior is
2626
  undefined. For integral operands the `/` operator yields the algebraic
2627
+ quotient with any fractional part discarded;[^25] if the quotient `a/b`
2628
  is representable in the type of the result, `(a/b)*b + a%b` is equal to
2629
+ `a`; otherwise, the behavior of both `a/b` and `a%b` is undefined.
2630
 
2631
  ## Additive operators <a id="expr.add">[[expr.add]]</a>
2632
 
2633
  The additive operators `+` and `-` group left-to-right. The usual
2634
  arithmetic conversions are performed for operands of arithmetic or
 
2698
  `-((P)-((Q)+1))`, and has the value zero if the expression `P` points
2699
  one past the last element of the array object, even though the
2700
  expression `(Q)+1` does not point to an element of the array object.
2701
  Unless both pointers point to elements of the same array object, or one
2702
  past the last element of the array object, the behavior is
2703
+ undefined.[^26]
2704
+
2705
+ For addition or subtraction, if the expressions `P` or `Q` have type
2706
+ “pointer to cv `T`”, where `T` is different from the cv-unqualified
2707
+ array element type, the behavior is undefined. In particular, a pointer
2708
+ to a base class cannot be used for pointer arithmetic when the array
2709
+ contains objects of a derived class type.
2710
 
2711
  If the value 0 is added to or subtracted from a pointer value, the
2712
  result compares equal to the original pointer value. If two pointers
2713
  point to the same object or both point one past the end of the same
2714
  array or both are null, and the two pointers are subtracted, the result
 
2734
  The value of `E1 << E2` is `E1` left-shifted `E2` bit positions; vacated
2735
  bits are zero-filled. If `E1` has an unsigned type, the value of the
2736
  result is $\mathrm{E1}\times2^\mathrm{E2}$, reduced modulo one more than
2737
  the maximum value representable in the result type. Otherwise, if `E1`
2738
  has a signed type and non-negative value, and
2739
+ $\mathrm{E1}\times2^\mathrm{E2}$ is representable in the corresponding
2740
+ unsigned type of the result type, then that value, converted to the
2741
+ result type, is the resulting value; otherwise, the behavior is
2742
+ undefined.
2743
 
2744
  The value of `E1 >> E2` is `E1` right-shifted `E2` bit positions. If
2745
  `E1` has an unsigned type or if `E1` has a signed type and a
2746
  non-negative value, the value of the result is the integral part of the
2747
  quotient of $\mathrm{E1}/2^\mathrm{E2}$. If `E1` has a signed type and a
 
2759
  relational-expression '>' shift-expression
2760
  relational-expression '<=' shift-expression
2761
  relational-expression '>=' shift-expression
2762
  ```
2763
 
2764
+ The operands shall have arithmetic, enumeration, or pointer type. The
2765
+ operators `<` (less than), `>` (greater than), `<=` (less than or equal
2766
+ to), and `>=` (greater than or equal to) all yield `false` or `true`.
2767
+ The type of the result is `bool`.
2768
 
2769
  The usual arithmetic conversions are performed on operands of arithmetic
2770
+ or enumeration type. If both operands are pointers, pointer
2771
+ conversions ([[conv.ptr]]) and qualification conversions (
2772
+ [[conv.qual]]) are performed to bring them to their composite pointer
2773
+ type (Clause  [[expr]]). After conversions, the operands shall have the
2774
+ same type.
 
 
 
 
 
 
 
 
 
 
 
 
2775
 
2776
+ Comparing pointers to objects is defined as follows:
 
 
 
 
 
 
 
 
 
2777
 
2778
+ - If two pointers point to different elements of the same array, or to
2779
+ subobjects thereof, the pointer to the element with the higher
2780
+ subscript compares greater.
2781
+ - If one pointer points to an element of an array, or to a subobject
2782
+ thereof, and another pointer points one past the last element of the
2783
+ array, the latter pointer compares greater.
2784
+ - If two pointers point to different non-static data members of the same
2785
+ object, or to subobjects of such members, recursively, the pointer to
2786
+ the later declared member compares greater provided the two members
2787
+ have the same access control (Clause  [[class.access]]) and provided
2788
+ their class is not a union.
2789
 
2790
+ If two operands `p` and `q` compare equal ([[expr.eq]]), `p<=q` and
2791
+ `p>=q` both yield `true` and `p<q` and `p>q` both yield `false`.
2792
+ Otherwise, if a pointer `p` compares greater than a pointer `q`, `p>=q`,
2793
+ `p>q`, `q<=p`, and `q<p` all yield `true` and `p<=q`, `p<q`, `q>=p`, and
2794
+ `q>p` all yield `false`. Otherwise, the result of each of the operators
2795
+ is unspecified.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2796
 
2797
  If both operands (after conversions) are of arithmetic or enumeration
2798
  type, each of the operators shall yield `true` if the specified
2799
  relationship is true and `false` if it is false.
2800
 
 
2805
  relational-expression
2806
  equality-expression '==' relational-expression
2807
  equality-expression '!=' relational-expression
2808
  ```
2809
 
2810
+ The `==` (equal to) and the `!=` (not equal to) operators group
2811
+ left-to-right. The operands shall have arithmetic, enumeration, pointer,
2812
+ or pointer to member type, or type `std::nullptr_t`. The operators `==`
2813
+ and `!=` both yield `true` or `false`, i.e., a result of type `bool`. In
2814
+ each case below, the operands shall have the same type after the
2815
+ specified conversions have been applied.
 
 
2816
 
2817
+ If at least one of the operands is a pointer, pointer conversions (
2818
+ [[conv.ptr]]) and qualification conversions ([[conv.qual]]) are
2819
+ performed on both operands to bring them to their composite pointer type
2820
+ (Clause  [[expr]]). Comparing pointers is defined as follows: Two
2821
+ pointers compare equal if they are both null, both point to the same
2822
+ function, or both represent the same address ([[basic.compound]]),
2823
+ otherwise they compare unequal.
 
 
 
 
 
 
 
 
 
2824
 
2825
+ If at least one of the operands is a pointer to member, pointer to
2826
+ member conversions ([[conv.mem]]) and qualification conversions (
2827
+ [[conv.qual]]) are performed on both operands to bring them to their
2828
+ composite pointer type (Clause  [[expr]]). Comparing pointers to members
2829
+ is defined as follows:
2830
+
2831
+ - If two pointers to members are both the null member pointer value,
2832
+ they compare equal.
2833
+ - If only one of two pointers to members is the null member pointer
2834
+ value, they compare unequal.
2835
+ - If either is a pointer to a virtual member function, the result is
2836
+ unspecified.
2837
+ - If one refers to a member of class `C1` and the other refers to a
2838
+ member of a different class `C2`, where neither is a base class of the
2839
+ other, the result is unspecified.
2840
+ ``` cpp
2841
+ struct A {};
2842
+ struct B : A { int x; };
2843
+ struct C : A { int x; };
2844
+
2845
+ int A::*bx = (int(A::*))&B::x;
2846
+ int A::*cx = (int(A::*))&C::x;
2847
+
2848
+ bool b1 = (bx == cx); // unspecified
2849
+ ```
2850
+ - Otherwise, two pointers to members compare equal if they would refer
2851
+ to the same member of the same most derived object ([[intro.object]])
2852
+ or the same subobject if indirection with a hypothetical object of the
2853
+ associated class type were performed, otherwise they compare unequal.
2854
  ``` cpp
2855
  struct B {
2856
  int f();
2857
  };
2858
  struct L : B { };
 
2863
  int (L::*pl)() = pb;
2864
  int (R::*pr)() = pb;
2865
  int (D::*pdl)() = pl;
2866
  int (D::*pdr)() = pr;
2867
  bool x = (pdl == pdr); // false
2868
+ bool y = (pb == pl); // true
2869
  ```
2870
 
2871
+ Two operands of type `std::nullptr_t` or one operand of type
2872
+ `std::nullptr_t` and the other a null pointer constant compare equal.
2873
 
2874
+ If two operands compare equal, the result is `true` for the `==`
2875
+ operator and `false` for the `!=` operator. If two operands compare
2876
+ unequal, the result is `false` for the `==` operator and `true` for the
2877
+ `!=` operator. Otherwise, the result of each of the operators is
2878
+ unspecified.
2879
+
2880
+ If both operands are of arithmetic or enumeration type, the usual
2881
+ arithmetic conversions are performed on both operands; each of the
2882
+ operators shall yield `true` if the specified relationship is true and
2883
+ `false` if it is false.
2884
 
2885
  ## Bitwise AND operator <a id="expr.bit.and">[[expr.bit.and]]</a>
2886
 
2887
  ``` bnf
2888
  and-expression:
 
2925
  inclusive-or-expression
2926
  logical-and-expression '&&' inclusive-or-expression
2927
  ```
2928
 
2929
  The `&&` operator groups left-to-right. The operands are both
2930
+ contextually converted to `bool` (Clause  [[conv]]). The result is
2931
  `true` if both operands are `true` and `false` otherwise. Unlike `&`,
2932
  `&&` guarantees left-to-right evaluation: the second operand is not
2933
  evaluated if the first operand is `false`.
2934
 
2935
  The result is a `bool`. If the second expression is evaluated, every
 
2971
  one of the second and third expressions is evaluated. Every value
2972
  computation and side effect associated with the first expression is
2973
  sequenced before every value computation and side effect associated with
2974
  the second or third expression.
2975
 
2976
+ If either the second or the third operand has type `void`, one of the
2977
+ following shall hold:
 
 
 
2978
 
2979
+ - The second or the third operand (but not both) is a (possibly
2980
+ parenthesized) *throw-expression* ([[except.throw]]); the result is
2981
+ of the type and value category of the other.
2982
  - Both the second and the third operands have type `void`; the result is
2983
  of type `void` and is a prvalue. This includes the case where both
2984
  operands are *throw-expression*s.
2985
 
2986
  Otherwise, if the second and third operand have different types and
 
2996
  reference to `T2`”, subject to the constraint that in the conversion
2997
  the reference must bind directly ([[dcl.init.ref]]) to an lvalue.
2998
  - If `E2` is an xvalue: `E1` can be converted to match `E2` if `E1` can
2999
  be implicitly converted to the type “rvalue reference to `T2`”,
3000
  subject to the constraint that the reference must bind directly.
3001
+ - If `E2` is a prvalue or if neither of the conversions above can be
3002
  done and at least one of the operands has (possibly cv-qualified)
3003
  class type:
3004
  - if `E1` and `E2` have class type, and the underlying class types are
3005
  the same or one is a base class of the other: `E1` can be converted
3006
  to match `E2` if the class of `T2` is the same type as, or a base
 
3016
  match `E2` if `E1` can be implicitly converted to the type that
3017
  expression `E2` would have if `E2` were converted to a prvalue (or
3018
  the type it has, if `E2` is a prvalue).
3019
 
3020
  Using this process, it is determined whether the second operand can be
3021
+ converted to match the third operand, and whether the third operand can
3022
+ be converted to match the second operand. If both can be converted, or
3023
+ one can be converted but the conversion is ambiguous, the program is
3024
+ ill-formed. If neither can be converted, the operands are left unchanged
3025
+ and further checking is performed as described below. If exactly one
3026
+ conversion is possible, that conversion is applied to the chosen operand
3027
+ and the converted operand is used in place of the original operand for
3028
+ the remainder of this section.
3029
 
3030
  If the second and third operands are glvalues of the same value category
3031
  and have the same type, the result is of that type and value category
3032
  and it is a bit-field if the second or the third operand is a bit-field,
3033
  or if both are bit-fields.
 
3052
  the second operand or the third operand depending on the value of the
3053
  first operand.
3054
  - The second and third operands have arithmetic or enumeration type; the
3055
  usual arithmetic conversions are performed to bring them to a common
3056
  type, and the result is of that type.
3057
+ - One or both of the second and third operands have pointer type;
3058
+ pointer conversions ([[conv.ptr]]) and qualification conversions (
 
 
3059
  [[conv.qual]]) are performed to bring them to their composite pointer
3060
+ type (Clause  [[expr]]). The result is of the composite pointer type.
3061
+ - One or both of the second and third operands have pointer to member
3062
+ type; pointer to member conversions ([[conv.mem]]) and qualification
3063
+ conversions ([[conv.qual]]) are performed to bring them to their
3064
+ composite pointer type (Clause  [[expr]]). The result is of the
3065
+ composite pointer type.
3066
+ - Both the second and third operands have type `std::nullptr_t` or one
3067
+ has that type and the other is a null pointer constant. The result is
3068
+ of type `std::nullptr_t`.
3069
 
3070
  ## Assignment and compound assignment operators <a id="expr.ass">[[expr.ass]]</a>
3071
 
3072
  The assignment operator (`=`) and the compound assignment operators all
3073
  group right-to-left. All require a modifiable lvalue as their left
 
3128
 
3129
  A *braced-init-list* may appear on the right-hand side of
3130
 
3131
  - an assignment to a scalar, in which case the initializer list shall
3132
  have at most a single element. The meaning of `x={v}`, where `T` is
3133
+ the scalar type of the expression `x`, is that of `x=T{v}`. The
3134
+ meaning of `x={}` is `x=T{}`.
3135
+ - an assignment to an object of class type, in which case the
3136
+ initializer list is passed as the argument to the assignment operator
3137
+ function selected by overload resolution ([[over.ass]],
3138
+ [[over.match]]).
3139
 
3140
  ``` cpp
3141
  complex<double> z;
3142
  z = { 1,2 }; // meaning z.operator=({1,2\)}
3143
  z += { 1, 2 }; // meaning z.operator+=({1,2\)}
 
3156
  expression ',' assignment-expression
3157
  ```
3158
 
3159
  A pair of expressions separated by a comma is evaluated left-to-right;
3160
  the left expression is a discarded-value expression (Clause 
3161
+ [[expr]]).[^27] Every value computation and side effect associated with
3162
  the left expression is sequenced before every value computation and side
3163
  effect associated with the right expression. The type and value of the
3164
  result are the type and value of the right operand; the result is of the
3165
  same value category as its right operand, and is a bit-field if its
3166
+ right operand is a glvalue and a bit-field. If the value of the right
3167
+ operand is a temporary ([[class.temporary]]), the result is that
3168
+ temporary.
3169
 
3170
  In contexts where comma is given a special meaning, in lists of
3171
  arguments to functions ([[expr.call]]) and lists of initializers (
3172
  [[dcl.init]]) the comma operator as described in Clause  [[expr]] can
3173
  appear only in parentheses.
 
3190
  ``` bnf
3191
  constant-expression:
3192
  conditional-expression
3193
  ```
3194
 
3195
+ A *conditional-expression* `e` is a *core constant expression* unless
3196
+ the evaluation of `e`, following the rules of the abstract machine (
3197
+ [[intro.execution]]), would evaluate one of the following expressions:
 
 
 
3198
 
3199
+ - `this` ([[expr.prim.general]]), except in a `constexpr` function or a
3200
+ `constexpr` constructor that is being evaluated as part of `e`;
 
 
3201
  - an invocation of a function other than a `constexpr` constructor for a
3202
+ literal class, a `constexpr` function, or an implicit invocation of a
3203
+ trivial destructor ([[class.dtor]]) Overload resolution (
3204
  [[over.match]]) is applied as usual ;
3205
  - an invocation of an undefined `constexpr` function or an undefined
3206
+ `constexpr` constructor;
3207
+ - an expression that would exceed the implementation-defined limits (see
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3208
  Annex  [[implimits]]);
3209
+ - an operation that would have undefined behavior including, for
3210
+ example, signed integer overflow (Clause [[expr]]), certain pointer
3211
+ arithmetic ([[expr.add]]), division by zero ([[expr.mul]]), or
3212
+ certain shift operations ([[expr.shift]]) ;
3213
  - a *lambda-expression* ([[expr.prim.lambda]]);
3214
  - an lvalue-to-rvalue conversion ([[conv.lval]]) unless it is applied
3215
  to
3216
+ - a non-volatile glvalue of integral or enumeration type that refers
3217
+ to a non-volatile const object with a preceding initialization,
3218
+ initialized with a constant expression a string literal (
3219
+ [[lex.string]]) corresponds to an array of such objects. , or
3220
+ - a non-volatile glvalue that refers to a non-volatile object defined
3221
+ with `constexpr`, or that refers to a non-mutable sub-object of such
3222
+ an object, or
3223
+ - a non-volatile glvalue of literal type that refers to a non-volatile
3224
+ object whose lifetime began within the evaluation of `e`;
3225
+ - an lvalue-to-rvalue conversion ([[conv.lval]]) or modification (
3226
+ [[expr.ass]], [[expr.post.incr]], [[expr.pre.incr]]) that is applied
3227
+ to a glvalue that refers to a non-active member of a union or a
3228
+ subobject thereof;
3229
  - an *id-expression* that refers to a variable or data member of
3230
+ reference type unless the reference has a preceding initialization and
3231
+ either
3232
+ - it is initialized with a constant expression or
3233
+ - it is a non-static data member of an object whose lifetime began
3234
+ within the evaluation of `e`;
3235
+ - in a *lambda-expression*, a reference to `this` or to a variable with
3236
+ automatic storage duration defined outside that *lambda-expression*,
3237
+ where the reference would be an odr-use ([[basic.def.odr]],
3238
+ [[expr.prim.lambda]]);
3239
+ - a conversion from type cv `void *` to a pointer-to-object type;
3240
  - a dynamic cast ([[expr.dynamic.cast]]);
3241
  - a `reinterpret_cast` ([[expr.reinterpret.cast]]);
3242
  - a pseudo-destructor call ([[expr.pseudo]]);
3243
+ - modification of an object ([[expr.ass]], [[expr.post.incr]],
3244
+ [[expr.pre.incr]]) unless it is applied to a non-volatile lvalue of
3245
+ literal type that refers to a non-volatile object whose lifetime began
3246
+ within the evaluation of `e`;
3247
+ - a typeid expression ([[expr.typeid]]) whose operand is a glvalue of a
3248
  polymorphic class type;
3249
  - a *new-expression* ([[expr.new]]);
3250
  - a *delete-expression* ([[expr.delete]]);
 
3251
  - a relational ([[expr.rel]]) or equality ([[expr.eq]]) operator where
3252
+ the result is unspecified; or
 
3253
  - a *throw-expression* ([[except.throw]]).
3254
 
3255
+ ``` cpp
3256
+ int x; // not constant
3257
+ struct A {
3258
+ constexpr A(bool b) : m(b?42:x) { }
3259
+ int m;
3260
+ };
3261
+ constexpr int v = A(true).m; // OK: constructor call initializes
3262
+ // m with the value 42
3263
+ constexpr int w = A(false).m; // error: initializer for m is
3264
+ // x, which is non-constant
3265
+
3266
+ constexpr int f1(int k) {
3267
+ constexpr int x = k; // error: x is not initialized by a
3268
+ // constant expression because lifetime of k
3269
+ // began outside the initializer of x
3270
+ return x;
3271
+ }
3272
+ constexpr int f2(int k) {
3273
+ int x = k; // OK: not required to be a constant expression
3274
+ // because x is not constexpr
3275
+ return x;
3276
+ }
3277
+
3278
+ constexpr int incr(int &n) {
3279
+ return ++n;
3280
+ }
3281
+ constexpr int g(int k) {
3282
+ constexpr int x = incr(k); // error: incr(k) is not a core constant
3283
+ // expression because lifetime of k
3284
+ // began outside the expression incr(k)
3285
+ return x;
3286
+ }
3287
+ constexpr int h(int k) {
3288
+ int x = incr(k); // OK: incr(k) is not required to be a core
3289
+ // constant expression
3290
+ return x;
3291
+ }
3292
+ constexpr int y = h(1); // OK: initializes y with the value 2
3293
+ // h(1) is a core constant expression because
3294
+ // the lifetime of k begins inside h(1)
3295
+ ```
3296
+
3297
+ An *integral constant expression* is an expression of integral or
3298
+ unscoped enumeration type, implicitly converted to a prvalue, where the
3299
+ converted expression is a core constant expression. Such expressions may
3300
+ be used as array bounds ([[dcl.array]], [[expr.new]]), as bit-field
3301
+ lengths ([[class.bit]]), as enumerator initializers if the underlying
3302
+ type is not fixed ([[dcl.enum]]), and as alignments ([[dcl.align]]). A
3303
+ *converted constant expression* of type `T` is an expression, implicitly
3304
+ converted to a prvalue of type `T`, where the converted expression is a
3305
+ core constant expression and the implicit conversion sequence contains
3306
+ only user-defined conversions, lvalue-to-rvalue conversions (
3307
+ [[conv.lval]]), integral promotions ([[conv.prom]]), and integral
3308
+ conversions ([[conv.integral]]) other than narrowing conversions (
3309
+ [[dcl.init.list]]). such expressions may be used in `new` expressions (
3310
+ [[expr.new]]), as case expressions ([[stmt.switch]]), as enumerator
3311
+ initializers if the underlying type is fixed ([[dcl.enum]]), as array
3312
+ bounds ([[dcl.array]]), and as integral or enumeration non-type
3313
+ template arguments ([[temp.arg]]).
3314
+
3315
+ A *constant expression* is either a glvalue core constant expression
3316
+ whose value refers to an object with static storage duration or to a
3317
+ function, or a prvalue core constant expression whose value is an object
3318
+ where, for that object and its subobjects:
3319
+
3320
+ - each non-static data member of reference type refers to an object with
3321
+ static storage duration or to a function, and
3322
+ - if the object or subobject is of pointer type, it contains the address
3323
+ of an object with static storage duration, the address past the end of
3324
+ such an object ([[expr.add]]), the address of a function, or a null
3325
+ pointer value.
3326
 
 
 
3327
  Since this International Standard imposes no restrictions on the
3328
  accuracy of floating-point operations, it is unspecified whether the
3329
  evaluation of a floating-point expression during translation yields the
3330
  same result as the evaluation of the same expression (or the same
3331
+ operations on the same values) during program execution.[^28]
3332
 
3333
  ``` cpp
3334
  bool f() {
3335
  char array[1 + int(1 + 0.2 - 0.1 - 0.1)]; // Must be evaluated during translation
3336
  int size = 1 + int(1 + 0.2 - 0.1 - 0.1); // May be evaluated at runtime
 
3339
  ```
3340
 
3341
  It is unspecified whether the value of `f()` will be `true` or `false`.
3342
 
3343
  If an expression of literal class type is used in a context where an
3344
+ integral constant expression is required, then that expression is
3345
+ contextually implicitly converted (Clause  [[conv]]) to an integral or
3346
+ unscoped enumeration type and the selected conversion function shall be
3347
  `constexpr`.
3348
 
3349
  ``` cpp
3350
  struct A {
3351
  constexpr A(int i) : val(i) { }
3352
+ constexpr operator int() const { return val; }
3353
+ constexpr operator long() const { return 43; }
3354
  private:
3355
  int val;
3356
  };
3357
  template<int> struct X { };
3358
  constexpr A a = 42;
 
3372
  [basic.lookup.argdep]: basic.md#basic.lookup.argdep
3373
  [basic.lookup.classref]: basic.md#basic.lookup.classref
3374
  [basic.lookup.unqual]: basic.md#basic.lookup.unqual
3375
  [basic.lval]: basic.md#basic.lval
3376
  [basic.namespace]: dcl.md#basic.namespace
3377
+ [basic.scope.block]: basic.md#basic.scope.block
3378
  [basic.scope.class]: basic.md#basic.scope.class
 
3379
  [basic.start.main]: basic.md#basic.start.main
3380
  [basic.stc.dynamic]: basic.md#basic.stc.dynamic
3381
  [basic.stc.dynamic.allocation]: basic.md#basic.stc.dynamic.allocation
3382
  [basic.stc.dynamic.deallocation]: basic.md#basic.stc.dynamic.deallocation
3383
  [basic.stc.dynamic.safety]: basic.md#basic.stc.dynamic.safety
 
3420
  [conv.prom]: conv.md#conv.prom
3421
  [conv.ptr]: conv.md#conv.ptr
3422
  [conv.qual]: conv.md#conv.qual
3423
  [dcl.align]: dcl.md#dcl.align
3424
  [dcl.array]: dcl.md#dcl.array
 
3425
  [dcl.dcl]: dcl.md#dcl.dcl
3426
  [dcl.enum]: dcl.md#dcl.enum
3427
  [dcl.fct]: dcl.md#dcl.fct
3428
  [dcl.fct.def]: dcl.md#dcl.fct.def
3429
  [dcl.fct.def.delete]: dcl.md#dcl.fct.def.delete
3430
+ [dcl.fct.def.general]: dcl.md#dcl.fct.def.general
3431
  [dcl.fct.default]: dcl.md#dcl.fct.default
3432
  [dcl.init]: dcl.md#dcl.init
3433
  [dcl.init.aggr]: dcl.md#dcl.init.aggr
3434
  [dcl.init.list]: dcl.md#dcl.init.list
3435
  [dcl.init.ref]: dcl.md#dcl.init.ref
 
3499
  [new.delete.single]: language.md#new.delete.single
3500
  [over]: over.md#over
3501
  [over.ass]: over.md#over.ass
3502
  [over.built]: over.md#over.built
3503
  [over.call]: over.md#over.call
3504
+ [over.ics.user]: over.md#over.ics.user
3505
  [over.literal]: over.md#over.literal
3506
  [over.match]: over.md#over.match
3507
  [over.match.oper]: over.md#over.match.oper
3508
  [over.oper]: over.md#over.oper
3509
  [over.over]: over.md#over.over
3510
  [replacement.functions]: library.md#replacement.functions
3511
  [stmt.switch]: stmt.md#stmt.switch
3512
  [support.runtime]: language.md#support.runtime
3513
  [support.types]: language.md#support.types
3514
  [temp.arg]: temp.md#temp.arg
3515
+ [temp.mem]: temp.md#temp.mem
3516
  [temp.names]: temp.md#temp.names
3517
  [temp.res]: temp.md#temp.res
3518
  [temp.variadic]: temp.md#temp.variadic
3519
  [type.info]: language.md#type.info
3520
 
 
3533
  `(*this)` ([[class.mfct.non-static]]).
3534
 
3535
  [^5]: This is true even if the subscript operator is used in the
3536
  following common idiom: `&x[0]`.
3537
 
3538
+ [^6]: If the class member access expression is evaluated, the
 
 
 
3539
  subexpression evaluation happens even if the result is unnecessary
3540
  to determine the value of the entire postfix expression, for example
3541
  if the *id-expression* denotes a static member.
3542
 
3543
+ [^7]: Note that `(*(E1))` is an lvalue.
3544
 
3545
+ [^8]: The most derived object ([[intro.object]]) pointed or referred to
3546
  by `v` can contain other `B` objects as base classes, but these are
3547
  ignored.
3548
 
3549
+ [^9]: The recommended name for such a class is `extended_type_info`.
3550
 
3551
+ [^10]: If `p` is an expression of pointer type, then `*p`, `(*p)`,
3552
  `*(p)`, `((*p))`, `*((p))`, and so on all meet this requirement.
3553
 
3554
+ [^11]: Function types (including those used in pointer to member
3555
  function types) are never cv-qualified; see  [[dcl.fct]].
3556
 
3557
+ [^12]: The types may have different cv-qualifiers, subject to the
3558
  overall restriction that a `reinterpret_cast` cannot cast away
3559
  constness.
3560
 
3561
+ [^13]: `T1` and `T2` may have different cv-qualifiers, subject to the
3562
  overall restriction that a `reinterpret_cast` cannot cast away
3563
  constness.
3564
 
3565
+ [^14]: This is sometimes referred to as a *type pun*.
3566
 
3567
+ [^15]: `const_cast`
3568
 
3569
  is not limited to conversions that cast away a const-qualifier.
3570
 
3571
+ [^16]: `sizeof(bool)` is not required to be `1`.
3572
 
3573
+ [^17]: The actual size of a base class subobject may be less than the
3574
  result of applying `sizeof` to the subobject, due to virtual base
3575
  classes and less strict padding requirements on base class
3576
  subobjects.
3577
 
3578
+ [^18]: If the conversion function returns a signed integer type, the
3579
+ second standard conversion converts to the unsigned type
3580
+ `std::size_t` and thus thwarts any attempt to detect a negative
3581
+ value afterwards.
3582
+
3583
  [^19]: This may include evaluating a *new-initializer* and/or calling a
3584
  constructor.
3585
 
3586
  [^20]: A lambda expression with a *lambda-introducer* that consists of
3587
  empty square brackets can follow the `delete` keyword if the lambda
 
3592
 
3593
  [^22]: For non-zero-length arrays, this is the same as a pointer to the
3594
  first element of the array created by that *new-expression*.
3595
  Zero-length arrays do not have a first element.
3596
 
3597
+ [^23]: If the static type of the object to be deleted is complete and is
3598
+ different from the dynamic type, and the destructor is not virtual,
3599
+ the size might be incorrect, but that case is already undefined, as
3600
+ stated above.
3601
+
3602
+ [^24]: This includes implicit calls such as the call to an allocation
3603
  function in a *new-expression*.
3604
 
3605
+ [^25]: This is often called truncation towards zero.
3606
 
3607
+ [^26]: Another way to approach pointer arithmetic is first to convert
3608
  the pointer(s) to character pointer(s): In this scheme the integral
3609
  value of the expression added to or subtracted from the converted
3610
  pointer is first multiplied by the size of the object originally
3611
  pointed to, and the resulting pointer is converted back to the
3612
  original type. For pointer subtraction, the result of the difference
 
3616
  When viewed in this way, an implementation need only provide one
3617
  extra byte (which might overlap another object in the program) just
3618
  after the end of the object in order to satisfy the “one past the
3619
  last element” requirements.
3620
 
3621
+ [^27]: However, an invocation of an overloaded comma operator is an
3622
  ordinary function call; hence, the evaluations of its argument
3623
  expressions are unsequenced relative to one another (see
3624
  [[intro.execution]]).
3625
 
3626
+ [^28]: Nonetheless, implementations are encouraged to provide consistent
3627
+ results, irrespective of whether the evaluation was performed during
3628
+ translation and/or during program execution.