From Jason Turner

[basic]

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

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpre5ha1pc/{from.md → to.md} +1567 -784
tmp/tmpre5ha1pc/{from.md → to.md} RENAMED
@@ -13,88 +13,105 @@ compound types from these. — *end note*]
13
 
14
  [*Note 2*: This Clause does not cover concepts that affect only a
15
  single part of the language. Such concepts are discussed in the relevant
16
  Clauses. — *end note*]
17
 
18
- An *entity* is a value, object, reference, structured binding, function,
19
- enumerator, type, class member, bit-field, template, template
20
- specialization, namespace, or pack.
21
 
22
- A *name* is an *identifier* [[lex.name]], *operator-function-id*
23
- [[over.oper]], *literal-operator-id* [[over.literal]], or
24
- *conversion-function-id* [[class.conv.fct]].
 
 
 
 
 
25
 
26
  Every name is introduced by a *declaration*, which is a
27
 
28
  - *name-declaration*, *block-declaration*, or *member-declaration*
29
  [[dcl.pre]], [[class.mem]],
30
  - *init-declarator* [[dcl.decl]],
31
  - *identifier* in a structured binding declaration [[dcl.struct.bind]],
 
 
32
  - *init-capture* [[expr.prim.lambda.capture]],
33
  - *condition* with a *declarator* [[stmt.pre]],
34
  - *member-declarator* [[class.mem]],
35
  - *using-declarator* [[namespace.udecl]],
36
- - *parameter-declaration* [[dcl.fct]],
37
  - *type-parameter* [[temp.param]],
 
 
 
38
  - *elaborated-type-specifier* that introduces a name [[dcl.type.elab]],
39
  - *class-specifier* [[class.pre]],
40
  - *enum-specifier* or *enumerator-definition* [[dcl.enum]],
41
  - *exception-declaration* [[except.pre]], or
42
  - implicit declaration of an injected-class-name [[class.pre]].
43
 
44
- [*Note 3*: The interpretation of a *for-range-declaration* produces one
 
 
 
45
  or more of the above [[stmt.ranged]]. — *end note*]
46
 
47
- An entity E is denoted by the name (if any) that is introduced by a
48
- declaration of E or by a *typedef-name* introduced by a declaration
49
- specifying E.
 
50
 
51
- A *variable* is introduced by the declaration of a reference other than
52
- a non-static data member or of an object. The variable’s name, if any,
53
- denotes the reference or object.
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  A *local entity* is a variable with automatic storage duration
56
  [[basic.stc.auto]], a structured binding [[dcl.struct.bind]] whose
57
- corresponding variable is such an entity, or the `*this` object
58
- [[expr.prim.this]].
59
-
60
- Some names denote types or templates. In general, whenever a name is
61
- encountered it is necessary to determine whether that name denotes one
62
- of these entities before continuing to parse the program that contains
63
- it. The process that determines this is called *name lookup*
64
- [[basic.lookup]].
65
-
66
- Two names are *the same* if
67
-
68
- - they are *identifier*s composed of the same character sequence, or
69
- - they are *operator-function-id*s formed with the same operator, or
70
- - they are *conversion-function-id*s formed with equivalent
71
- [[temp.over.link]] types, or
72
- - they are *literal-operator-id*s [[over.literal]] formed with the same
73
- literal suffix identifier.
74
 
75
  A name used in more than one translation unit can potentially refer to
76
  the same entity in these translation units depending on the linkage
77
  [[basic.link]] of the name specified in each translation unit.
78
 
79
  ## Declarations and definitions <a id="basic.def">[[basic.def]]</a>
80
 
81
- A declaration [[dcl.dcl]] may (re)introduce one or more names and/or
82
  entities into a translation unit. If so, the declaration specifies the
83
  interpretation and semantic properties of these names. A declaration of
84
- an entity or *typedef-name* X is a redeclaration of X if another
85
- declaration of X is reachable from it [[module.reach]]. A declaration
86
- may also have effects including:
 
 
 
 
87
 
88
  - a static assertion [[dcl.pre]],
89
  - controlling template instantiation [[temp.explicit]],
90
  - guiding template argument deduction for constructors
91
  [[temp.deduct.guide]],
92
  - use of attributes [[dcl.attr]], and
93
  - nothing (in the case of an *empty-declaration*).
94
 
95
- Each entity declared by a *declaration* is also *defined* by that
 
 
96
  declaration unless:
97
 
98
  - it declares a function without specifying the function’s body
99
  [[dcl.fct.def]],
100
  - it contains the `extern` specifier [[dcl.stc]] or a
@@ -102,28 +119,31 @@ declaration unless:
102
  nor a *function-body*,
103
  - it declares a non-inline static data member in a class definition
104
  [[class.mem]], [[class.static]],
105
  - it declares a static data member outside a class definition and the
106
  variable was defined within the class with the `constexpr` specifier
107
- (this usage is deprecated; see [[depr.static.constexpr]]),
 
108
  - it is an *elaborated-type-specifier* [[class.name]],
109
  - it is an *opaque-enum-declaration* [[dcl.enum]],
110
  - it is a *template-parameter* [[temp.param]],
111
  - it is a *parameter-declaration* [[dcl.fct]] in a function declarator
112
  that is not the *declarator* of a *function-definition*,
113
  - it is a `typedef` declaration [[dcl.typedef]],
114
  - it is an *alias-declaration* [[dcl.typedef]],
 
115
  - it is a *using-declaration* [[namespace.udecl]],
116
  - it is a *deduction-guide* [[temp.deduct.guide]],
117
  - it is a *static_assert-declaration* [[dcl.pre]],
 
118
  - it is an *attribute-declaration* [[dcl.pre]],
119
  - it is an *empty-declaration* [[dcl.pre]],
120
  - it is a *using-directive* [[namespace.udir]],
121
  - it is a *using-enum-declaration* [[enum.udecl]],
122
  - it is a *template-declaration* [[temp.pre]] whose *template-head* is
123
  not followed by either a *concept-definition* or a *declaration* that
124
- defines a function, a class, a variable, or a static data member.
125
  - it is an explicit instantiation declaration [[temp.explicit]], or
126
  - it is an explicit specialization [[temp.expl.spec]] whose
127
  *declaration* is not a definition.
128
 
129
  A declaration is said to be a *definition* of each entity that it
@@ -144,11 +164,10 @@ struct X { // defines X
144
  X(): x(0) { } // defines a constructor of X
145
  };
146
  int X::y = 1; // defines X::y
147
  enum { up, down }; // defines up and down
148
  namespace N { int d; } // defines N and N::d
149
- namespace N1 = N; // defines N1
150
  X anX; // defines anX
151
  ```
152
 
153
  whereas these are just declarations:
154
 
@@ -156,17 +175,18 @@ whereas these are just declarations:
156
  extern int a; // declares a
157
  extern const int c; // declares c
158
  int f(int); // declares f
159
  struct S; // declares S
160
  typedef int Int; // declares Int
 
161
  extern X anotherX; // declares anotherX
162
  using N::d; // declares d
163
  ```
164
 
165
  — *end example*]
166
 
167
- [*Note 1*: In some circumstances, C++ implementations implicitly
168
  define the default constructor [[class.default.ctor]], copy constructor,
169
  move constructor [[class.copy.ctor]], copy assignment operator, move
170
  assignment operator [[class.copy.assign]], or destructor [[class.dtor]]
171
  member functions. — *end note*]
172
 
@@ -205,11 +225,11 @@ struct C {
205
  };
206
  ```
207
 
208
  — *end example*]
209
 
210
- [*Note 2*: A class name can also be implicitly declared by an
211
  *elaborated-type-specifier* [[dcl.type.elab]]. — *end note*]
212
 
213
  In the definition of an object, the type of that object shall not be an
214
  incomplete type [[term.incomplete.type]], an abstract class type
215
  [[class.abstract]], or a (possibly multidimensional) array thereof.
@@ -234,11 +254,12 @@ An expression or conversion is *potentially evaluated* unless it is an
234
  unevaluated operand [[expr.context]], a subexpression thereof, or a
235
  conversion in an initialization or conversion sequence in such a
236
  context. The set of *potential results* of an expression E is defined as
237
  follows:
238
 
239
- - If E is an *id-expression* [[expr.prim.id]], the set contains only E.
 
240
  - If E is a subscripting operation [[expr.sub]] with an array operand,
241
  the set contains the potential results of that operand.
242
  - If E is a class member access expression [[expr.ref]] of the form E₁
243
  `.` `template`ₒₚₜ E₂ naming a non-static data member, the set
244
  contains the potential results of E₁.
@@ -255,24 +276,26 @@ follows:
255
  potential results of the right operand.
256
  - Otherwise, the set is empty.
257
 
258
  [*Note 1*:
259
 
260
- This set is a (possibly-empty) set of *id-expression*s, each of which is
261
- either E or a subexpression of E.
262
 
263
  [*Example 1*:
264
 
265
  In the following example, the set of potential results of the
266
  initializer of `n` contains the first `S::x` subexpression, but not the
267
- second `S::x` subexpression.
 
268
 
269
  ``` cpp
270
  struct S { static const int x = 0; };
271
  const int &f(const int &r);
272
  int n = b ? (1, S::x) // S::x is not odr-used here
273
  : f(S::x); // S::x is odr-used here, so a definition is required
 
274
  ```
275
 
276
  — *end example*]
277
 
278
  — *end note*]
@@ -281,13 +304,13 @@ A function is *named by* an expression or conversion as follows:
281
 
282
  - A function is named by an expression or conversion if it is the
283
  selected member of an overload set
284
  [[basic.lookup]], [[over.match]], [[over.over]] in an overload
285
  resolution performed as part of forming that expression or conversion,
286
- unless it is a pure virtual function and either the expression is not
287
- an *id-expression* naming the function with an explicitly qualified
288
- name or the expression forms a pointer to member [[expr.unary.op]].
289
  \[*Note 2*: This covers taking the address of functions
290
  [[conv.func]], [[expr.unary.op]], calls to named functions
291
  [[expr.call]], operator overloading [[over]], user-defined conversions
292
  [[class.conv.fct]], allocation functions for *new-expression*s
293
  [[expr.new]], as well as non-default initialization [[dcl.init]]. A
@@ -302,31 +325,64 @@ A function is *named by* an expression or conversion as follows:
302
  - A deallocation function for a class is named by a *delete-expression*
303
  if it is the selected usual deallocation function as specified in 
304
  [[expr.delete]] and  [[class.free]].
305
 
306
  A variable is named by an expression if the expression is an
307
- *id-expression* that denotes it. A variable `x` that is named by a
308
- potentially-evaluated expression E is *odr-used* by E unless
 
309
 
310
- - `x` is a reference that is usable in constant expressions
311
- [[expr.const]], or
312
- - `x` is a variable of non-reference type that is usable in constant
313
- expressions and has no mutable subobjects, and E is an element of the
314
- set of potential results of an expression of non-volatile-qualified
315
- non-class type to which the lvalue-to-rvalue conversion [[conv.lval]]
316
- is applied, or
317
- - `x` is a variable of non-reference type, and E is an element of the
318
- set of potential results of a discarded-value expression
319
- [[expr.context]] to which the lvalue-to-rvalue conversion is not
320
- applied.
 
 
321
 
322
- A structured binding is odr-used if it appears as a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
323
  potentially-evaluated expression.
324
 
325
  `*this` is odr-used if `this` appears as a potentially-evaluated
326
- expression (including as the result of the implicit transformation in
327
- the body of a non-static member function [[class.mfct.non.static]]).
328
 
329
  A virtual member function is odr-used if it is not pure. A function is
330
  odr-used if it is named by a potentially-evaluated expression or
331
  conversion. A non-placement allocation or deallocation function for a
332
  class is odr-used by the definition of a constructor of that class. A
@@ -334,36 +390,40 @@ non-placement deallocation function for a class is odr-used by the
334
  definition of the destructor of that class, or by being selected by the
335
  lookup at the point of definition of a virtual destructor
336
  [[class.dtor]].[^2]
337
 
338
  An assignment operator function in a class is odr-used by an
339
- implicitly-defined copy-assignment or move-assignment function for
340
  another class as specified in  [[class.copy.assign]]. A constructor for
341
  a class is odr-used as specified in  [[dcl.init]]. A destructor for a
342
  class is odr-used if it is potentially invoked [[class.dtor]].
343
 
344
  A local entity [[basic.pre]] is *odr-usable* in a scope
345
- [[basic.scope.scope]] if:
346
 
347
  - either the local entity is not `*this`, or an enclosing class or
348
  non-lambda function parameter scope exists and, if the innermost such
349
  scope is a function parameter scope, it corresponds to a non-static
350
  member function, and
351
  - for each intervening scope [[basic.scope.scope]] between the point at
352
  which the entity is introduced and the scope (where `*this` is
353
  considered to be introduced within the innermost enclosing class or
354
- non-lambda function definition scope), either:
355
- - the intervening scope is a block scope, or
 
 
356
  - the intervening scope is the function parameter scope of a
357
- *lambda-expression* that has a *simple-capture* naming the entity or
358
- has a *capture-default*, and the block scope of the
359
- *lambda-expression* is also an intervening scope.
 
 
360
 
361
  If a local entity is odr-used in a scope in which it is not odr-usable,
362
  the program is ill-formed.
363
 
364
- [*Example 2*:
365
 
366
  ``` cpp
367
  void f(int n) {
368
  [] { n = 1; }; // error: n is not odr-usable due to intervening lambda-expression
369
  struct A {
@@ -376,19 +436,41 @@ void f(int n) {
376
  }
377
  ```
378
 
379
  — *end example*]
380
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
381
  Every program shall contain at least one definition of every function or
382
  variable that is odr-used in that program outside of a discarded
383
  statement [[stmt.if]]; no diagnostic required. The definition can appear
384
  explicitly in the program, it can be found in the standard or a
385
  user-defined library, or (when appropriate) it is implicitly defined
386
  (see  [[class.default.ctor]], [[class.copy.ctor]], [[class.dtor]], and
387
  [[class.copy.assign]]).
388
 
389
- [*Example 3*:
390
 
391
  ``` cpp
392
  auto f() {
393
  struct A {};
394
  return A{};
@@ -411,11 +493,11 @@ end of every definition domain in which it is odr-used outside of a
411
  discarded statement.
412
 
413
  A definition of a class shall be reachable in every context in which the
414
  class is used in a way that requires the class type to be complete.
415
 
416
- [*Example 4*:
417
 
418
  The following complete translation unit is well-formed, even though it
419
  never defines `X`:
420
 
421
  ``` cpp
@@ -427,11 +509,11 @@ X* x2; // use X in pointer formation
427
  — *end example*]
428
 
429
  [*Note 3*:
430
 
431
  The rules for declarations and expressions describe in which contexts
432
- complete class types are required. A class type `T` must be complete if:
433
 
434
  - an object of type `T` is defined [[basic.def]], or
435
  - a non-static class data member of type `T` is declared [[class.mem]],
436
  or
437
  - `T` is used as the allocated type or array element type in a
@@ -451,20 +533,27 @@ complete class types are required. A class type `T` must be complete if:
451
  - the `typeid` operator [[expr.typeid]] or the `sizeof` operator
452
  [[expr.sizeof]] is applied to an operand of type `T`, or
453
  - a function with a return type or argument type of type `T` is defined
454
  [[basic.def]] or called [[expr.call]], or
455
  - a class with a base class of type `T` is defined [[class.derived]], or
456
- - an lvalue of type `T` is assigned to [[expr.ass]], or
457
  - the type `T` is the subject of an `alignof` expression
458
  [[expr.alignof]], or
459
  - an *exception-declaration* has type `T`, reference to `T`, or pointer
460
  to `T` [[except.handle]].
461
 
462
  — *end note*]
463
 
464
- For any definable item `D` with definitions in multiple translation
465
- units,
 
 
 
 
 
 
 
466
 
467
  - if `D` is a non-inline non-templated function or variable, or
468
  - if the definitions in different translation units do not satisfy the
469
  following requirements,
470
 
@@ -479,24 +568,25 @@ point, the following requirements shall be satisfied.
479
  [[module.unit]].
480
  - Each such definition shall consist of the same sequence of tokens,
481
  where the definition of a closure type is considered to consist of the
482
  sequence of tokens of the corresponding *lambda-expression*.
483
  - In each such definition, corresponding names, looked up according to 
484
- [[basic.lookup]], shall refer to the same entity, after overload
485
  resolution [[over.match]] and after matching of partial template
486
- specialization [[temp.over]], except that a name can refer to
 
487
  - a non-volatile const object with internal or no linkage if the
488
  object
489
  - has the same literal type in all definitions of `D`,
490
  - is initialized with a constant expression [[expr.const]],
491
  - is not odr-used in any definition of `D`, and
492
  - has the same value in all definitions of `D`,
493
 
494
  or
495
  - a reference with internal or no linkage initialized with a constant
496
- expression such that the reference refers to the same entity in all
497
- definitions of `D`.
498
  - In each such definition, except within the default arguments and
499
  default template arguments of `D`, corresponding *lambda-expression*s
500
  shall have the same closure type (see below).
501
  - In each such definition, corresponding entities shall have the same
502
  language linkage.
@@ -510,20 +600,26 @@ point, the following requirements shall be satisfied.
510
  implicit calls to conversion functions, constructors, operator new
511
  functions and operator delete functions, shall refer to the same
512
  function.
513
  - In each such definition, a default argument used by an (implicit or
514
  explicit) function call or a default template argument used by an
515
- (implicit or explicit) *template-id* or *simple-template-id* is
516
- treated as if its token sequence were present in the definition of
517
- `D`; that is, the default argument or default template argument is
518
- subject to the requirements described in this paragraph (recursively).
 
 
 
 
 
 
519
  - If `D` is a class with an implicitly-declared constructor
520
  [[class.default.ctor]], [[class.copy.ctor]], it is as if the
521
  constructor was implicitly defined in every translation unit where it
522
  is odr-used, and the implicit definition in every translation unit
523
  shall call the same constructor for a subobject of `D`.
524
- \[*Example 5*:
525
  ``` cpp
526
  // translation unit 1:
527
  struct X {
528
  X(int, int);
529
  X(int, int, int);
@@ -551,31 +647,31 @@ point, the following requirements shall be satisfied.
551
  - If `D` is a class with a defaulted three-way comparison operator
552
  function [[class.spaceship]], it is as if the operator was implicitly
553
  defined in every translation unit where it is odr-used, and the
554
  implicit definition in every translation unit shall call the same
555
  comparison operators for each subobject of `D`.
 
 
 
 
556
 
557
- If `D` is a template and is defined in more than one translation unit,
558
- then the preceding requirements shall apply both to names from the
559
- template’s enclosing scope used in the template definition, and also to
560
- dependent names at the point of instantiation [[temp.dep]]. These
561
- requirements also apply to corresponding entities defined within each
562
- definition of `D` (including the closure types of *lambda-expression*s,
563
- but excluding entities defined within default arguments or default
564
- template arguments of either `D` or an entity not defined within `D`).
565
- For each such entity and for `D` itself, the behavior is as if there is
566
- a single entity with a single definition, including in the application
567
- of these requirements to other entities.
568
 
569
  [*Note 4*: The entity is still declared in multiple translation units,
570
  and [[basic.link]] still applies to these declarations. In particular,
571
  *lambda-expression*s [[expr.prim.lambda]] appearing in the type of `D`
572
  can result in the different declarations having distinct types, and
573
  *lambda-expression*s appearing in a default argument of `D` might still
574
  denote different types in different translation units. — *end note*]
575
 
576
- [*Example 6*:
577
 
578
  ``` cpp
579
  inline void f(bool cond, void (*p)()) {
580
  if (cond) f(false, []{});
581
  }
@@ -612,17 +708,17 @@ diagnostic required.
612
  ### General <a id="basic.scope.scope">[[basic.scope.scope]]</a>
613
 
614
  The declarations in a program appear in a number of *scopes* that are in
615
  general discontiguous. The *global scope* contains the entire program;
616
  every other scope S is introduced by a declaration,
617
- *parameter-declaration-clause*, *statement*, or *handler* (as described
618
- in the following subclauses of [[basic.scope]]) appearing in another
619
- scope which thereby contains S. An *enclosing scope* at a program point
620
- is any scope that contains it; the smallest such scope is said to be the
621
- *immediate scope* at that point. A scope *intervenes* between a program
622
- point P and a scope S (that does not contain P) if it is or contains S
623
- but does not contain P.
624
 
625
  Unless otherwise specified:
626
 
627
  - The smallest scope that contains a scope S is the *parent scope* of S.
628
  - No two declarations (re)introduce the same entity.
@@ -630,12 +726,13 @@ Unless otherwise specified:
630
  [[basic.scope.pdecl]].
631
  - A declaration’s *target scope* is the scope it inhabits.
632
  - Any names (re)introduced by a declaration are *bound* to it in its
633
  target scope.
634
 
635
- An entity *belongs* to a scope S if S is the target scope of a
636
- declaration of the entity.
 
637
 
638
  [*Note 1*:
639
 
640
  Special cases include that:
641
 
@@ -643,35 +740,36 @@ Special cases include that:
643
  scopes [[basic.scope.temp]].
644
  - Corresponding declarations with appropriate linkage declare the same
645
  entity [[basic.link]].
646
  - The declaration in a *template-declaration* inhabits the same scope as
647
  the *template-declaration*.
648
- - Friend declarations and declarations of qualified names and template
649
- specializations do not bind names [[dcl.meaning]]; those with
650
- qualified names target a specified scope, and other friend
651
- declarations and certain *elaborated-type-specifier*s
652
- [[dcl.type.elab]] target a larger enclosing scope.
653
- - Block-scope extern declarations target a larger enclosing scope but
654
- bind a name in their immediate scope.
 
655
  - The names of unscoped enumerators are bound in the two innermost
656
  enclosing scopes [[dcl.enum]].
657
  - A class’s name is also bound in its own scope [[class.pre]].
658
  - The names of the members of an anonymous union are bound in the
659
  union’s parent scope [[class.union.anon]].
660
 
661
  — *end note*]
662
 
663
  Two non-static member functions have *corresponding object parameters*
664
- if:
665
 
666
  - exactly one is an implicit object member function with no
667
  *ref-qualifier* and the types of their object parameters [[dcl.fct]],
668
- after removing top-level references, are the same, or
669
  - their object parameters have the same type.
670
 
671
  Two non-static member function templates have *corresponding object
672
- parameters* if:
673
 
674
  - exactly one is an implicit object member function with no
675
  *ref-qualifier* and the types of their object parameters, after
676
  removing any references, are equivalent, or
677
  - the types of their object parameters are equivalent.
@@ -684,22 +782,26 @@ are non-static members, they have corresponding object parameters.
684
 
685
  Two declarations *correspond* if they (re)introduce the same name, both
686
  declare constructors, or both declare destructors, unless
687
 
688
  - either is a *using-declarator*, or
689
- - one declares a type (not a *typedef-name*) and the other declares a
690
  variable, non-static data member other than of an anonymous union
691
  [[class.union.anon]], enumerator, function, or function template, or
692
- - each declares a function or function template, except when
 
 
 
 
 
693
  - both declare functions with the same
694
  non-object-parameter-type-list,[^3] equivalent [[temp.over.link]]
695
  trailing *requires-clause*s (if any, except as specified in
696
  [[temp.friend]]), and, if both are non-static members, they have
697
  corresponding object parameters, or
698
  - both declare function templates with corresponding signatures and
699
- equivalent *template-head*s and trailing *requires-clause*s (if
700
- any).
701
 
702
  [*Note 2*:
703
 
704
  Declarations can correspond even if neither binds a name.
705
 
@@ -743,17 +845,34 @@ struct X {
743
  };
744
  ```
745
 
746
  — *end example*]
747
 
 
 
 
 
 
 
 
 
 
 
 
 
 
748
  Two declarations *potentially conflict* if they correspond and cause
749
  their shared name to denote different entities [[basic.link]]. The
750
  program is ill-formed if, in any scope, a name is bound to two
751
- declarations that potentially conflict and one precedes the other
752
- [[basic.lookup]].
753
 
754
- [*Note 3*: Overload resolution can consider potentially conflicting
 
 
 
 
755
  declarations found in multiple scopes (e.g., via *using-directive*s or
756
  for operator functions), in which case it is often
757
  ambiguous. — *end note*]
758
 
759
  [*Example 3*:
@@ -769,10 +888,22 @@ namespace A {}
769
  namespace B = A;
770
  namespace B = A; // OK, no effect
771
  namespace B = B; // OK, no effect
772
  namespace A = B; // OK, no effect
773
  namespace B {} // error: different entity for B
 
 
 
 
 
 
 
 
 
 
 
 
774
  ```
775
 
776
  — *end example*]
777
 
778
  A declaration is *nominable* in a class, class template, or namespace E
@@ -895,11 +1026,13 @@ variable [[dcl.fct.def.general]] is immediately before the
895
  The locus of the declaration of a structured binding [[dcl.struct.bind]]
896
  is immediately after the *identifier-list* of the structured binding
897
  declaration.
898
 
899
  The locus of a *for-range-declaration* of a range-based `for` statement
900
- [[stmt.ranged]] is immediately after the *for-range-initializer*.
 
 
901
 
902
  The locus of a *template-parameter* is immediately after it.
903
 
904
  [*Example 5*:
905
 
@@ -911,12 +1044,15 @@ template<class T
911
  N = 0> struct A { };
912
  ```
913
 
914
  — *end example*]
915
 
 
 
 
916
  The locus of a *concept-definition* is immediately after its
917
- concept-name [[temp.concept]].
918
 
919
  [*Note 3*: The *constraint-expression* cannot use the
920
  *concept-name*. — *end note*]
921
 
922
  The locus of a *namespace-definition* with an *identifier* is
@@ -937,11 +1073,12 @@ but they do not bind names in it. — *end note*]
937
 
938
  ### Block scope <a id="basic.scope.block">[[basic.scope.block]]</a>
939
 
940
  Each
941
 
942
- - selection or iteration statement [[stmt.select]], [[stmt.iter]],
 
943
  - substatement of such a statement,
944
  - *handler* [[except.pre]], or
945
  - compound statement [[stmt.block]] that is not the *compound-statement*
946
  of a *handler*
947
 
@@ -964,11 +1101,12 @@ for (int i = 0; i < 10; i++)
964
  int j = i; // j = 42
965
  ```
966
 
967
  — *end example*]
968
 
969
- If a declaration whose target scope is the block scope S of a
 
970
 
971
  - *compound-statement* of a *lambda-expression*, *function-body*, or
972
  *function-try-block*,
973
  - substatement of a selection or iteration statement that is not itself
974
  a selection or iteration statement, or
@@ -1010,11 +1148,11 @@ A *parameter-declaration-clause* P introduces a
1010
  parameter scope is nested within its class’s scope. — *end note*]
1011
  - If P is associated with a *lambda-declarator*, its scope extends to
1012
  the end of the *compound-statement* in the *lambda-expression*.
1013
  - If P is associated with a *requirement-parameter-list*, its scope
1014
  extends to the end of the *requirement-body* of the
1015
- requires-expression.
1016
  - If P is associated with a *deduction-guide*, its scope extends to the
1017
  end of the *deduction-guide*.
1018
 
1019
  ### Lambda scope <a id="basic.scope.lambda">[[basic.scope.lambda]]</a>
1020
 
@@ -1081,13 +1219,13 @@ Any declaration of an enumeration E introduces an *enumeration scope*
1081
  that includes the *enumerator-list* of the *enum-specifier* for E (if
1082
  any).
1083
 
1084
  ### Template parameter scope <a id="basic.scope.temp">[[basic.scope.temp]]</a>
1085
 
1086
- Each template *template-parameter* introduces a
1087
- *template parameter scope* that includes the *template-head* of the
1088
- *template-parameter*.
1089
 
1090
  Each *template-declaration* D introduces a template parameter scope that
1091
  extends from the beginning of its *template-parameter-list* to the end
1092
  of the *template-declaration*. Any declaration outside the
1093
  *template-parameter-list* that would inhabit that scope instead inhabits
@@ -1097,19 +1235,35 @@ not a template parameter scope.
1097
 
1098
  [*Note 1*: Therefore, only template parameters belong to a template
1099
  parameter scope, and only template parameter scopes have a template
1100
  parameter scope as a parent scope. — *end note*]
1101
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1102
  ## Name lookup <a id="basic.lookup">[[basic.lookup]]</a>
1103
 
1104
  ### General <a id="basic.lookup.general">[[basic.lookup.general]]</a>
1105
 
1106
- The name lookup rules apply uniformly to all names (including
1107
- *typedef-name*s [[dcl.typedef]], *namespace-name*s [[basic.namespace]],
1108
- and *class-name*s [[class.name]]) wherever the grammar allows such names
1109
- in the context discussed by a particular rule. Name lookup associates
1110
- the use of a name with a set of declarations [[basic.def]] of that name.
1111
  Unless otherwise specified, the program is ill-formed if no declarations
1112
  are found. If the declarations found by name lookup all denote functions
1113
  or function templates, the declarations are said to form an *overload
1114
  set*. Otherwise, if the declarations found by name lookup do not all
1115
  denote the same entity, they are *ambiguous* and the program is
@@ -1182,18 +1336,18 @@ the *using-declarator* [[namespace.udecl]].
1182
 
1183
  In certain contexts, only certain kinds of declarations are included.
1184
  After any such restriction, any declarations of classes or enumerations
1185
  are discarded if any other declarations are found.
1186
 
1187
- [*Note 4*: A type (but not a *typedef-name* or template) is therefore
1188
  hidden by any other entity in its scope. — *end note*]
1189
 
1190
  However, if a lookup is *type-only*, only declarations of types and
1191
  templates whose specializations are types are considered; furthermore,
1192
- if declarations of a *typedef-name* and of the type to which it refers
1193
- are found, the declaration of the *typedef-name* is discarded instead of
1194
- the type declaration.
1195
 
1196
  ### Member name lookup <a id="class.member.lookup">[[class.member.lookup]]</a>
1197
 
1198
  A *search* in a scope X for a name M from a program point P is a single
1199
  search in X for M from P unless X is the scope of a class or class
@@ -1535,11 +1689,11 @@ name in the *unqualified-id* does not find any
1535
  - function declaration inhabiting a block scope, or
1536
  - declaration not of a function or function template
1537
 
1538
  then lookup for the name also includes the result of
1539
  *argument-dependent lookup* in a set of associated namespaces that
1540
- depends on the types of the arguments (and for template template
1541
  arguments, the namespace of the template argument), as specified below.
1542
 
1543
  [*Example 1*:
1544
 
1545
  ``` cpp
@@ -1601,26 +1755,34 @@ lookup does not apply and the friend function `f` is not found.
1601
 
1602
  — *end note*]
1603
 
1604
  For each argument type `T` in the function call, there is a set of zero
1605
  or more *associated entities* to be considered. The set of entities is
1606
- determined entirely by the types of the function arguments (and any
1607
  template template arguments). Any *typedef-name*s and
1608
  *using-declaration*s used to specify the types do not contribute to this
1609
  set. The set of entities is determined in the following way:
1610
 
1611
- - If `T` is a fundamental type, its associated set of entities is empty.
 
 
 
 
 
 
 
1612
  - If `T` is a class type (including unions), its associated entities
1613
- are: the class itself; the class of which it is a member, if any; and
1614
- its direct and indirect base classes. Furthermore, if `T` is a class
1615
- template specialization, its associated entities also include: the
1616
- entities associated with the types of the template arguments provided
1617
- for template type parameters; the templates used as template template
1618
- arguments; and the classes of which any member templates used as
1619
- template template arguments are members. \[*Note 2*: Non-type template
1620
- arguments do not contribute to the set of associated
1621
- entities. *end note*]
 
1622
  - If `T` is an enumeration type, its associated entities are `T` and, if
1623
  it is a class member, the member’s class.
1624
  - If `T` is a pointer to `U` or an array of `U`, its associated entities
1625
  are those associated with `U`.
1626
  - If `T` is a function type, its associated entities are those
@@ -1636,12 +1798,12 @@ set. The set of entities is determined in the following way:
1636
  In addition, if the argument is an overload set or the address of such a
1637
  set, its associated entities are the union of those associated with each
1638
  of the members of the set, i.e., the entities associated with its
1639
  parameter types and return type. Additionally, if the aforementioned
1640
  overload set is named with a *template-id*, its associated entities also
1641
- include its template *template-argument*s and those associated with its
1642
- type *template-argument*s.
1643
 
1644
  The *associated namespaces* for a call are the innermost enclosing
1645
  non-inline namespaces for its associated entities as well as every
1646
  element of the inline namespace set [[namespace.def]] of those
1647
  namespaces. Argument-dependent lookup finds all declarations of
@@ -1710,11 +1872,11 @@ void test() {
1710
  }
1711
  ```
1712
 
1713
  — *end example*]
1714
 
1715
- [*Note 3*: The associated namespace can include namespaces already
1716
  considered by ordinary unqualified lookup. — *end note*]
1717
 
1718
  [*Example 3*:
1719
 
1720
  ``` cpp
@@ -1738,14 +1900,15 @@ int main() {
1738
 
1739
  #### General <a id="basic.lookup.qual.general">[[basic.lookup.qual.general]]</a>
1740
 
1741
  Lookup of an *identifier* followed by a `::` scope resolution operator
1742
  considers only namespaces, types, and templates whose specializations
1743
- are types. If a name, *template-id*, or *decltype-specifier* is followed
1744
- by a `::`, it shall designate a namespace, class, enumeration, or
1745
- dependent type, and the `::` is never interpreted as a complete
1746
- *nested-name-specifier*.
 
1747
 
1748
  [*Example 1*:
1749
 
1750
  ``` cpp
1751
  class A {
@@ -1782,13 +1945,13 @@ A *qualified name* is
1782
  - the terminal name of
1783
  - a *qualified-id*,
1784
  - a *using-declarator*,
1785
  - a *typename-specifier*,
1786
  - a *qualified-namespace-specifier*, or
1787
- - a *nested-name-specifier*, *elaborated-type-specifier*, or
1788
- *class-or-decltype* that has a *nested-name-specifier*
1789
- [[expr.prim.id.qual]].
1790
 
1791
  The *lookup context* of a member-qualified name is the type of its
1792
  associated object expression (considered dependent if the object
1793
  expression is type-dependent). The lookup context of any other qualified
1794
  name is the type, template, or namespace nominated by the preceding
@@ -2151,37 +2314,88 @@ struct Base::Data* pBase; // OK, refers to nested Data
2151
 
2152
  In a *using-directive* or *namespace-alias-definition*, during the
2153
  lookup for a *namespace-name* or for a name in a *nested-name-specifier*
2154
  only namespace names are considered.
2155
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2156
  ## Program and linkage <a id="basic.link">[[basic.link]]</a>
2157
 
2158
- A *program* consists of one or more translation units [[lex.separate]]
2159
  linked together. A translation unit consists of a sequence of
2160
  declarations.
2161
 
2162
  ``` bnf
2163
  translation-unit:
2164
  declaration-seqₒₚₜ
2165
  global-module-fragmentₒₚₜ module-declaration declaration-seqₒₚₜ private-module-fragmentₒₚₜ
2166
  ```
2167
 
2168
- A name is said to have *linkage* when it can denote the same object,
2169
- reference, function, type, template, namespace or value as a name
2170
- introduced by a declaration in another scope:
2171
 
2172
- - When a name has *external linkage*, the entity it denotes can be
2173
- referred to by names from scopes of other translation units or from
2174
- other scopes of the same translation unit.
2175
- - When a name has *module linkage*, the entity it denotes can be
2176
- referred to by names from other scopes of the same module unit
2177
- [[module.unit]] or from scopes of other module units of that same
2178
- module.
2179
- - When a name has *internal linkage*, the entity it denotes can be
2180
- referred to by names from other scopes in the same translation unit.
2181
- - When a name has *no linkage*, the entity it denotes cannot be referred
2182
- to by names from other scopes.
2183
 
2184
  The name of an entity that belongs to a namespace scope
2185
  [[basic.scope.namespace]] has internal linkage if it is the name of
2186
 
2187
  - a variable, variable template, function, or function template that is
@@ -2193,18 +2407,18 @@ The name of an entity that belongs to a namespace scope
2193
  - it is inline, or
2194
  - it was previously declared and the prior declaration did not have
2195
  internal linkage; or
2196
  - a data member of an anonymous union.
2197
 
2198
- [*Note 1*: An instantiated variable template that has const-qualified
2199
  type can have external or module linkage, even if not declared
2200
  `extern`. — *end note*]
2201
 
2202
  An unnamed namespace or a namespace declared directly or indirectly
2203
  within an unnamed namespace has internal linkage. All other namespaces
2204
  have external linkage. The name of an entity that belongs to a namespace
2205
- scope that has not been given internal linkage above and that is the
2206
  name of
2207
 
2208
  - a variable; or
2209
  - a function; or
2210
  - a named class [[class.pre]], or an unnamed class defined in a typedef
@@ -2217,12 +2431,21 @@ name of
2217
  purposes [[dcl.enum]]; or
2218
  - a template
2219
 
2220
  has its linkage determined as follows:
2221
 
2222
- - if the enclosing namespace has internal linkage, the name has internal
2223
- linkage;
 
 
 
 
 
 
 
 
 
2224
  - otherwise, if the declaration of the name is attached to a named
2225
  module [[module.unit]] and is not exported [[module.interface]], the
2226
  name has module linkage;
2227
  - otherwise, the name has external linkage.
2228
 
@@ -2263,26 +2486,29 @@ linkage.
2263
 
2264
  Two declarations of entities declare the same entity if, considering
2265
  declarations of unnamed types to introduce their names for linkage
2266
  purposes, if any [[dcl.typedef]], [[dcl.enum]], they correspond
2267
  [[basic.scope.scope]], have the same target scope that is not a function
2268
- or template parameter scope, and either
 
2269
 
2270
  - they appear in the same translation unit, or
 
 
2271
  - they both declare names with module linkage and are attached to the
2272
  same module, or
2273
  - they both declare names with external linkage.
2274
 
2275
- [*Note 2*: There are other circumstances in which declarations declare
2276
  the same entity
2277
  [[dcl.link]], [[temp.type]], [[temp.spec.partial]]. — *end note*]
2278
 
2279
  If a declaration H that declares a name with internal linkage precedes a
2280
  declaration D in another translation unit U and would declare the same
2281
  entity as D if it appeared in U, the program is ill-formed.
2282
 
2283
- [*Note 3*: Such an H can appear only in a header unit. — *end note*]
2284
 
2285
  If two declarations of an entity are attached to different modules, the
2286
  program is ill-formed; no diagnostic is required if neither is reachable
2287
  from the other.
2288
 
@@ -2329,11 +2555,11 @@ For any two declarations of an entity E:
2329
  - If one declares E to be a namespace, the other shall do so.
2330
  - If one declares E to be a type, the other shall declare E to be a type
2331
  of the same kind [[dcl.type.elab]].
2332
  - If one declares E to be a class template, the other shall do so with
2333
  the same kind and an equivalent *template-head* [[temp.over.link]].
2334
- \[*Note 4*: The declarations can supply different default template
2335
  arguments. — *end note*]
2336
  - If one declares E to be a function template or a (partial
2337
  specialization of a) variable template, the other shall declare E to
2338
  be one with an equivalent *template-head* and type.
2339
  - If one declares E to be an alias template, the other shall declare E
@@ -2357,22 +2583,27 @@ void h(); // #2
2357
  namespace h {} // error: same entity as #2, but not a function
2358
  ```
2359
 
2360
  — *end example*]
2361
 
2362
- [*Note 5*: Linkage to non-C++ declarations can be achieved using a
2363
  *linkage-specification* [[dcl.link]]. — *end note*]
2364
 
2365
  A declaration D *names* an entity E if
2366
 
2367
  - D contains a *lambda-expression* whose closure type is E,
 
 
 
 
 
2368
  - E is not a function or function template and D contains an
2369
  *id-expression*, *type-specifier*, *nested-name-specifier*,
2370
  *template-name*, or *concept-name* denoting E, or
2371
  - E is a function or function template and D contains an expression that
2372
  names E [[basic.def.odr]] or an *id-expression* that refers to a set
2373
- of overloads that contains E. \[*Note 6*: Non-dependent names in an
2374
  instantiated declaration do not refer to a set of overloads
2375
  [[temp.res]]. — *end note*]
2376
 
2377
  A declaration is an *exposure* if it either names a TU-local entity
2378
  (defined below), ignoring
@@ -2389,38 +2620,46 @@ A declaration is an *exposure* if it either names a TU-local entity
2389
  not an odr-use [[term.odr.use]],
2390
 
2391
  or defines a constexpr variable initialized to a TU-local value (defined
2392
  below).
2393
 
2394
- [*Note 7*: An inline function template can be an exposure even though
2395
  certain explicit specializations of it would be usable in other
2396
  translation units. — *end note*]
2397
 
2398
  An entity is *TU-local* if it is
2399
 
2400
- - a type, function, variable, or template that
 
2401
  - has a name with internal linkage, or
2402
  - does not have a name with linkage and is declared, or introduced by
2403
  a *lambda-expression*, within the definition of a TU-local entity,
2404
  - a type with no name that is defined outside a *class-specifier*,
2405
  function body, or *initializer* or is introduced by a
2406
  *defining-type-specifier* that is used to declare only TU-local
2407
  entities,
2408
  - a specialization of a TU-local template,
2409
  - a specialization of a template with any TU-local template argument, or
2410
  - a specialization of a template whose (possibly instantiated)
2411
- declaration is an exposure. \[*Note 8*: A specialization can be
2412
  produced by implicit or explicit instantiation. — *end note*]
2413
 
2414
  A value or object is *TU-local* if either
2415
 
 
2416
  - it is, or is a pointer to, a TU-local function or the object
2417
- associated with a TU-local variable, or
2418
  - it is an object of class or array type and any of its subobjects or
2419
  any of the objects or functions to which its non-static data members
2420
  of reference type refer is TU-local and is usable in constant
2421
- expressions.
 
 
 
 
 
 
2422
 
2423
  If a (possibly instantiated) declaration of, or a deduction guide for, a
2424
  non-TU-local entity in a module interface unit (outside the
2425
  *private-module-fragment*, if any) or module partition [[module.unit]]
2426
  is an exposure, the program is ill-formed. Such a declaration in any
@@ -2463,10 +2702,20 @@ namespace N {
2463
  static void adl(int);
2464
  }
2465
  void adl(double);
2466
 
2467
  inline void h(auto x) { adl(x); } // OK, but certain specializations are exposures
 
 
 
 
 
 
 
 
 
 
2468
  ```
2469
 
2470
  Translation unit #2
2471
 
2472
  ``` cpp
@@ -2489,27 +2738,23 @@ void other() {
2489
  ### Memory model <a id="intro.memory">[[intro.memory]]</a>
2490
 
2491
  The fundamental storage unit in the C++ memory model is the *byte*. A
2492
  byte is at least large enough to contain the ordinary literal encoding
2493
  of any element of the basic literal character set [[lex.charset]] and
2494
- the eight-bit code units of the Unicode[^5]
 
2495
 
2496
- UTF-8 encoding form and is composed of a contiguous sequence of
2497
- bits,[^6]
2498
-
2499
- the number of which is *implementation-defined*. The least significant
2500
- bit is called the *low-order bit*; the most significant bit is called
2501
- the *high-order bit*. The memory available to a C++ program consists of
2502
- one or more sequences of contiguous bytes. Every byte has a unique
2503
- address.
2504
 
2505
  [*Note 1*: The representation of types is described in 
2506
  [[basic.types.general]]. — *end note*]
2507
 
2508
- A *memory location* is either an object of scalar type that is not a
2509
- bit-field or a maximal sequence of adjacent bit-fields all having
2510
- nonzero width.
2511
 
2512
  [*Note 2*: Various features of the language, such as references and
2513
  virtual functions, might involve additional memory locations that are
2514
  not accessible to programs but are managed by the
2515
  implementation. — *end note*]
@@ -2580,21 +2825,21 @@ Objects can contain other objects, called *subobjects*. A subobject can
2580
  be a *member subobject* [[class.mem]], a *base class subobject*
2581
  [[class.derived]], or an array element. An object that is not a
2582
  subobject of any other object is called a *complete object*. If an
2583
  object is created in storage associated with a member subobject or array
2584
  element *e* (which may or may not be within its lifetime), the created
2585
- object is a subobject of *e*’s containing object if:
2586
 
2587
  - the lifetime of *e*’s containing object has begun and not ended, and
2588
  - the storage for the new object exactly overlays the storage location
2589
  associated with *e*, and
2590
  - the new object is of the same type as *e* (ignoring cv-qualification).
2591
 
2592
  If a complete object is created [[expr.new]] in storage associated with
2593
  another object *e* of type “array of N `unsigned char`” or of type
2594
  “array of N `std::byte`” [[cstddef.syn]], that array *provides storage*
2595
- for the created object if:
2596
 
2597
  - the lifetime of *e* has begun and not ended, and
2598
  - the storage for the new object fits entirely within *e*, and
2599
  - there is no array object that satisfies these constraints nested
2600
  within *e*.
@@ -2604,10 +2849,12 @@ another object, the lifetime of that object ends because its storage was
2604
  reused [[basic.life]]. — *end note*]
2605
 
2606
  [*Example 1*:
2607
 
2608
  ``` cpp
 
 
2609
  template<typename ...T>
2610
  struct AlignedUnion {
2611
  alignas(T...) unsigned char data[max(sizeof(T)...)];
2612
  };
2613
  int f() {
@@ -2618,20 +2865,20 @@ int f() {
2618
  return *c + *d; // OK
2619
  }
2620
 
2621
  struct A { unsigned char a[32]; };
2622
  struct B { unsigned char b[16]; };
2623
- A a;
2624
  B *b = new (a.a + 8) B; // a.a provides storage for *b
2625
  int *p = new (b->b + 4) int; // b->b provides storage for *p
2626
  // a.a does not provide storage for *p (directly),
2627
  // but *p is nested within a (see below)
2628
  ```
2629
 
2630
  — *end example*]
2631
 
2632
- An object *a* is *nested within* another object *b* if:
2633
 
2634
  - *a* is a subobject of *b*, or
2635
  - *b* provides storage for *a*, or
2636
  - there exists an object *c* where *a* is nested within *c*, and *c* is
2637
  nested within *b*.
@@ -2672,23 +2919,45 @@ the circumstances under which the object has zero size are
2672
  object with nonzero size shall occupy one or more bytes of storage,
2673
  including every byte that is occupied in full or in part by any of its
2674
  subobjects. An object of trivially copyable or standard-layout type
2675
  [[basic.types.general]] shall occupy contiguous bytes of storage.
2676
 
 
 
 
 
 
 
 
 
2677
  Unless an object is a bit-field or a subobject of zero size, the address
2678
  of that object is the address of the first byte it occupies. Two objects
2679
  with overlapping lifetimes that are not bit-fields may have the same
2680
- address if one is nested within the other, or if at least one is a
2681
- subobject of zero size and they are of different types; otherwise, they
2682
- have distinct addresses and occupy disjoint bytes of storage.[^7]
 
 
 
 
 
 
2683
 
2684
  [*Example 2*:
2685
 
2686
  ``` cpp
2687
  static const char test1 = 'x';
2688
  static const char test2 = 'x';
2689
  const bool b = &test1 != &test2; // always true
 
 
 
 
 
 
 
 
2690
  ```
2691
 
2692
  — *end example*]
2693
 
2694
  The address of a non-bit-field subobject of zero size is the address of
@@ -2697,16 +2966,16 @@ subobject.
2697
 
2698
  Some operations are described as *implicitly creating objects* within a
2699
  specified region of storage. For each operation that is specified as
2700
  implicitly creating objects, that operation implicitly creates and
2701
  starts the lifetime of zero or more objects of implicit-lifetime types
2702
- [[basic.types.general]] in its specified region of storage if doing so
2703
- would result in the program having defined behavior. If no such set of
2704
- objects would give the program defined behavior, the behavior of the
2705
- program is undefined. If multiple such sets of objects would give the
2706
- program defined behavior, it is unspecified which such set of objects is
2707
- created.
2708
 
2709
  [*Note 4*: Such operations do not start the lifetimes of subobjects of
2710
  such objects that are not themselves of implicit-lifetime
2711
  types. — *end note*]
2712
 
@@ -2739,32 +3008,123 @@ X *make_x() {
2739
  }
2740
  ```
2741
 
2742
  — *end example*]
2743
 
2744
- An operation that begins the lifetime of an array of `unsigned char` or
2745
- `std::byte` implicitly creates objects within the region of storage
2746
- occupied by the array.
2747
 
2748
  [*Note 5*: The array object provides storage for these
2749
  objects. — *end note*]
2750
 
2751
- Any implicit or explicit invocation of a function named `operator new`
2752
- or `operator new[]` implicitly creates objects in the returned region of
2753
- storage and returns a pointer to a suitable created object.
 
2754
 
2755
  [*Note 6*: Some functions in the C++ standard library implicitly create
2756
  objects
2757
- [[obj.lifetime]], [[allocator.traits.members]], [[c.malloc]], [[cstring.syn]], [[bit.cast]]. — *end note*]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2758
 
2759
  ### Lifetime <a id="basic.life">[[basic.life]]</a>
2760
 
 
 
 
2761
  The *lifetime* of an object or reference is a runtime property of the
2762
  object or reference. A variable is said to have *vacuous initialization*
2763
- if it is default-initialized and, if it is of class type or a (possibly
2764
- multidimensional) array thereof, that class type has a trivial default
2765
- constructor. The lifetime of an object of type `T` begins when:
 
 
2766
 
2767
  - storage with the proper alignment and size for type `T` is obtained,
2768
  and
2769
  - its initialization (if any) is complete (including vacuous
2770
  initialization) [[dcl.init]],
@@ -2779,10 +3139,29 @@ except as described in [[allocator.members]]. The lifetime of an object
2779
  - if `T` is a non-class type, the object is destroyed, or
2780
  - if `T` is a class type, the destructor call starts, or
2781
  - the storage which the object occupies is released, or is reused by an
2782
  object that is not nested within *o* [[intro.object]].
2783
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2784
  The lifetime of a reference begins when its initialization is complete.
2785
  The lifetime of a reference ends as if it were a scalar object requiring
2786
  storage.
2787
 
2788
  [*Note 1*: [[class.base.init]] describes the lifetime of base and
@@ -2811,22 +3190,22 @@ In this case, the destructor is not implicitly invoked.
2811
 
2812
  [*Note 4*: The correct behavior of a program often depends on the
2813
  destructor being invoked for each object of class type. — *end note*]
2814
 
2815
  Before the lifetime of an object has started but after the storage which
2816
- the object will occupy has been allocated[^8]
2817
 
2818
- or, after the lifetime of an object has ended and before the storage
2819
  which the object occupied is reused or released, any pointer that
2820
  represents the address of the storage location where the object will be
2821
  or was located may be used but only in limited ways. For an object under
2822
  construction or destruction, see  [[class.cdtor]]. Otherwise, such a
2823
  pointer refers to allocated storage [[basic.stc.dynamic.allocation]],
2824
  and using the pointer as if the pointer were of type `void*` is
2825
  well-defined. Indirection through such a pointer is permitted but the
2826
  resulting lvalue may only be used in limited ways, as described below.
2827
- The program has undefined behavior if:
2828
 
2829
  - the pointer is used as the operand of a *delete-expression*,
2830
  - the pointer is used to access a non-static data member or call a
2831
  non-static member function of the object, or
2832
  - the pointer is implicitly converted [[conv.ptr]] to a pointer to a
@@ -2836,11 +3215,11 @@ The program has undefined behavior if:
2836
  cv `void`, or to pointer to cv `void` and subsequently to pointer to
2837
  cv `char`, cv `unsigned char`, or cv `std::byte` [[cstddef.syn]], or
2838
  - the pointer is used as the operand of a `dynamic_cast`
2839
  [[expr.dynamic.cast]].
2840
 
2841
- [*Example 1*:
2842
 
2843
  ``` cpp
2844
  #include <cstdlib>
2845
 
2846
  struct B {
@@ -2869,36 +3248,32 @@ void g() {
2869
  ```
2870
 
2871
  — *end example*]
2872
 
2873
  Similarly, before the lifetime of an object has started but after the
2874
- storage which the object will occupy has been allocated or, after the
2875
  lifetime of an object has ended and before the storage which the object
2876
  occupied is reused or released, any glvalue that refers to the original
2877
  object may be used but only in limited ways. For an object under
2878
  construction or destruction, see  [[class.cdtor]]. Otherwise, such a
2879
  glvalue refers to allocated storage [[basic.stc.dynamic.allocation]],
2880
  and using the properties of the glvalue that do not depend on its value
2881
- is well-defined. The program has undefined behavior if:
2882
 
2883
  - the glvalue is used to access the object, or
2884
  - the glvalue is used to call a non-static member function of the
2885
  object, or
2886
  - the glvalue is bound to a reference to a virtual base class
2887
  [[dcl.init.ref]], or
2888
  - the glvalue is used as the operand of a `dynamic_cast`
2889
  [[expr.dynamic.cast]] or as the operand of `typeid`.
2890
 
2891
- If, after the lifetime of an object has ended and before the storage
2892
- which the object occupied is reused or released, a new object is created
2893
- at the storage location which the original object occupied, a pointer
2894
- that pointed to the original object, a reference that referred to the
2895
- original object, or the name of the original object will automatically
2896
- refer to the new object and, once the lifetime of the new object has
2897
- started, can be used to manipulate the new object, if the original
2898
- object is transparently replaceable (see below) by the new object. An
2899
- object o₁ is *transparently replaceable* by an object o₂ if:
2900
 
2901
  - the storage that o₂ occupies exactly overlays the storage that o₁
2902
  occupied, and
2903
  - o₁ and o₂ are of the same type (ignoring the top-level cv-qualifiers),
2904
  and
@@ -2907,11 +3282,20 @@ object o₁ is *transparently replaceable* by an object o₂ if:
2907
  [[intro.object]], and
2908
  - either o₁ and o₂ are both complete objects, or o₁ and o₂ are direct
2909
  subobjects of objects p₁ and p₂, respectively, and p₁ is transparently
2910
  replaceable by p₂.
2911
 
2912
- [*Example 2*:
 
 
 
 
 
 
 
 
 
2913
 
2914
  ``` cpp
2915
  struct C {
2916
  int i;
2917
  void f();
@@ -2933,25 +3317,25 @@ c1 = c2; // well-defined
2933
  c1.f(); // well-defined; c1 refers to a new object of type C
2934
  ```
2935
 
2936
  — *end example*]
2937
 
2938
- [*Note 5*: If these conditions are not met, a pointer to the new object
2939
  can be obtained from a pointer that represents the address of its
2940
  storage by calling `std::launder` [[ptr.launder]]. — *end note*]
2941
 
2942
  If a program ends the lifetime of an object of type `T` with static
2943
  [[basic.stc.static]], thread [[basic.stc.thread]], or automatic
2944
  [[basic.stc.auto]] storage duration and if `T` has a non-trivial
2945
- destructor,[^9]
2946
 
2947
  and another object of the original type does not occupy that same
2948
  storage location when the implicit destructor call takes place, the
2949
  behavior of the program is undefined. This is true even if the block is
2950
  exited with an exception.
2951
 
2952
- [*Example 3*:
2953
 
2954
  ``` cpp
2955
  class T { };
2956
  struct B {
2957
  ~B();
@@ -2968,11 +3352,11 @@ void h() {
2968
  Creating a new object within the storage that a const, complete object
2969
  with static, thread, or automatic storage duration occupies, or within
2970
  the storage that such a const object used to occupy before its lifetime
2971
  ended, results in undefined behavior.
2972
 
2973
- [*Example 4*:
2974
 
2975
  ``` cpp
2976
  struct B {
2977
  B();
2978
  ~B();
@@ -2986,67 +3370,114 @@ void h() {
2986
  }
2987
  ```
2988
 
2989
  — *end example*]
2990
 
2991
- In this subclause, “before” and “after” refer to the “happens before”
2992
- relation [[intro.multithread]].
2993
-
2994
- [*Note 6*: Therefore, undefined behavior results if an object that is
2995
- being constructed in one thread is referenced from another thread
2996
- without adequate synchronization. — *end note*]
2997
-
2998
- ### Indeterminate values <a id="basic.indet">[[basic.indet]]</a>
2999
 
3000
  When storage for an object with automatic or dynamic storage duration is
3001
- obtained, the object has an *indeterminate value*, and if no
3002
- initialization is performed for the object, that object retains an
3003
- indeterminate value until that value is replaced [[expr.ass]].
3004
 
3005
- [*Note 1*: Objects with static or thread storage duration are
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3006
  zero-initialized, see  [[basic.start.static]]. — *end note*]
3007
 
3008
- If an indeterminate value is produced by an evaluation, the behavior is
3009
- undefined except in the following cases:
 
 
3010
 
3011
- - If an indeterminate value of unsigned ordinary character type
3012
- [[basic.fundamental]] or `std::byte` type [[cstddef.syn]] is produced
3013
- by the evaluation of:
3014
  - the second or third operand of a conditional expression
3015
  [[expr.cond]],
3016
  - the right operand of a comma expression [[expr.comma]],
3017
  - the operand of a cast or conversion
3018
  [[conv.integral]], [[expr.type.conv]], [[expr.static.cast]], [[expr.cast]]
3019
  to an unsigned ordinary character type or `std::byte` type
3020
  [[cstddef.syn]], or
3021
  - a discarded-value expression [[expr.context]],
3022
 
3023
- then the result of the operation is an indeterminate value.
3024
- - If an indeterminate value of unsigned ordinary character type or
3025
- `std::byte` type is produced by the evaluation of the right operand of
3026
- a simple assignment operator [[expr.ass]] whose first operand is an
3027
- lvalue of unsigned ordinary character type or `std::byte` type, an
3028
- indeterminate value replaces the value of the object referred to by
3029
- the left operand.
3030
- - If an indeterminate value of unsigned ordinary character type is
3031
- produced by the evaluation of the initialization expression when
3032
- initializing an object of unsigned ordinary character type, that
3033
- object is initialized to an indeterminate value.
 
 
 
3034
  - If an indeterminate value of unsigned ordinary character type or
3035
  `std::byte` type is produced by the evaluation of the initialization
3036
  expression when initializing an object of `std::byte` type, that
3037
- object is initialized to an indeterminate value.
 
 
 
 
 
 
3038
 
3039
  [*Example 1*:
3040
 
3041
  ``` cpp
3042
  int f(bool b) {
3043
- unsigned char c;
3044
- unsigned char d = c; // OK, d has an indeterminate value
3045
  int e = d; // undefined behavior
3046
  return b ? d : 0; // undefined behavior if b is true
3047
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3048
  ```
3049
 
3050
  — *end example*]
3051
 
3052
  ### Storage duration <a id="basic.stc">[[basic.stc]]</a>
@@ -3061,24 +3492,24 @@ object and is one of the following:
3061
  - static storage duration
3062
  - thread storage duration
3063
  - automatic storage duration
3064
  - dynamic storage duration
3065
 
 
 
 
 
3066
  Static, thread, and automatic storage durations are associated with
3067
- objects introduced by declarations [[basic.def]] and implicitly created
3068
- by the implementation [[class.temporary]]. The dynamic storage duration
3069
- is associated with objects created by a *new-expression* [[expr.new]].
 
3070
 
3071
  The storage duration categories apply to references as well.
3072
 
3073
- When the end of the duration of a region of storage is reached, the
3074
- values of all pointers representing the address of any part of that
3075
- region of storage become invalid pointer values [[basic.compound]].
3076
- Indirection through an invalid pointer value and passing an invalid
3077
- pointer value to a deallocation function have undefined behavior. Any
3078
- other use of an invalid pointer value has *implementation-defined*
3079
- behavior.[^10]
3080
 
3081
  #### Static storage duration <a id="basic.stc.static">[[basic.stc.static]]</a>
3082
 
3083
  All variables which
3084
 
@@ -3115,18 +3546,22 @@ specified in  [[basic.start.static]], [[basic.start.dynamic]], and
3115
  [[stmt.dcl]] and, if constructed, is destroyed on thread exit
3116
  [[basic.start.term]]. — *end note*]
3117
 
3118
  #### Automatic storage duration <a id="basic.stc.auto">[[basic.stc.auto]]</a>
3119
 
3120
- Variables that belong to a block or parameter scope and are not
3121
- explicitly declared `static`, `thread_local`, or `extern` have
3122
- *automatic storage duration*. The storage for these entities lasts until
3123
- the block in which they are created exits.
3124
 
3125
  [*Note 1*: These variables are initialized and destroyed as described
3126
  in  [[stmt.dcl]]. — *end note*]
3127
 
 
 
 
 
3128
  If a variable with automatic storage duration has initialization or a
3129
  destructor with side effects, an implementation shall not destroy it
3130
  before the end of its block nor eliminate it as an optimization, even if
3131
  it appears to be unused, except that a class object or its copy/move may
3132
  be eliminated as specified in  [[class.copy.elision]].
@@ -3147,29 +3582,25 @@ global *deallocation functions* `operator delete` and
3147
  [[new.delete.placement]] do not perform allocation or
3148
  deallocation. — *end note*]
3149
 
3150
  The library provides default definitions for the global allocation and
3151
  deallocation functions. Some global allocation and deallocation
3152
- functions are replaceable [[new.delete]]; these are attached to the
3153
- global module [[module.unit]]. A C++ program shall provide at most one
3154
- definition of a replaceable allocation or deallocation function. Any
3155
- such function definition replaces the default version provided in the
3156
- library [[replacement.functions]]. The following allocation and
3157
- deallocation functions [[support.dynamic]] are implicitly declared in
3158
- global scope in each translation unit of a program.
3159
 
3160
  ``` cpp
3161
- [[nodiscard]] void* operator new(std::size_t);
3162
- [[nodiscard]] void* operator new(std::size_t, std::align_val_t);
3163
 
3164
  void operator delete(void*) noexcept;
3165
  void operator delete(void*, std::size_t) noexcept;
3166
  void operator delete(void*, std::align_val_t) noexcept;
3167
  void operator delete(void*, std::size_t, std::align_val_t) noexcept;
3168
 
3169
- [[nodiscard]] void* operator new[](std::size_t);
3170
- [[nodiscard]] void* operator new[](std::size_t, std::align_val_t);
3171
 
3172
  void operator delete[](void*) noexcept;
3173
  void operator delete[](void*, std::size_t) noexcept;
3174
  void operator delete[](void*, std::align_val_t) noexcept;
3175
  void operator delete[](void*, std::size_t, std::align_val_t) noexcept;
@@ -3224,11 +3655,11 @@ from any previously returned value `p1`, unless that value `p1` was
3224
  subsequently passed to a replaceable deallocation function. Furthermore,
3225
  for the library allocation functions in  [[new.delete.single]] and 
3226
  [[new.delete.array]], `p0` represents the address of a block of storage
3227
  disjoint from the storage for any other object accessible to the caller.
3228
  The effect of indirecting through a pointer returned from a request for
3229
- zero size is undefined.[^11]
3230
 
3231
  For an allocation function other than a reserved placement allocation
3232
  function [[new.delete.placement]], the pointer returned on a successful
3233
  call shall represent the address of storage that is aligned as follows:
3234
 
@@ -3243,12 +3674,12 @@ call shall represent the address of storage that is aligned as follows:
3243
 
3244
  An allocation function that fails to allocate storage can invoke the
3245
  currently installed new-handler function [[new.handler]], if any.
3246
 
3247
  [*Note 3*: A program-supplied allocation function can obtain the
3248
- address of the currently installed `new_handler` using the
3249
- `std::get_new_handler` function [[get.new.handler]]. — *end note*]
3250
 
3251
  An allocation function that has a non-throwing exception specification
3252
  [[except.spec]] indicates failure by returning a null pointer value. Any
3253
  other allocation function never returns a null pointer value and
3254
  indicates failure only by throwing an exception [[except.throw]] of a
@@ -3263,11 +3694,13 @@ calls to the functions in the C++ standard library.
3263
 
3264
  [*Note 4*: In particular, a global allocation function is not called to
3265
  allocate storage for objects with static storage duration
3266
  [[basic.stc.static]], for objects or references with thread storage
3267
  duration [[basic.stc.thread]], for objects of type `std::type_info`
3268
- [[expr.typeid]], or for an exception object
 
 
3269
  [[except.throw]]. — *end note*]
3270
 
3271
  ##### Deallocation functions <a id="basic.stc.dynamic.deallocation">[[basic.stc.dynamic.deallocation]]</a>
3272
 
3273
  A deallocation function that is not a class member function shall belong
@@ -3287,11 +3720,11 @@ first parameter shall be `C*`; otherwise, the type of its first
3287
  parameter shall be `void*`. A deallocation function may have more than
3288
  one parameter. A *usual deallocation function* is a deallocation
3289
  function whose parameters after the first are
3290
 
3291
  - optionally, a parameter of type `std::destroying_delete_t`, then
3292
- - optionally, a parameter of type `std::size_t`,[^12] then
3293
  - optionally, a parameter of type `std::align_val_t`.
3294
 
3295
  A destroying operator delete shall be a usual deallocation function. A
3296
  deallocation function may be an instance of a function template. Neither
3297
  the first parameter nor the return type shall depend on a template
@@ -3308,129 +3741,41 @@ has no effect.
3308
  If the argument given to a deallocation function in the standard library
3309
  is a pointer that is not the null pointer value [[basic.compound]], the
3310
  deallocation function shall deallocate the storage referenced by the
3311
  pointer, ending the duration of the region of storage.
3312
 
3313
- #### Duration of subobjects <a id="basic.stc.inherit">[[basic.stc.inherit]]</a>
3314
-
3315
- The storage duration of subobjects and reference members is that of
3316
- their complete object [[intro.object]].
3317
-
3318
- ### Alignment <a id="basic.align">[[basic.align]]</a>
3319
-
3320
- Object types have *alignment requirements*
3321
- [[basic.fundamental]], [[basic.compound]] which place restrictions on
3322
- the addresses at which an object of that type may be allocated. An
3323
- *alignment* is an *implementation-defined* integer value representing
3324
- the number of bytes between successive addresses at which a given object
3325
- can be allocated. An object type imposes an alignment requirement on
3326
- every object of that type; stricter alignment can be requested using the
3327
- alignment specifier [[dcl.align]].
3328
-
3329
- A *fundamental alignment* is represented by an alignment less than or
3330
- equal to the greatest alignment supported by the implementation in all
3331
- contexts, which is equal to `alignof(std::max_align_t)`
3332
- [[support.types]]. The alignment required for a type may be different
3333
- when it is used as the type of a complete object and when it is used as
3334
- the type of a subobject.
3335
-
3336
- [*Example 1*:
3337
-
3338
- ``` cpp
3339
- struct B { long double d; };
3340
- struct D : virtual B { char c; };
3341
- ```
3342
-
3343
- When `D` is the type of a complete object, it will have a subobject of
3344
- type `B`, so it must be aligned appropriately for a `long double`. If
3345
- `D` appears as a subobject of another object that also has `B` as a
3346
- virtual base class, the `B` subobject might be part of a different
3347
- subobject, reducing the alignment requirements on the `D` subobject.
3348
-
3349
- — *end example*]
3350
-
3351
- The result of the `alignof` operator reflects the alignment requirement
3352
- of the type in the complete-object case.
3353
-
3354
- An *extended alignment* is represented by an alignment greater than
3355
- `alignof(std::max_align_t)`. It is *implementation-defined* whether any
3356
- extended alignments are supported and the contexts in which they are
3357
- supported [[dcl.align]]. A type having an extended alignment requirement
3358
- is an *over-aligned type*.
3359
-
3360
- [*Note 1*: Every over-aligned type is or contains a class type to which
3361
- extended alignment applies (possibly through a non-static data
3362
- member). — *end note*]
3363
-
3364
- A *new-extended alignment* is represented by an alignment greater than
3365
- `__STDCPP_DEFAULT_NEW_ALIGNMENT__` [[cpp.predefined]].
3366
-
3367
- Alignments are represented as values of the type `std::size_t`. Valid
3368
- alignments include only those values returned by an `alignof` expression
3369
- for the fundamental types plus an additional *implementation-defined*
3370
- set of values, which may be empty. Every alignment value shall be a
3371
- non-negative integral power of two.
3372
-
3373
- Alignments have an order from *weaker* to *stronger* or *stricter*
3374
- alignments. Stricter alignments have larger alignment values. An address
3375
- that satisfies an alignment requirement also satisfies any weaker valid
3376
- alignment requirement.
3377
-
3378
- The alignment requirement of a complete type can be queried using an
3379
- `alignof` expression [[expr.alignof]]. Furthermore, the narrow character
3380
- types [[basic.fundamental]] shall have the weakest alignment
3381
- requirement.
3382
-
3383
- [*Note 2*: This enables the ordinary character types to be used as the
3384
- underlying type for an aligned memory area [[dcl.align]]. — *end note*]
3385
-
3386
- Comparing alignments is meaningful and provides the obvious results:
3387
-
3388
- - Two alignments are equal when their numeric values are equal.
3389
- - Two alignments are different when their numeric values are not equal.
3390
- - When an alignment is larger than another it represents a stricter
3391
- alignment.
3392
-
3393
- [*Note 3*: The runtime pointer alignment function [[ptr.align]] can be
3394
- used to obtain an aligned pointer within a buffer; an
3395
- *alignment-specifier* [[dcl.align]] can be used to align storage
3396
- explicitly. — *end note*]
3397
-
3398
- If a request for a specific extended alignment in a specific context is
3399
- not supported by an implementation, the program is ill-formed.
3400
-
3401
  ### Temporary objects <a id="class.temporary">[[class.temporary]]</a>
3402
 
3403
- Temporary objects are created
3404
 
3405
- - when a prvalue is converted to an xvalue [[conv.rval]],
3406
  - when needed by the implementation to pass or return an object of
3407
- trivially copyable type (see below), and
3408
- - when throwing an exception [[except.throw]]. \[*Note 1*: The lifetime
3409
- of exception objects is described in  [[except.throw]]. — *end note*]
3410
 
3411
  Even when the creation of the temporary object is unevaluated
3412
  [[expr.context]], all the semantic restrictions shall be respected as if
3413
  the temporary object had been created and later destroyed.
3414
 
3415
- [*Note 2*: This includes accessibility [[class.access]] and whether it
3416
  is deleted, for the constructor selected and for the destructor.
3417
  However, in the special case of the operand of a *decltype-specifier*
3418
  [[dcl.type.decltype]], no temporary is introduced, so the foregoing does
3419
  not apply to such a prvalue. — *end note*]
3420
 
3421
  The materialization of a temporary object is generally delayed as long
3422
  as possible in order to avoid creating unnecessary temporary objects.
3423
 
3424
- [*Note 3*:
3425
 
3426
  Temporary objects are materialized:
3427
 
3428
  - when binding a reference to a prvalue
3429
  [[dcl.init.ref]], [[expr.type.conv]], [[expr.dynamic.cast]], [[expr.static.cast]], [[expr.const.cast]], [[expr.cast]],
3430
- - when performing member access on a class prvalue
3431
  [[expr.ref]], [[expr.mptr.oper]],
 
 
3432
  - when performing an array-to-pointer conversion or subscripting on an
3433
  array prvalue [[conv.array]], [[expr.sub]],
3434
  - when initializing an object of type `std::initializer_list<T>` from a
3435
  *braced-init-list* [[dcl.init.list]],
3436
  - for certain unevaluated operands [[expr.typeid]], [[expr.sizeof]], and
@@ -3478,49 +3823,56 @@ result is constructed directly in `c`. On the other hand, the expression
3478
  materialized so that the reference parameter of `X::operator=(const X&)`
3479
  can bind to it.
3480
 
3481
  — *end example*]
3482
 
3483
- When an object of class type `X` is passed to or returned from a
3484
- function, if `X` has at least one eligible copy or move constructor
3485
- [[special]], each such constructor is trivial, and the destructor of `X`
3486
- is either trivial or deleted, implementations are permitted to create a
3487
- temporary object to hold the function parameter or result object. The
3488
- temporary object is constructed from the function argument or return
3489
- value, respectively, and the function’s parameter or return object is
3490
- initialized as if by using the eligible trivial constructor to copy the
3491
- temporary (even if that constructor is inaccessible or would not be
3492
- selected by overload resolution to perform a copy or move of the
3493
- object).
3494
 
3495
- [*Note 4*: This latitude is granted to allow objects of class type to
3496
- be passed to or returned from functions in registers. *end note*]
 
 
3497
 
3498
- When an implementation introduces a temporary object of a class that has
3499
- a non-trivial constructor [[class.default.ctor]], [[class.copy.ctor]],
3500
- it shall ensure that a constructor is called for the temporary object.
3501
- Similarly, the destructor shall be called for a temporary with a
3502
- non-trivial destructor [[class.dtor]]. Temporary objects are destroyed
3503
- as the last step in evaluating the full-expression [[intro.execution]]
3504
- that (lexically) contains the point where they were created. This is
3505
- true even if that evaluation ends in throwing an exception. The value
3506
- computations and side effects of destroying a temporary object are
3507
- associated only with the full-expression, not with any specific
3508
- subexpression.
3509
 
3510
- There are four contexts in which temporaries are destroyed at a
3511
- different point than the end of the full-expression. The first context
3512
- is when a default constructor is called to initialize an element of an
3513
- array with no corresponding initializer [[dcl.init]]. The second context
3514
- is when a copy constructor is called to copy an element of an array
3515
- while the entire array is copied
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3516
  [[expr.prim.lambda.capture]], [[class.copy.ctor]]. In either case, if
3517
  the constructor has one or more default arguments, the destruction of
3518
  every temporary created in a default argument is sequenced before the
3519
  construction of the next array element, if any.
3520
 
3521
- The third context is when a reference binds to a temporary object.[^13]
3522
 
3523
  The temporary object to which the reference is bound or the temporary
3524
  object that is the complete object of a subobject to which the reference
3525
  is bound persists for the lifetime of the reference if the glvalue to
3526
  which the reference is bound was obtained through one of the following:
@@ -3562,11 +3914,11 @@ int&& c = cond ? id<int[3]>{1, 2, 3}[i] : static_cast<int&&>(0);
3562
  // exactly one of the two temporaries is lifetime-extended
3563
  ```
3564
 
3565
  — *end example*]
3566
 
3567
- [*Note 5*:
3568
 
3569
  An explicit type conversion [[expr.type.conv]], [[expr.cast]] is
3570
  interpreted as a sequence of elementary casts, covered above.
3571
 
3572
  [*Example 3*:
@@ -3577,11 +3929,11 @@ const int& x = (const int&)1; // temporary for value 1 has same lifetime as x
3577
 
3578
  — *end example*]
3579
 
3580
  — *end note*]
3581
 
3582
- [*Note 6*:
3583
 
3584
  If a temporary object has a reference member initialized by another
3585
  temporary object, lifetime extension applies recursively to such a
3586
  member’s initializer.
3587
 
@@ -3605,43 +3957,52 @@ The exceptions to this lifetime rule are:
3605
  containing the call.
3606
  - A temporary object bound to a reference element of an aggregate of
3607
  class type initialized from a parenthesized *expression-list*
3608
  [[dcl.init]] persists until the completion of the full-expression
3609
  containing the *expression-list*.
3610
- - The lifetime of a temporary bound to the returned value in a function
3611
- `return` statement [[stmt.return]] is not extended; the temporary is
3612
- destroyed at the end of the full-expression in the `return` statement.
3613
  - A temporary bound to a reference in a *new-initializer* [[expr.new]]
3614
  persists until the completion of the full-expression containing the
3615
  *new-initializer*.
3616
- \[*Note 7*: This might introduce a dangling reference. — *end note*]
3617
  \[*Example 5*:
3618
  ``` cpp
3619
  struct S { int mi; const std::pair<int,int>& mp; };
3620
  S a { 1, {2,3} };
3621
  S* p = new S{ 1, {2,3} }; // creates dangling reference
3622
  ```
3623
 
3624
  — *end example*]
3625
 
3626
- The fourth context is when a temporary object other than a function
3627
- parameter object is created in the *for-range-initializer* of a
3628
- range-based `for` statement. If such a temporary object would otherwise
3629
- be destroyed at the end of the *for-range-initializer* full-expression,
3630
- the object persists for the lifetime of the reference initialized by the
3631
- *for-range-initializer*.
3632
 
3633
- The destruction of a temporary whose lifetime is not extended beyond the
3634
- full-expression in which it was created is sequenced before the
3635
- destruction of every temporary which is constructed earlier in the same
3636
- full-expression. If the lifetime of two or more temporaries with
3637
- lifetimes extending beyond the full-expressions in which they were
3638
- created ends at the same point, these temporaries are destroyed at that
3639
- point in the reverse order of the completion of their construction. In
3640
- addition, the destruction of such temporaries shall take into account
3641
- the ordering of destruction of objects with static, thread, or automatic
3642
- storage duration
 
 
 
 
 
 
 
 
 
 
 
 
3643
  [[basic.stc.static]], [[basic.stc.thread]], [[basic.stc.auto]]; that is,
3644
  if `obj1` is an object with the same storage duration as the temporary
3645
  and created before the temporary is created the temporary shall be
3646
  destroyed before `obj1` is destroyed; if `obj2` is an object with the
3647
  same storage duration as the temporary and created after the temporary
@@ -3693,11 +4054,11 @@ functions [[dcl.fct]]. — *end note*]
3693
 
3694
  For any object (other than a potentially-overlapping subobject) of
3695
  trivially copyable type `T`, whether or not the object holds a valid
3696
  value of type `T`, the underlying bytes [[intro.memory]] making up the
3697
  object can be copied into an array of `char`, `unsigned char`, or
3698
- `std::byte` [[cstddef.syn]].[^14]
3699
 
3700
  If the content of that array is copied back into the object, the object
3701
  shall subsequently hold its original value.
3702
 
3703
  [*Example 1*:
@@ -3713,11 +4074,11 @@ std::memcpy(&obj, buf, N); // at this point, each subobject of obj of scala
3713
  — *end example*]
3714
 
3715
  For two distinct objects `obj1` and `obj2` of trivially copyable type
3716
  `T`, where neither `obj1` nor `obj2` is a potentially-overlapping
3717
  subobject, if the underlying bytes [[intro.memory]] making up `obj1` are
3718
- copied into `obj2`,[^15]
3719
 
3720
  `obj2` shall subsequently hold the same value as `obj1`.
3721
 
3722
  [*Example 2*:
3723
 
@@ -3730,23 +4091,31 @@ std::memcpy(t1p, t2p, sizeof(T));
3730
  // the same value as the corresponding subobject in *t2p
3731
  ```
3732
 
3733
  — *end example*]
3734
 
3735
- The *object representation* of an object of type `T` is the sequence of
3736
- *N* `unsigned char` objects taken up by the object of type `T`, where
3737
- *N* equals `sizeof(T)`. The *value representation* of an object of type
3738
- `T` is the set of bits that participate in representing a value of type
3739
- `T`. Bits in the object representation that are not part of the value
3740
- representation are *padding bits*. For trivially copyable types, the
3741
- value representation is a set of bits in the object representation that
3742
- determines a *value*, which is one discrete element of an
3743
- *implementation-defined* set of values.[^16]
 
 
 
 
 
 
 
 
3744
 
3745
  A class that has been declared but not defined, an enumeration type in
3746
  certain contexts [[dcl.enum]], or an array of unknown bound or of
3747
- incomplete element type, is an *incompletely-defined object type*.[^17]
3748
 
3749
  Incompletely-defined object types and cv `void` are *incomplete types*
3750
  [[basic.fundamental]].
3751
 
3752
  [*Note 2*: Objects cannot be defined to have an incomplete type
@@ -3804,34 +4173,36 @@ contexts incomplete types are prohibited. — *end note*]
3804
 
3805
  An *object type* is a (possibly cv-qualified) type that is not a
3806
  function type, not a reference type, and not cv `void`.
3807
 
3808
  Arithmetic types [[basic.fundamental]], enumeration types, pointer
3809
- types, pointer-to-member types [[basic.compound]], `std::nullptr_t`, and
3810
- cv-qualified [[basic.type.qualifier]] versions of these types are
3811
- collectively called *scalar types*. Scalar types, trivially copyable
3812
- class types [[class.prop]], arrays of such types, and cv-qualified
3813
- versions of these types are collectively called *trivially copyable
3814
- types*. Scalar types, trivial class types [[class.prop]], arrays of such
3815
- types and cv-qualified versions of these types are collectively called
3816
- *trivial types*. Scalar types, standard-layout class types
3817
- [[class.prop]], arrays of such types and cv-qualified versions of these
3818
- types are collectively called *standard-layout types*. Scalar types,
3819
- implicit-lifetime class types [[class.prop]], array types, and
3820
- cv-qualified versions of these types are collectively called
3821
- *implicit-lifetime types*.
 
 
3822
 
3823
  A type is a *literal type* if it is:
3824
 
3825
  - cv `void`; or
3826
  - a scalar type; or
3827
  - a reference type; or
3828
  - an array of literal type; or
3829
  - a possibly cv-qualified class type [[class]] that has all of the
3830
  following properties:
3831
  - it has a constexpr destructor [[dcl.constexpr]],
3832
- - all of its non-static non-variant data members and base classes are
3833
  of non-volatile literal types, and
3834
  - it
3835
  - is a closure type [[expr.prim.lambda.closure]],
3836
  - is an aggregate union type that has either no variant members or
3837
  at least one variant member of non-volatile literal type,
@@ -3851,20 +4222,30 @@ expression. — *end note*]
3851
  Two types *cv1* `T1` and *cv2* `T2` are *layout-compatible types* if
3852
  `T1` and `T2` are the same type, layout-compatible enumerations
3853
  [[dcl.enum]], or layout-compatible standard-layout class types
3854
  [[class.mem]].
3855
 
 
 
 
 
 
 
 
 
 
 
3856
  ### Fundamental types <a id="basic.fundamental">[[basic.fundamental]]</a>
3857
 
3858
  There are five *standard signed integer types*: “`signed char`”,
3859
  “`short int`”, “`int`”, “`long int`”, and “`long long int`”. In this
3860
  list, each type provides at least as much storage as those preceding it
3861
  in the list. There may also be *implementation-defined* *extended signed
3862
  integer types*. The standard and extended signed integer types are
3863
  collectively called *signed integer types*. The range of representable
3864
- values for a signed integer type is -2ᴺ⁻¹ to 2ᴺ⁻¹-1 (inclusive), where
3865
- *N* is called the *width* of the type.
3866
 
3867
  [*Note 1*: Plain `int`s are intended to have the natural width
3868
  suggested by the architecture of the execution environment; the other
3869
  signed integer types are provided to meet special needs. — *end note*]
3870
 
@@ -3886,11 +4267,11 @@ arithmetic yields undefined behavior [[expr.pre]]. — *end note*]
3886
  An unsigned integer type has the same object representation, value
3887
  representation, and alignment requirements [[basic.align]] as the
3888
  corresponding signed integer type. For each value x of a signed integer
3889
  type, the value of the corresponding unsigned integer type congruent to
3890
  x modulo 2ᴺ has the same value of corresponding bits in its value
3891
- representation.[^18]
3892
 
3893
  [*Example 1*: The value -1 of a signed integer type has the same
3894
  representation as the largest value of the corresponding unsigned
3895
  type. — *end example*]
3896
 
@@ -3903,22 +4284,22 @@ type. — *end example*]
3903
  | `int` | 16 |
3904
  | `long int` | 32 |
3905
  | `long long int` | 64 |
3906
 
3907
 
3908
- The width of each signed integer type shall not be less than the values
3909
- specified in [[basic.fundamental.width]]. The value representation of a
3910
- signed or unsigned integer type comprises N bits, where N is the
3911
- respective width. Each set of values for any padding bits
3912
  [[basic.types.general]] in the object representation are alternative
3913
  representations of the value specified by the value representation.
3914
 
3915
  [*Note 3*: Padding bits have unspecified value, but cannot cause traps.
3916
- In contrast, see ISO C 6.2.6.2. — *end note*]
3917
 
3918
  [*Note 4*: The signed and unsigned integer types satisfy the
3919
- constraints given in ISO C 5.2.4.2.1. — *end note*]
3920
 
3921
  Except as specified above, the width of a signed or unsigned integer
3922
  type is *implementation-defined*.
3923
 
3924
  Each value x of an unsigned integer type with width N has a unique
@@ -3956,12 +4337,12 @@ than the width of that type has padding bits; see
3956
  Type `wchar_t` is a distinct type that has an *implementation-defined*
3957
  signed or unsigned integer type as its underlying type.
3958
 
3959
  Type `char8_t` denotes a distinct type whose underlying type is
3960
  `unsigned char`. Types `char16_t` and `char32_t` denote distinct types
3961
- whose underlying types are `uint_least16_t` and `uint_least32_t`,
3962
- respectively, in `<cstdint>`.
3963
 
3964
  Type `bool` is a distinct type that has the same object representation,
3965
  value representation, and alignment requirements as an
3966
  *implementation-defined* unsigned integer type. The values of type
3967
  `bool` are `true` and `false`.
@@ -4001,128 +4382,233 @@ interactions with floating-point types. — *end note*]
4001
 
4002
  Except as specified in [[basic.extended.fp]], the object and value
4003
  representations and accuracy of operations of floating-point types are
4004
  *implementation-defined*.
4005
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4006
  Integral and floating-point types are collectively termed *arithmetic
4007
  types*.
4008
 
4009
- [*Note 10*: Properties of the arithmetic types, such as their minimum
4010
  and maximum representable value, can be queried using the facilities in
4011
  the standard library headers `<limits>`, `<climits>`, and
4012
  `<cfloat>`. — *end note*]
4013
 
4014
  A type cv `void` is an incomplete type that cannot be completed; such a
4015
  type has an empty set of values. It is used as the return type for
4016
- functions that do not return a value. Any expression can be explicitly
4017
- converted to type cv `void`
4018
- [[expr.type.conv]], [[expr.static.cast]], [[expr.cast]]. An expression
4019
- of type cv `void` shall be used only as an expression statement
4020
- [[stmt.expr]], as an operand of a comma expression [[expr.comma]], as a
4021
- second or third operand of `?:` [[expr.cond]], as the operand of
4022
- `typeid`, `noexcept`, or `decltype`, as the expression in a `return`
4023
- statement [[stmt.return]] for a function with the return type cv `void`,
4024
- or as the operand of an explicit conversion to type cv `void`.
4025
-
4026
- A value of type `std::nullptr_t` is a null pointer constant
4027
- [[conv.ptr]]. Such values participate in the pointer and the
4028
- pointer-to-member conversions [[conv.ptr]], [[conv.mem]].
4029
- `sizeof(std::nullptr_t)` shall be equal to `sizeof(void*)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4030
 
4031
  The types described in this subclause are called *fundamental types*.
4032
 
4033
- [*Note 11*: Even if the implementation defines two or more fundamental
4034
  types to have the same value representation, they are nevertheless
4035
  different types. — *end note*]
4036
 
4037
  ### Optional extended floating-point types <a id="basic.extended.fp">[[basic.extended.fp]]</a>
4038
 
4039
  If the implementation supports an extended floating-point type
4040
- [[basic.fundamental]] whose properties are specified by the ISO/IEC/IEEE
4041
  60559 floating-point interchange format binary16, then the
4042
- *typedef-name* `std::float16_t` is defined in the header `<stdfloat>`
4043
  and names such a type, the macro `__STDCPP_FLOAT16_T__` is defined
4044
  [[cpp.predefined]], and the floating-point literal suffixes `f16` and
4045
  `F16` are supported [[lex.fcon]].
4046
 
4047
  If the implementation supports an extended floating-point type whose
4048
- properties are specified by the ISO/IEC/IEEE 60559 floating-point
4049
- interchange format binary32, then the *typedef-name* `std::float32_t` is
4050
- defined in the header `<stdfloat>` and names such a type, the macro
4051
  `__STDCPP_FLOAT32_T__` is defined, and the floating-point literal
4052
  suffixes `f32` and `F32` are supported.
4053
 
4054
  If the implementation supports an extended floating-point type whose
4055
- properties are specified by the ISO/IEC/IEEE 60559 floating-point
4056
- interchange format binary64, then the *typedef-name* `std::float64_t` is
4057
- defined in the header `<stdfloat>` and names such a type, the macro
4058
  `__STDCPP_FLOAT64_T__` is defined, and the floating-point literal
4059
  suffixes `f64` and `F64` are supported.
4060
 
4061
  If the implementation supports an extended floating-point type whose
4062
- properties are specified by the ISO/IEC/IEEE 60559 floating-point
4063
- interchange format binary128, then the *typedef-name* `std::float128_t`
4064
- is defined in the header `<stdfloat>` and names such a type, the macro
4065
  `__STDCPP_FLOAT128_T__` is defined, and the floating-point literal
4066
  suffixes `f128` and `F128` are supported.
4067
 
4068
  If the implementation supports an extended floating-point type with the
4069
- properties, as specified by ISO/IEC/IEEE 60559, of radix (b) of 2,
4070
- storage width in bits (k) of 16, precision in bits (p) of 8, maximum
4071
- exponent (emax) of 127, and exponent field width in bits (w) of 8, then
4072
- the *typedef-name* `std::bfloat16_t` is defined in the header
4073
- `<stdfloat>` and names such a type, the macro `__STDCPP_BFLOAT16_T__` is
4074
- defined, and the floating-point literal suffixes `bf16` and `BF16` are
4075
- supported.
4076
 
4077
  [*Note 1*: A summary of the parameters for each type is given in
4078
  [[basic.extended.fp]]. The precision p includes the implicit 1 bit at
4079
- the beginning of the mantissa, so the storage used for the mantissa is
4080
- p-1 bits. ISO/IEC/IEEE 60559 does not assign a name for a type having
4081
- the parameters specified for `std::bfloat16_t`. — *end note*]
4082
 
4083
  **Table: Properties of named extended floating-point types** <a id="basic.extended.fp">[basic.extended.fp]</a>
4084
 
4085
  | Parameter | `float16_t` | `float32_t` | `float64_t` | `float128_t` | `bfloat16_t` |
4086
  | --------------------------------- | ----------- | ----------- | ----------- | ------------ | ------------ |
4087
- | ISO/IEC/IEEE 60559 name | binary16 | binary32 | binary64 | binary128 | |
4088
  | $k$, storage width in bits | 16 | 32 | 64 | 128 | 16 |
4089
  | $p$, precision in bits | 11 | 24 | 53 | 113 | 8 |
4090
  | $emax$, maximum exponent | 15 | 127 | 1023 | 16383 | 127 |
4091
  | $w$, exponent field width in bits | 5 | 8 | 11 | 15 | 8 |
4092
 
4093
 
4094
  *Recommended practice:* Any names that the implementation provides for
4095
  the extended floating-point types described in this subsection that are
4096
- in addition to the names defined in the `<stdfloat>` header should be
4097
  chosen to increase compatibility and interoperability with the
4098
  interchange types `_Float16`, `_Float32`, `_Float64`, and `_Float128`
4099
- defined in ISO/IEC TS 18661-3 and with future versions of the C
4100
- standard.
4101
 
4102
  ### Compound types <a id="basic.compound">[[basic.compound]]</a>
4103
 
4104
  Compound types can be constructed in the following ways:
4105
 
4106
  - *arrays* of objects of a given type, [[dcl.array]];
4107
  - *functions*, which have parameters of given types and return `void` or
4108
- references or objects of a given type, [[dcl.fct]];
4109
  - *pointers* to cv `void` or objects or functions (including static
4110
  members of classes) of a given type, [[dcl.ptr]];
4111
  - *references* to objects or functions of a given type, [[dcl.ref]].
4112
  There are two types of references:
4113
  - lvalue reference
4114
  - rvalue reference
4115
- - *classes* containing a sequence of objects of various types [[class]],
4116
- a set of types, enumerations and functions for manipulating these
4117
- objects [[class.mfct]], and a set of restrictions on the access to
4118
  these entities [[class.access]];
4119
  - *unions*, which are classes capable of containing objects of different
4120
  types at different times, [[class.union]];
4121
  - *enumerations*, which comprise a set of named constant values,
4122
  [[dcl.enum]];
4123
- - *pointers to non-static class members*,[^19] which identify members of
4124
  a given type within objects of a given class, [[dcl.mptr]]. Pointers
4125
  to data members and pointers to member functions are collectively
4126
  called *pointer-to-member* types.
4127
 
4128
  These methods of constructing types can be applied recursively;
@@ -4146,46 +4632,59 @@ to as a “pointer to `T`”.
4146
  “pointer to `X`”. — *end example*]
4147
 
4148
  Except for pointers to static members, text referring to “pointers” does
4149
  not apply to pointers to members. Pointers to incomplete types are
4150
  allowed although there are restrictions on what can be done with them
4151
- [[basic.align]]. Every value of pointer type is one of the following:
 
4152
 
4153
  - a *pointer to* an object or function (the pointer is said to *point*
4154
  to the object or function), or
4155
  - a *pointer past the end of* an object [[expr.add]], or
4156
  - the *null pointer value* for that type, or
4157
  - an *invalid pointer value*.
4158
 
4159
  A value of a pointer type that is a pointer to or past the end of an
4160
  object *represents the address* of the first byte in memory
4161
- [[intro.memory]] occupied by the object[^20]
4162
 
4163
  or the first byte in memory after the end of the storage occupied by the
4164
  object, respectively.
4165
 
4166
  [*Note 2*: A pointer past the end of an object [[expr.add]] is not
4167
  considered to point to an unrelated object of the object’s type, even if
4168
- the unrelated object is located at that address. A pointer value becomes
4169
- invalid when the storage it denotes reaches the end of its storage
4170
- duration; see [[basic.stc]]. — *end note*]
4171
 
4172
  For purposes of pointer arithmetic [[expr.add]] and comparison
4173
  [[expr.rel]], [[expr.eq]], a pointer past the end of the last element of
4174
  an array `x` of n elements is considered to be equivalent to a pointer
4175
- to a hypothetical array element n of `x` and an object of type `T` that
4176
  is not an array element is considered to belong to an array with one
4177
  element of type `T`. The value representation of pointer types is
4178
  *implementation-defined*. Pointers to layout-compatible types shall have
4179
  the same value representation and alignment requirements
4180
  [[basic.align]].
4181
 
4182
  [*Note 3*: Pointers to over-aligned types [[basic.align]] have no
4183
  special representation, but their range of valid values is restricted by
4184
  the extended alignment requirement. — *end note*]
4185
 
4186
- Two objects *a* and *b* are *pointer-interconvertible* if:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4187
 
4188
  - they are the same object, or
4189
  - one is a union object and the other is a non-static data member of
4190
  that object [[class.union]], or
4191
  - one is a standard-layout class object and the other is the first
@@ -4197,11 +4696,11 @@ Two objects *a* and *b* are *pointer-interconvertible* if:
4197
 
4198
  If two objects are pointer-interconvertible, then they have the same
4199
  address, and it is possible to obtain a pointer to one from a pointer to
4200
  the other via a `reinterpret_cast` [[expr.reinterpret.cast]].
4201
 
4202
- [*Note 4*: An array object and its first element are not
4203
  pointer-interconvertible, even though they have the same
4204
  address. — *end note*]
4205
 
4206
  A byte of storage *b* is *reachable through* a pointer value that points
4207
  to an object *x* if there is an object *y*, pointer-interconvertible
@@ -4218,11 +4717,11 @@ alignment requirements as an object of type “pointer to cv `char`”.
4218
  Each type other than a function or reference type is part of a group of
4219
  four distinct, but related, types: a *cv-unqualified* version, a
4220
  *const-qualified* version, a *volatile-qualified* version, and a
4221
  *const-volatile-qualified* version. The types in each such group shall
4222
  have the same representation and alignment requirements
4223
- [[basic.align]].[^21]
4224
 
4225
  A function or reference type is always cv-unqualified.
4226
 
4227
  - A *const object* is an object of type `const T` or a non-mutable
4228
  subobject of a const object.
@@ -4330,11 +4829,11 @@ integral promotions [[conv.prom]] and the usual arithmetic conversions
4330
  [[expr.arith.conv]]. — *end note*]
4331
 
4332
  Every floating-point type has a *floating-point conversion rank* defined
4333
  as follows:
4334
 
4335
- - The rank of a floating point type `T` is greater than the rank of any
4336
  floating-point type whose set of values is a proper subset of the set
4337
  of values of `T`.
4338
  - The rank of `long double` is greater than the rank of `double`, which
4339
  is greater than the rank of `float`.
4340
  - Two extended floating-point types with the same set of values have
@@ -4342,11 +4841,19 @@ as follows:
4342
  - An extended floating-point type with the same set of values as exactly
4343
  one cv-unqualified standard floating-point type has a rank equal to
4344
  the rank of that standard floating-point type.
4345
  - An extended floating-point type with the same set of values as more
4346
  than one cv-unqualified standard floating-point type has a rank equal
4347
- to the rank of `double`.
 
 
 
 
 
 
 
 
4348
 
4349
  [*Note 2*: The conversion ranks of floating-point types `T1` and `T2`
4350
  are unordered if the set of values of `T1` is neither a subset nor a
4351
  superset of the set of values of `T2`. This can happen when one type has
4352
  both a larger range and a lower precision than the other. — *end note*]
@@ -4429,16 +4936,18 @@ or *initializer* E are
4429
  A *full-expression* is
4430
 
4431
  - an unevaluated operand [[expr.context]],
4432
  - a *constant-expression* [[expr.const]],
4433
  - an immediate invocation [[expr.const]],
4434
- - an *init-declarator* [[dcl.decl]] or a *mem-initializer*
 
4435
  [[class.base.init]], including the constituent expressions of the
4436
  initializer,
4437
  - an invocation of a destructor generated at the end of the lifetime of
4438
  an object other than a temporary object [[class.temporary]] whose
4439
- lifetime has not been extended, or
 
4440
  - an expression that is not a subexpression of another expression and
4441
  that is not otherwise part of a full-expression.
4442
 
4443
  If a language construct is defined to produce an implicit call of a
4444
  function, a use of the language construct is considered to be an
@@ -4465,11 +4974,11 @@ S s1(1); // full-expression comprises call of S::S(int)
4465
  void f() {
4466
  S s2 = 2; // full-expression comprises call of S::S(int)
4467
  if (S(3).v()) // full-expression includes lvalue-to-rvalue and int to bool conversions,
4468
  // performed before temporary is deleted at end of full-expression
4469
  { }
4470
- bool b = noexcept(S()); // exception specification of destructor of S considered for noexcept
4471
 
4472
  // full-expression is destruction of s2 at end of block
4473
  }
4474
  struct B {
4475
  B(S = S(0));
@@ -4486,19 +4995,20 @@ full-expression. For example, subexpressions involved in evaluating
4486
  default arguments [[dcl.fct.default]] are considered to be created in
4487
  the expression that calls the function, not the expression that defines
4488
  the default argument. — *end note*]
4489
 
4490
  Reading an object designated by a `volatile` glvalue [[basic.lval]],
4491
- modifying an object, calling a library I/O function, or calling a
4492
- function that does any of those operations are all *side effects*, which
4493
- are changes in the state of the execution environment. *Evaluation* of
4494
- an expression (or a subexpression) in general includes both value
 
4495
  computations (including determining the identity of an object for
4496
  glvalue evaluation and fetching a value previously assigned to an object
4497
  for prvalue evaluation) and initiation of side effects. When a call to a
4498
  library I/O function returns or an access through a volatile glvalue is
4499
- evaluated the side effect is considered complete, even though some
4500
  external actions implied by the call (such as the I/O itself) or by the
4501
  `volatile` access may not have completed yet.
4502
 
4503
  *Sequenced before* is an asymmetric, transitive, pair-wise relation
4504
  between evaluations executed by a single thread [[intro.multithread]],
@@ -4523,29 +5033,43 @@ every value computation and every side effect associated with the
4523
  expression *X* is sequenced before every value computation and every
4524
  side effect associated with the expression *Y*.
4525
 
4526
  Every value computation and side effect associated with a
4527
  full-expression is sequenced before every value computation and side
4528
- effect associated with the next full-expression to be evaluated.[^22]
4529
 
4530
  Except where noted, evaluations of operands of individual operators and
4531
  of subexpressions of individual expressions are unsequenced.
4532
 
4533
  [*Note 5*: In an expression that is evaluated more than once during the
4534
  execution of a program, unsequenced and indeterminately sequenced
4535
  evaluations of its subexpressions need not be performed consistently in
4536
  different evaluations. — *end note*]
4537
 
4538
  The value computations of the operands of an operator are sequenced
4539
- before the value computation of the result of the operator. If a side
4540
- effect on a memory location [[intro.memory]] is unsequenced relative to
4541
- either another side effect on the same memory location or a value
4542
- computation using the value of any object in the same memory location,
4543
- and they are not potentially concurrent [[intro.multithread]], the
4544
- behavior is undefined.
4545
-
4546
- [*Note 6*: The next subclause imposes similar, but more complex
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4547
  restrictions on potentially concurrent computations. — *end note*]
4548
 
4549
  [*Example 3*:
4550
 
4551
  ``` cpp
@@ -4553,24 +5077,35 @@ void g(int i) {
4553
  i = 7, i++, i++; // i becomes 9
4554
 
4555
  i = i++ + 1; // the value of i is incremented
4556
  i = i++ + i; // undefined behavior
4557
  i = i + 1; // the value of i is incremented
 
 
 
4558
  }
4559
  ```
4560
 
4561
  — *end example*]
4562
 
4563
- When invoking a function (whether or not the function is inline), every
4564
- argument expression and the postfix expression designating the called
4565
- function are sequenced before every expression or statement in the body
4566
- of the called function. For each function invocation or evaluation of an
4567
- *await-expression* *F*, each evaluation that does not occur within *F*
4568
- but is evaluated on the same thread and as part of the same signal
4569
- handler (if any) is either sequenced before all evaluations that occur
4570
- within *F* or sequenced after all evaluations that occur within
4571
- *F*;[^23]
 
 
 
 
 
 
 
 
4572
 
4573
  if *F* invokes or resumes a coroutine [[expr.await]], only evaluations
4574
  subsequent to the previous suspension (if any) and prior to the next
4575
  suspension (if any) are considered to occur within *F*.
4576
 
@@ -4589,14 +5124,19 @@ regardless of the syntax of the expression that calls the function.
4589
 
4590
  If a signal handler is executed as a result of a call to the
4591
  `std::raise` function, then the execution of the handler is sequenced
4592
  after the invocation of the `std::raise` function and before its return.
4593
 
4594
- [*Note 7*: When a signal is received for another reason, the execution
4595
  of the signal handler is usually unsequenced with respect to the rest of
4596
  the program. — *end note*]
4597
 
 
 
 
 
 
4598
  ### Multi-threaded executions and data races <a id="intro.multithread">[[intro.multithread]]</a>
4599
 
4600
  #### General <a id="intro.multithread.general">[[intro.multithread.general]]</a>
4601
 
4602
  A *thread of execution* (also known as a *thread*) is a single flow of
@@ -4606,12 +5146,12 @@ subsequently executed by the thread.
4606
 
4607
  [*Note 1*: When one thread creates another, the initial call to the
4608
  top-level function of the new thread is executed by the new thread, not
4609
  by the creating thread. — *end note*]
4610
 
4611
- Every thread in a program can potentially access every object and
4612
- function in a program.[^24]
4613
 
4614
  Under a hosted implementation, a C++ program can have more than one
4615
  thread running concurrently. The execution of each thread proceeds as
4616
  defined by the remainder of this document. The execution of the entire
4617
  program consists of an execution of all of its threads.
@@ -4639,27 +5179,37 @@ below.
4639
  Much of this subclause is motivated by the desire to support atomic
4640
  operations with explicit and detailed visibility constraints. However,
4641
  it also implicitly supports a simpler view for more restricted
4642
  programs. — *end note*]
4643
 
4644
- Two expression evaluations *conflict* if one of them modifies a memory
4645
- location [[intro.memory]] and the other one reads or modifies the same
4646
- memory location.
 
 
 
 
 
 
 
 
 
 
4647
 
4648
  The library defines a number of atomic operations [[atomics]] and
4649
  operations on mutexes [[thread]] that are specially identified as
4650
  synchronization operations. These operations play a special role in
4651
  making assignments in one thread visible to another. A synchronization
4652
- operation on one or more memory locations is either a consume operation,
4653
- an acquire operation, a release operation, or both an acquire and
4654
- release operation. A synchronization operation without an associated
4655
- memory location is a fence and can be either an acquire fence, a release
4656
- fence, or both an acquire and release fence. In addition, there are
4657
- relaxed atomic operations, which are not synchronization operations, and
4658
- atomic read-modify-write operations, which have special characteristics.
4659
 
4660
- [*Note 2*: For example, a call that acquires a mutex will perform an
4661
  acquire operation on the locations comprising the mutex.
4662
  Correspondingly, a call that releases the same mutex will perform a
4663
  release operation on those same locations. Informally, performing a
4664
  release operation on A forces prior side effects on other memory
4665
  locations to become visible to other threads that later perform a
@@ -4668,11 +5218,11 @@ not synchronization operations even though, like synchronization
4668
  operations, they cannot contribute to data races. — *end note*]
4669
 
4670
  All modifications to a particular atomic object M occur in some
4671
  particular total order, called the *modification order* of M.
4672
 
4673
- [*Note 3*: There is a separate order for each atomic object. There is
4674
  no requirement that these can be combined into a single total order for
4675
  all objects. In general this will be impossible since different threads
4676
  can observe modifications to different objects in inconsistent
4677
  orders. — *end note*]
4678
 
@@ -4684,181 +5234,107 @@ subsequent operation is an atomic read-modify-write operation.
4684
  Certain library calls *synchronize with* other library calls performed
4685
  by another thread. For example, an atomic store-release synchronizes
4686
  with a load-acquire that takes its value from the store
4687
  [[atomics.order]].
4688
 
4689
- [*Note 4*: Except in the specified cases, reading a later value does
4690
  not necessarily ensure visibility as described below. Such a requirement
4691
  would sometimes interfere with efficient implementation. — *end note*]
4692
 
4693
- [*Note 5*: The specifications of the synchronization operations define
4694
  when one reads the value written by another. For atomic objects, the
4695
  definition is clear. All operations on a given mutex occur in a single
4696
  total order. Each mutex acquisition “reads the value written” by the
4697
  last mutex release. — *end note*]
4698
 
4699
- An evaluation A *carries a dependency* to an evaluation B if
4700
-
4701
- - the value of A is used as an operand of B, unless:
4702
- - B is an invocation of any specialization of `std::kill_dependency`
4703
- [[atomics.order]], or
4704
- - A is the left operand of a built-in logical (`&&`, see 
4705
- [[expr.log.and]]) or logical (`||`, see  [[expr.log.or]]) operator,
4706
- or
4707
- - A is the left operand of a conditional (`?:`, see  [[expr.cond]])
4708
- operator, or
4709
- - A is the left operand of the built-in comma (`,`) operator
4710
- [[expr.comma]];
4711
-
4712
- or
4713
- - A writes a scalar object or bit-field M, B reads the value written by
4714
- A from M, and A is sequenced before B, or
4715
- - for some evaluation X, A carries a dependency to X, and X carries a
4716
- dependency to B.
4717
-
4718
- [*Note 6*: “Carries a dependency to” is a subset of “is sequenced
4719
- before”, and is similarly strictly intra-thread. — *end note*]
4720
-
4721
- An evaluation A is *dependency-ordered before* an evaluation B if
4722
-
4723
- - A performs a release operation on an atomic object M, and, in another
4724
- thread, B performs a consume operation on M and reads the value
4725
- written by A, or
4726
- - for some evaluation X, A is dependency-ordered before X and X carries
4727
- a dependency to B.
4728
-
4729
- [*Note 7*: The relation “is dependency-ordered before” is analogous to
4730
- “synchronizes with”, but uses release/consume in place of
4731
- release/acquire. — *end note*]
4732
-
4733
- An evaluation A *inter-thread happens before* an evaluation B if
4734
-
4735
- - A synchronizes with B, or
4736
- - A is dependency-ordered before B, or
4737
- - for some evaluation X
4738
- - A synchronizes with X and X is sequenced before B, or
4739
- - A is sequenced before X and X inter-thread happens before B, or
4740
- - A inter-thread happens before X and X inter-thread happens before B.
4741
-
4742
- [*Note 8*: The “inter-thread happens before” relation describes
4743
- arbitrary concatenations of “sequenced before”, “synchronizes with” and
4744
- “dependency-ordered before” relationships, with two exceptions. The
4745
- first exception is that a concatenation is not permitted to end with
4746
- “dependency-ordered before” followed by “sequenced before”. The reason
4747
- for this limitation is that a consume operation participating in a
4748
- “dependency-ordered before” relationship provides ordering only with
4749
- respect to operations to which this consume operation actually carries a
4750
- dependency. The reason that this limitation applies only to the end of
4751
- such a concatenation is that any subsequent release operation will
4752
- provide the required ordering for a prior consume operation. The second
4753
- exception is that a concatenation is not permitted to consist entirely
4754
- of “sequenced before”. The reasons for this limitation are (1) to permit
4755
- “inter-thread happens before” to be transitively closed and (2) the
4756
- “happens before” relation, defined below, provides for relationships
4757
- consisting entirely of “sequenced before”. — *end note*]
4758
-
4759
  An evaluation A *happens before* an evaluation B (or, equivalently, B
4760
- *happens after* A) if:
4761
-
4762
- - A is sequenced before B, or
4763
- - A inter-thread happens before B.
4764
-
4765
- The implementation shall ensure that no program execution demonstrates a
4766
- cycle in the “happens before” relation.
4767
-
4768
- [*Note 9*: This cycle would otherwise be possible only through the use
4769
- of consume operations. — *end note*]
4770
-
4771
- An evaluation A *simply happens before* an evaluation B if either
4772
 
4773
  - A is sequenced before B, or
4774
  - A synchronizes with B, or
4775
- - A simply happens before X and X simply happens before B.
4776
 
4777
- [*Note 10*: In the absence of consume operations, the happens before
4778
- and simply happens before relations are identical. — *end note*]
4779
 
4780
  An evaluation A *strongly happens before* an evaluation D if, either
4781
 
4782
  - A is sequenced before D, or
4783
  - A synchronizes with D, and both A and D are sequentially consistent
4784
  atomic operations [[atomics.order]], or
4785
  - there are evaluations B and C such that A is sequenced before B, B
4786
- simply happens before C, and C is sequenced before D, or
4787
  - there is an evaluation B such that A strongly happens before B, and B
4788
  strongly happens before D.
4789
 
4790
- [*Note 11*: Informally, if A strongly happens before B, then A appears
4791
- to be evaluated before B in all contexts. Strongly happens before
4792
- excludes consume operations. — *end note*]
4793
 
4794
  A *visible side effect* A on a scalar object or bit-field M with respect
4795
  to a value computation B of M satisfies the conditions:
4796
 
4797
  - A happens before B and
4798
  - there is no other side effect X to M such that A happens before X and
4799
  X happens before B.
4800
 
4801
  The value of a non-atomic scalar object or bit-field M, as determined by
4802
- evaluation B, shall be the value stored by the visible side effect A.
4803
 
4804
- [*Note 12*: If there is ambiguity about which side effect to a
4805
  non-atomic object or bit-field is visible, then the behavior is either
4806
  unspecified or undefined. — *end note*]
4807
 
4808
- [*Note 13*: This states that operations on ordinary objects are not
4809
  visibly reordered. This is not actually detectable without data races,
4810
- but it is necessary to ensure that data races, as defined below, and
4811
- with suitable restrictions on the use of atomics, correspond to data
4812
- races in a simple interleaved (sequentially consistent)
4813
- execution. — *end note*]
4814
 
4815
- The value of an atomic object M, as determined by evaluation B, shall be
4816
- the value stored by some side effect A that modifies M, where B does not
4817
- happen before A.
4818
 
4819
- [*Note 14*: The set of such side effects is also restricted by the rest
4820
  of the rules described here, and in particular, by the coherence
4821
  requirements below. — *end note*]
4822
 
4823
  If an operation A that modifies an atomic object M happens before an
4824
- operation B that modifies M, then A shall be earlier than B in the
4825
  modification order of M.
4826
 
4827
- [*Note 15*: This requirement is known as write-write
4828
  coherence. — *end note*]
4829
 
4830
  If a value computation A of an atomic object M happens before a value
4831
  computation B of M, and A takes its value from a side effect X on M,
4832
- then the value computed by B shall either be the value stored by X or
4833
- the value stored by a side effect Y on M, where Y follows X in the
4834
  modification order of M.
4835
 
4836
- [*Note 16*: This requirement is known as read-read
4837
  coherence. — *end note*]
4838
 
4839
  If a value computation A of an atomic object M happens before an
4840
- operation B that modifies M, then A shall take its value from a side
4841
- effect X on M, where X precedes B in the modification order of M.
4842
 
4843
- [*Note 17*: This requirement is known as read-write
4844
  coherence. — *end note*]
4845
 
4846
  If a side effect X on an atomic object M happens before a value
4847
- computation B of M, then the evaluation B shall take its value from X or
4848
- from a side effect Y that follows X in the modification order of M.
4849
 
4850
- [*Note 18*: This requirement is known as write-read
4851
  coherence. — *end note*]
4852
 
4853
- [*Note 19*: The four preceding coherence requirements effectively
4854
  disallow compiler reordering of atomic operations to a single object,
4855
  even if both operations are relaxed loads. This effectively makes the
4856
  cache coherence guarantee provided by most hardware available to C++
4857
  atomic operations. — *end note*]
4858
 
4859
- [*Note 20*: The value observed by a load of an atomic depends on the
4860
  “happens before” relation, which depends on the values observed by loads
4861
  of atomics. The intended reading is that there must exist an association
4862
  of atomic loads with modifications they observe that, together with
4863
  suitably chosen modification orders and the “happens before” relation
4864
  derived as described above, satisfy the resulting constraints as imposed
@@ -4874,67 +5350,71 @@ The execution of a program contains a *data race* if it contains two
4874
  potentially concurrent conflicting actions, at least one of which is not
4875
  atomic, and neither happens before the other, except for the special
4876
  case for signal handlers described below. Any such data race results in
4877
  undefined behavior.
4878
 
4879
- [*Note 21*: It can be shown that programs that correctly use mutexes
4880
  and `memory_order::seq_cst` operations to prevent all data races and use
4881
  no other synchronization operations behave as if the operations executed
4882
  by their constituent threads were simply interleaved, with each value
4883
  computation of an object being taken from the last side effect on that
4884
  object in that interleaving. This is normally referred to as “sequential
4885
  consistency”. However, this applies only to data-race-free programs, and
4886
  data-race-free programs cannot observe most program transformations that
4887
  do not change single-threaded program semantics. In fact, most
4888
- single-threaded program transformations continue to be allowed, since
4889
- any program that behaves differently as a result has undefined
4890
  behavior. — *end note*]
4891
 
4892
- Two accesses to the same object of type `volatile std::sig_atomic_t` do
4893
- not result in a data race if both occur in the same thread, even if one
4894
- or more occurs in a signal handler. For each signal handler invocation,
4895
- evaluations performed by the thread invoking a signal handler can be
4896
- divided into two groups A and B, such that no evaluations in B happen
4897
- before evaluations in A, and the evaluations of such
4898
- `volatile std::sig_atomic_t` objects take values as though all
4899
- evaluations in A happened before the execution of the signal handler and
4900
- the execution of the signal handler happened before all evaluations in
4901
- B.
4902
 
4903
- [*Note 22*: Compiler transformations that introduce assignments to a
4904
  potentially shared memory location that would not be modified by the
4905
  abstract machine are generally precluded by this document, since such an
4906
  assignment might overwrite another assignment by a different thread in
4907
  cases in which an abstract machine execution would not have encountered
4908
  a data race. This includes implementations of data member assignment
4909
  that overwrite adjacent members in separate memory locations. Reordering
4910
  of atomic loads in cases in which the atomics in question might alias is
4911
  also generally precluded, since this could violate the coherence
4912
  rules. — *end note*]
4913
 
4914
- [*Note 23*: Transformations that introduce a speculative read of a
4915
- potentially shared memory location might not preserve the semantics of
4916
- the C++ program as defined in this document, since they potentially
4917
- introduce a data race. However, they are typically valid in the context
4918
- of an optimizing compiler that targets a specific machine with
4919
- well-defined semantics for data races. They would be invalid for a
4920
  hypothetical machine that is not tolerant of races or provides hardware
4921
  race detection. — *end note*]
4922
 
4923
  #### Forward progress <a id="intro.progress">[[intro.progress]]</a>
4924
 
4925
  The implementation may assume that any thread will eventually do one of
4926
  the following:
4927
 
4928
  - terminate,
 
4929
  - make a call to a library I/O function,
4930
- - perform an access through a volatile glvalue, or
4931
- - perform a synchronization operation or an atomic operation.
 
 
4932
 
4933
  [*Note 1*: This is intended to allow compiler transformations such as
4934
- removal of empty loops, even when termination cannot be
4935
- proven. *end note*]
 
4936
 
4937
  Executions of atomic functions that are either defined to be lock-free
4938
  [[atomics.flag]] or indicated as lock-free [[atomics.lockfree]] are
4939
  *lock-free executions*.
4940
 
@@ -4958,13 +5438,14 @@ Executions of atomic functions that are either defined to be lock-free
4958
 
4959
  During the execution of a thread of execution, each of the following is
4960
  termed an *execution step*:
4961
 
4962
  - termination of the thread of execution,
4963
- - performing an access through a volatile glvalue, or
4964
- - completion of a call to a library I/O function, a synchronization
4965
- operation, or an atomic operation.
 
4966
 
4967
  An invocation of a standard library function that blocks [[defns.block]]
4968
  is considered to continuously execute execution steps while waiting for
4969
  the condition that it blocks on to be satisfied.
4970
 
@@ -4986,12 +5467,12 @@ concurrent threads that are not blocked in a standard library function
4986
 
4987
  For a thread of execution providing *concurrent forward progress
4988
  guarantees*, the implementation ensures that the thread will eventually
4989
  make progress for as long as it has not terminated.
4990
 
4991
- [*Note 5*: This is required regardless of whether or not other threads
4992
- of execution (if any) have been or are making progress. To eventually
4993
  fulfill this requirement means that this will happen in an unspecified
4994
  but finite amount of time. — *end note*]
4995
 
4996
  It is *implementation-defined* whether the implementation-created thread
4997
  of execution that executes `main` [[basic.start.main]] and the threads
@@ -5104,24 +5585,24 @@ function parameter is called `argv`, where `argc` shall be the number of
5104
  arguments passed to the program from the environment in which the
5105
  program is run. If `argc` is nonzero these arguments shall be supplied
5106
  in `argv[0]` through `argv[argc - 1]` as pointers to the initial
5107
  characters of null-terminated multibyte strings (NTMBSs)
5108
  [[multibyte.strings]] and `argv[0]` shall be the pointer to the initial
5109
- character of a NTMBS that represents the name used to invoke the program
5110
- or `""`. The value of `argc` shall be non-negative. The value of
5111
  `argv[argc]` shall be 0.
5112
 
5113
  *Recommended practice:* Any further (optional) parameters should be
5114
  added after `argv`.
5115
 
5116
- The function `main` shall not be used within a program. The linkage
5117
  [[basic.link]] of `main` is *implementation-defined*. A program that
5118
  defines `main` as deleted or that declares `main` to be `inline`,
5119
  `static`, `constexpr`, or `consteval` is ill-formed. The function `main`
5120
  shall not be a coroutine [[dcl.fct.def.coroutine]]. The `main` function
5121
- shall not be declared with a *linkage-specification* [[dcl.link]]. A
5122
- program that declares
5123
 
5124
  - a variable `main` that belongs to the global scope, or
5125
  - a function `main` that belongs to the global scope and is attached to
5126
  a named module, or
5127
  - a function template `main` that belongs to the global scope, or
@@ -5137,29 +5618,29 @@ calling the function `std::exit(int)` [[support.start.term]]) does not
5137
  destroy any objects with automatic storage duration [[class.dtor]]. If
5138
  `std::exit` is invoked during the destruction of an object with static
5139
  or thread storage duration, the program has undefined behavior.
5140
 
5141
  A `return` statement [[stmt.return]] in `main` has the effect of leaving
5142
- the main function (destroying any objects with automatic storage
5143
- duration) and calling `std::exit` with the return value as the argument.
5144
- If control flows off the end of the *compound-statement* of `main`, the
5145
- effect is equivalent to a `return` with operand `0` (see also
5146
- [[except.handle]]).
5147
 
5148
  #### Static initialization <a id="basic.start.static">[[basic.start.static]]</a>
5149
 
5150
  Variables with static storage duration are initialized as a consequence
5151
  of program initiation. Variables with thread storage duration are
5152
  initialized as a consequence of thread execution. Within each of these
5153
  phases of initiation, initialization occurs as follows.
5154
 
5155
- *Constant initialization* is performed if a variable or temporary object
5156
- with static or thread storage duration is constant-initialized
5157
- [[expr.const]]. If constant initialization is not performed, a variable
5158
- with static storage duration [[basic.stc.static]] or thread storage
5159
- duration [[basic.stc.thread]] is zero-initialized [[dcl.init]].
5160
- Together, zero-initialization and constant initialization are called
5161
  *static initialization*; all other initialization is
5162
  *dynamic initialization*. All static initialization strongly happens
5163
  before [[intro.races]] any dynamic initialization.
5164
 
5165
  [*Note 1*: The dynamic initialization of non-block variables is
@@ -5252,11 +5733,11 @@ thread storage duration variable.
5252
  It is *implementation-defined* whether the dynamic initialization of a
5253
  non-block non-inline variable with static storage duration is sequenced
5254
  before the first statement of `main` or is deferred. If it is deferred,
5255
  it strongly happens before any non-initialization odr-use of any
5256
  non-inline function or non-inline variable defined in the same
5257
- translation unit as the variable to be initialized.[^25]
5258
 
5259
  It is *implementation-defined* in which threads and at which points in
5260
  the program such deferred dynamic initialization occurs.
5261
 
5262
  *Recommended practice:* An implementation should choose such points in a
@@ -5392,21 +5873,298 @@ static-storage-duration objects. — *end note*]
5392
 
5393
  Calling the function `std::abort()` declared in `<cstdlib>` terminates
5394
  the program without executing any destructors and without calling the
5395
  functions passed to `std::atexit()` or `std::at_quick_exit()`.
5396
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5397
  <!-- Link reference definitions -->
5398
  [allocator.members]: mem.md#allocator.members
5399
- [allocator.traits.members]: mem.md#allocator.traits.members
5400
  [atomics]: thread.md#atomics
5401
  [atomics.flag]: thread.md#atomics.flag
5402
  [atomics.lockfree]: thread.md#atomics.lockfree
5403
  [atomics.order]: thread.md#atomics.order
5404
  [bad.alloc]: support.md#bad.alloc
5405
  [basic]: #basic
5406
  [basic.align]: #basic.align
5407
  [basic.compound]: #basic.compound
 
 
 
 
5408
  [basic.def]: #basic.def
5409
  [basic.def.odr]: #basic.def.odr
5410
  [basic.exec]: #basic.exec
5411
  [basic.extended.fp]: #basic.extended.fp
5412
  [basic.fundamental]: #basic.fundamental
@@ -5423,21 +6181,24 @@ functions passed to `std::atexit()` or `std::at_quick_exit()`.
5423
  [basic.lookup.udir]: #basic.lookup.udir
5424
  [basic.lookup.unqual]: #basic.lookup.unqual
5425
  [basic.lval]: expr.md#basic.lval
5426
  [basic.memobj]: #basic.memobj
5427
  [basic.namespace]: dcl.md#basic.namespace
 
5428
  [basic.pre]: #basic.pre
5429
  [basic.scope]: #basic.scope
5430
  [basic.scope.block]: #basic.scope.block
5431
  [basic.scope.class]: #basic.scope.class
 
5432
  [basic.scope.enum]: #basic.scope.enum
5433
  [basic.scope.lambda]: #basic.scope.lambda
5434
  [basic.scope.namespace]: #basic.scope.namespace
5435
  [basic.scope.param]: #basic.scope.param
5436
  [basic.scope.pdecl]: #basic.scope.pdecl
5437
  [basic.scope.scope]: #basic.scope.scope
5438
  [basic.scope.temp]: #basic.scope.temp
 
5439
  [basic.start]: #basic.start
5440
  [basic.start.dynamic]: #basic.start.dynamic
5441
  [basic.start.main]: #basic.start.main
5442
  [basic.start.static]: #basic.start.static
5443
  [basic.start.term]: #basic.start.term
@@ -5446,11 +6207,10 @@ functions passed to `std::atexit()` or `std::at_quick_exit()`.
5446
  [basic.stc.dynamic]: #basic.stc.dynamic
5447
  [basic.stc.dynamic.allocation]: #basic.stc.dynamic.allocation
5448
  [basic.stc.dynamic.deallocation]: #basic.stc.dynamic.deallocation
5449
  [basic.stc.dynamic.general]: #basic.stc.dynamic.general
5450
  [basic.stc.general]: #basic.stc.general
5451
- [basic.stc.inherit]: #basic.stc.inherit
5452
  [basic.stc.static]: #basic.stc.static
5453
  [basic.stc.thread]: #basic.stc.thread
5454
  [basic.type.qualifier]: #basic.type.qualifier
5455
  [basic.type.qualifier.rel]: #basic.type.qualifier.rel
5456
  [basic.types]: #basic.types
@@ -5468,17 +6228,17 @@ functions passed to `std::atexit()` or `std::at_quick_exit()`.
5468
  [class.copy.assign]: class.md#class.copy.assign
5469
  [class.copy.ctor]: class.md#class.copy.ctor
5470
  [class.copy.elision]: class.md#class.copy.elision
5471
  [class.default.ctor]: class.md#class.default.ctor
5472
  [class.derived]: class.md#class.derived
 
5473
  [class.dtor]: class.md#class.dtor
5474
  [class.free]: class.md#class.free
5475
  [class.friend]: class.md#class.friend
5476
  [class.mem]: class.md#class.mem
 
5477
  [class.member.lookup]: #class.member.lookup
5478
- [class.mfct]: class.md#class.mfct
5479
- [class.mfct.non.static]: class.md#class.mfct.non.static
5480
  [class.name]: class.md#class.name
5481
  [class.pre]: class.md#class.pre
5482
  [class.prop]: class.md#class.prop
5483
  [class.qual]: #class.qual
5484
  [class.spaceship]: class.md#class.spaceship
@@ -5494,34 +6254,42 @@ functions passed to `std::atexit()` or `std::at_quick_exit()`.
5494
  [conv.integral]: expr.md#conv.integral
5495
  [conv.lval]: expr.md#conv.lval
5496
  [conv.mem]: expr.md#conv.mem
5497
  [conv.prom]: expr.md#conv.prom
5498
  [conv.ptr]: expr.md#conv.ptr
 
5499
  [conv.rank]: #conv.rank
5500
  [conv.rval]: expr.md#conv.rval
5501
  [cpp.predefined]: cpp.md#cpp.predefined
 
 
5502
  [cstddef.syn]: support.md#cstddef.syn
5503
  [cstring.syn]: strings.md#cstring.syn
5504
  [dcl.align]: dcl.md#dcl.align
5505
  [dcl.array]: dcl.md#dcl.array
5506
  [dcl.attr]: dcl.md#dcl.attr
 
 
5507
  [dcl.attr.nouniqueaddr]: dcl.md#dcl.attr.nouniqueaddr
5508
  [dcl.constexpr]: dcl.md#dcl.constexpr
5509
- [dcl.dcl]: dcl.md#dcl.dcl
 
5510
  [dcl.decl]: dcl.md#dcl.decl
5511
  [dcl.enum]: dcl.md#dcl.enum
5512
  [dcl.fct]: dcl.md#dcl.fct
5513
  [dcl.fct.def]: dcl.md#dcl.fct.def
5514
  [dcl.fct.def.coroutine]: dcl.md#dcl.fct.def.coroutine
5515
  [dcl.fct.def.general]: dcl.md#dcl.fct.def.general
5516
  [dcl.fct.default]: dcl.md#dcl.fct.default
5517
  [dcl.init]: dcl.md#dcl.init
5518
  [dcl.init.aggr]: dcl.md#dcl.init.aggr
 
5519
  [dcl.init.list]: dcl.md#dcl.init.list
5520
  [dcl.init.ref]: dcl.md#dcl.init.ref
5521
  [dcl.link]: dcl.md#dcl.link
5522
  [dcl.meaning]: dcl.md#dcl.meaning
 
5523
  [dcl.mptr]: dcl.md#dcl.mptr
5524
  [dcl.name]: dcl.md#dcl.name
5525
  [dcl.pre]: dcl.md#dcl.pre
5526
  [dcl.ptr]: dcl.md#dcl.ptr
5527
  [dcl.ref]: dcl.md#dcl.ref
@@ -5530,10 +6298,11 @@ functions passed to `std::atexit()` or `std::at_quick_exit()`.
5530
  [dcl.stc]: dcl.md#dcl.stc
5531
  [dcl.struct.bind]: dcl.md#dcl.struct.bind
5532
  [dcl.type.decltype]: dcl.md#dcl.type.decltype
5533
  [dcl.type.elab]: dcl.md#dcl.type.elab
5534
  [dcl.typedef]: dcl.md#dcl.typedef
 
5535
  [defns.block]: intro.md#defns.block
5536
  [depr.local]: future.md#depr.local
5537
  [depr.static.constexpr]: future.md#depr.static.constexpr
5538
  [diff.cpp11.basic]: compatibility.md#diff.cpp11.basic
5539
  [enum.udecl]: dcl.md#enum.udecl
@@ -5543,11 +6312,11 @@ functions passed to `std::atexit()` or `std::at_quick_exit()`.
5543
  [except.terminate]: except.md#except.terminate
5544
  [except.throw]: except.md#except.throw
5545
  [expr.add]: expr.md#expr.add
5546
  [expr.alignof]: expr.md#expr.alignof
5547
  [expr.arith.conv]: expr.md#expr.arith.conv
5548
- [expr.ass]: expr.md#expr.ass
5549
  [expr.await]: expr.md#expr.await
5550
  [expr.call]: expr.md#expr.call
5551
  [expr.cast]: expr.md#expr.cast
5552
  [expr.comma]: expr.md#expr.comma
5553
  [expr.cond]: expr.md#expr.cond
@@ -5555,57 +6324,67 @@ functions passed to `std::atexit()` or `std::at_quick_exit()`.
5555
  [expr.const.cast]: expr.md#expr.const.cast
5556
  [expr.context]: expr.md#expr.context
5557
  [expr.delete]: expr.md#expr.delete
5558
  [expr.dynamic.cast]: expr.md#expr.dynamic.cast
5559
  [expr.eq]: expr.md#expr.eq
5560
- [expr.log.and]: expr.md#expr.log.and
5561
- [expr.log.or]: expr.md#expr.log.or
5562
  [expr.mptr.oper]: expr.md#expr.mptr.oper
5563
  [expr.new]: expr.md#expr.new
5564
  [expr.pre]: expr.md#expr.pre
5565
  [expr.prim.id]: expr.md#expr.prim.id
 
5566
  [expr.prim.id.qual]: expr.md#expr.prim.id.qual
5567
  [expr.prim.id.unqual]: expr.md#expr.prim.id.unqual
5568
  [expr.prim.lambda]: expr.md#expr.prim.lambda
5569
  [expr.prim.lambda.capture]: expr.md#expr.prim.lambda.capture
5570
  [expr.prim.lambda.closure]: expr.md#expr.prim.lambda.closure
 
5571
  [expr.prim.this]: expr.md#expr.prim.this
5572
  [expr.prop]: expr.md#expr.prop
5573
  [expr.ref]: expr.md#expr.ref
 
5574
  [expr.reinterpret.cast]: expr.md#expr.reinterpret.cast
5575
  [expr.rel]: expr.md#expr.rel
5576
  [expr.sizeof]: expr.md#expr.sizeof
5577
  [expr.static.cast]: expr.md#expr.static.cast
5578
  [expr.sub]: expr.md#expr.sub
 
5579
  [expr.type.conv]: expr.md#expr.type.conv
5580
  [expr.typeid]: expr.md#expr.typeid
 
5581
  [expr.unary.op]: expr.md#expr.unary.op
5582
  [get.new.handler]: support.md#get.new.handler
5583
  [headers]: library.md#headers
 
 
5584
  [intro.execution]: #intro.execution
5585
  [intro.memory]: #intro.memory
5586
  [intro.multithread]: #intro.multithread
5587
  [intro.multithread.general]: #intro.multithread.general
5588
  [intro.object]: #intro.object
5589
  [intro.progress]: #intro.progress
5590
  [intro.races]: #intro.races
5591
  [lex.charset]: lex.md#lex.charset
5592
  [lex.fcon]: lex.md#lex.fcon
5593
  [lex.name]: lex.md#lex.name
5594
- [lex.separate]: lex.md#lex.separate
 
 
 
 
 
5595
  [module.context]: module.md#module.context
5596
  [module.global.frag]: module.md#module.global.frag
5597
  [module.interface]: module.md#module.interface
5598
  [module.reach]: module.md#module.reach
5599
  [module.unit]: module.md#module.unit
5600
  [multibyte.strings]: library.md#multibyte.strings
 
5601
  [namespace.def]: dcl.md#namespace.def
5602
  [namespace.qual]: #namespace.qual
5603
  [namespace.udecl]: dcl.md#namespace.udecl
5604
  [namespace.udir]: dcl.md#namespace.udir
5605
  [namespace.unnamed]: dcl.md#namespace.unnamed
5606
- [new.delete]: support.md#new.delete
5607
  [new.delete.array]: support.md#new.delete.array
5608
  [new.delete.placement]: support.md#new.delete.placement
5609
  [new.delete.single]: support.md#new.delete.single
5610
  [new.handler]: support.md#new.handler
5611
  [new.syn]: support.md#new.syn
@@ -5616,32 +6395,37 @@ functions passed to `std::atexit()` or `std::at_quick_exit()`.
5616
  [over.match.funcs]: over.md#over.match.funcs
5617
  [over.oper]: over.md#over.oper
5618
  [over.over]: over.md#over.over
5619
  [ptr.align]: mem.md#ptr.align
5620
  [ptr.launder]: support.md#ptr.launder
5621
- [replacement.functions]: library.md#replacement.functions
5622
  [special]: class.md#special
5623
  [std.modules]: library.md#std.modules
5624
  [stdfloat.syn]: support.md#stdfloat.syn
5625
  [stmt.block]: stmt.md#stmt.block
 
5626
  [stmt.dcl]: stmt.md#stmt.dcl
 
5627
  [stmt.expr]: stmt.md#stmt.expr
5628
  [stmt.if]: stmt.md#stmt.if
5629
  [stmt.iter]: stmt.md#stmt.iter
 
5630
  [stmt.pre]: stmt.md#stmt.pre
5631
  [stmt.ranged]: stmt.md#stmt.ranged
5632
  [stmt.return]: stmt.md#stmt.return
5633
  [stmt.select]: stmt.md#stmt.select
 
5634
  [support.dynamic]: support.md#support.dynamic
5635
  [support.runtime]: support.md#support.runtime
5636
  [support.start.term]: support.md#support.start.term
5637
  [support.types]: support.md#support.types
 
5638
  [temp.concept]: temp.md#temp.concept
5639
  [temp.deduct.guide]: temp.md#temp.deduct.guide
5640
  [temp.dep]: temp.md#temp.dep
5641
  [temp.dep.candidate]: temp.md#temp.dep.candidate
5642
  [temp.dep.constexpr]: temp.md#temp.dep.constexpr
 
5643
  [temp.dep.type]: temp.md#temp.dep.type
5644
  [temp.expl.spec]: temp.md#temp.expl.spec
5645
  [temp.explicit]: temp.md#temp.explicit
5646
  [temp.friend]: temp.md#temp.friend
5647
  [temp.local]: temp.md#temp.local
@@ -5652,17 +6436,21 @@ functions passed to `std::atexit()` or `std::at_quick_exit()`.
5652
  [temp.point]: temp.md#temp.point
5653
  [temp.pre]: temp.md#temp.pre
5654
  [temp.res]: temp.md#temp.res
5655
  [temp.spec]: temp.md#temp.spec
5656
  [temp.spec.partial]: temp.md#temp.spec.partial
 
5657
  [temp.type]: temp.md#temp.type
 
5658
  [term.incomplete.type]: #term.incomplete.type
5659
  [term.odr.use]: #term.odr.use
 
5660
  [term.unevaluated.operand]: expr.md#term.unevaluated.operand
5661
  [thread]: thread.md#thread
5662
  [thread.jthread.class]: thread.md#thread.jthread.class
5663
  [thread.thread.class]: thread.md#thread.thread.class
 
5664
  [thread.threads]: thread.md#thread.threads
5665
 
5666
  [^1]: Appearing inside the brace-enclosed *declaration-seq* in a
5667
  *linkage-specification* does not affect whether a declaration is a
5668
  definition.
@@ -5676,81 +6464,76 @@ functions passed to `std::atexit()` or `std::at_quick_exit()`.
5676
 
5677
  [^4]: Lookups in which function names are ignored include names
5678
  appearing in a *nested-name-specifier*, an
5679
  *elaborated-type-specifier*, or a *base-specifier*.
5680
 
5681
- [^5]: Unicode® is a registered trademark of Unicode, Inc. This
5682
- information is given for the convenience of users of this document
5683
- and does not constitute an endorsement by ISO or IEC of this
5684
- product.
5685
-
5686
- [^6]: The number of bits in a byte is reported by the macro `CHAR_BIT`
5687
  in the header `<climits>`.
5688
 
5689
- [^7]: Under the “as-if” rule an implementation is allowed to store two
5690
  objects at the same machine address or not store an object at all if
5691
  the program cannot observe the difference [[intro.execution]].
5692
 
5693
- [^8]: For example, before the dynamic initialization of an object with
5694
  static storage duration [[basic.start.dynamic]].
5695
 
5696
- [^9]: That is, an object for which a destructor will be called
5697
  implicitly—upon exit from the block for an object with automatic
5698
  storage duration, upon exit from the thread for an object with
5699
  thread storage duration, or upon exit from the program for an object
5700
  with static storage duration.
5701
 
5702
- [^10]: Some implementations might define that copying an invalid pointer
5703
- value causes a system-generated runtime fault.
5704
-
5705
- [^11]: The intent is to have `operator new()` implementable by calling
5706
  `std::malloc()` or `std::calloc()`, so the rules are substantially
5707
  the same. C++ differs from C in requiring a zero request to return a
5708
  non-null pointer.
5709
 
5710
- [^12]: The global `operator delete(void*, std::size_t)` precludes use of
5711
  an allocation function `void operator new(std::size_t, std::size_t)`
5712
  as a placement allocation function [[diff.cpp11.basic]].
5713
 
5714
- [^13]: The same rules apply to initialization of an `initializer_list`
5715
  object [[dcl.init.list]] with its underlying temporary array.
5716
 
5717
- [^14]: By using, for example, the library functions [[headers]]
5718
  `std::memcpy` or `std::memmove`.
5719
 
5720
- [^15]: By using, for example, the library functions [[headers]]
5721
  `std::memcpy` or `std::memmove`.
5722
 
5723
- [^16]: The intent is that the memory model of C++ is compatible with
5724
- that of ISO/IEC 9899 Programming Language C.
5725
 
5726
- [^17]: The size and layout of an instance of an incompletely-defined
5727
  object type is unknown.
5728
 
5729
- [^18]: This is also known as two’s complement representation.
5730
 
5731
- [^19]: Static class members are objects or functions, and pointers to
5732
  them are ordinary pointers to objects or functions.
5733
 
5734
- [^20]: For an object that is not within its lifetime, this is the first
5735
  byte in memory that it will occupy or used to occupy.
5736
 
5737
- [^21]: The same representation and alignment requirements are meant to
 
 
 
5738
  imply interchangeability as arguments to functions, return values
5739
  from functions, and non-static data members of unions.
5740
 
5741
- [^22]: As specified in  [[class.temporary]], after a full-expression is
5742
  evaluated, a sequence of zero or more invocations of destructor
5743
  functions for temporary objects takes place, usually in reverse
5744
  order of the construction of each temporary object.
5745
 
5746
- [^23]: In other words, function executions do not interleave with each
5747
  other.
5748
 
5749
- [^24]: An object with automatic or thread storage duration [[basic.stc]]
5750
  is associated with one specific thread, and can be accessed by a
5751
  different thread only indirectly through a pointer or reference
5752
  [[basic.compound]].
5753
 
5754
- [^25]: A non-block variable with static storage duration having
5755
  initialization with side effects is initialized in this case, even
5756
  if it is not itself odr-used [[term.odr.use]], [[basic.stc.static]].
 
13
 
14
  [*Note 2*: This Clause does not cover concepts that affect only a
15
  single part of the language. Such concepts are discussed in the relevant
16
  Clauses. — *end note*]
17
 
18
+ A *name* is an *identifier* [[lex.name]], *conversion-function-id*
19
+ [[class.conv.fct]], *operator-function-id* [[over.oper]], or
20
+ *literal-operator-id* [[over.literal]].
21
 
22
+ Two names are *the same* if
23
+
24
+ - they are *identifier*s composed of the same character sequence, or
25
+ - they are *conversion-function-id*s formed with equivalent
26
+ [[temp.over.link]] types, or
27
+ - they are *operator-function-id*s formed with the same operator, or
28
+ - they are *literal-operator-id*s formed with the same literal suffix
29
+ identifier.
30
 
31
  Every name is introduced by a *declaration*, which is a
32
 
33
  - *name-declaration*, *block-declaration*, or *member-declaration*
34
  [[dcl.pre]], [[class.mem]],
35
  - *init-declarator* [[dcl.decl]],
36
  - *identifier* in a structured binding declaration [[dcl.struct.bind]],
37
+ - *identifier* in a *result-name-introducer* in a postcondition
38
+ assertion [[dcl.contract.res]],
39
  - *init-capture* [[expr.prim.lambda.capture]],
40
  - *condition* with a *declarator* [[stmt.pre]],
41
  - *member-declarator* [[class.mem]],
42
  - *using-declarator* [[namespace.udecl]],
43
+ - *parameter-declaration* [[dcl.fct]], [[temp.param]],
44
  - *type-parameter* [[temp.param]],
45
+ - *type-tt-parameter* [[temp.param]],
46
+ - *variable-tt-parameter* [[temp.param]],
47
+ - *concept-tt-parameter* [[temp.param]],
48
  - *elaborated-type-specifier* that introduces a name [[dcl.type.elab]],
49
  - *class-specifier* [[class.pre]],
50
  - *enum-specifier* or *enumerator-definition* [[dcl.enum]],
51
  - *exception-declaration* [[except.pre]], or
52
  - implicit declaration of an injected-class-name [[class.pre]].
53
 
54
+ [*Note 3*: The term declaration is not a synonym for the grammar
55
+ non-terminal *declaration* [[dcl.pre]]. — *end note*]
56
+
57
+ [*Note 4*: The interpretation of a *for-range-declaration* produces one
58
  or more of the above [[stmt.ranged]]. — *end note*]
59
 
60
+ [*Note 5*: Some names denote types or templates. In general, whenever a
61
+ name is encountered it is necessary to look it up [[basic.lookup]] to
62
+ determine whether that name denotes one of these entities before
63
+ continuing to parse the program that contains it. — *end note*]
64
 
65
+ A *variable* is introduced by the declaration of
66
+
67
+ - a reference other than a non-static data member or
68
+ - an object.
69
+
70
+ An *entity* is a variable, structured binding, result binding, function,
71
+ enumerator, type, type alias, non-static data member, bit-field,
72
+ template, namespace, namespace alias, template parameter, function
73
+ parameter, or *init-capture*. The *underlying entity* of an entity is
74
+ that entity unless otherwise specified. A name *denotes* the underlying
75
+ entity of the entity declared by each declaration that introduces the
76
+ name.
77
+
78
+ [*Note 6*: Type aliases and namespace aliases have underlying entities
79
+ that are distinct from themselves. — *end note*]
80
 
81
  A *local entity* is a variable with automatic storage duration
82
  [[basic.stc.auto]], a structured binding [[dcl.struct.bind]] whose
83
+ corresponding variable is such an entity, a result binding
84
+ [[dcl.contract.res]], or the `*this` object [[expr.prim.this]].
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
  A name used in more than one translation unit can potentially refer to
87
  the same entity in these translation units depending on the linkage
88
  [[basic.link]] of the name specified in each translation unit.
89
 
90
  ## Declarations and definitions <a id="basic.def">[[basic.def]]</a>
91
 
92
+ A declaration [[basic.pre]] may (re)introduce one or more names and/or
93
  entities into a translation unit. If so, the declaration specifies the
94
  interpretation and semantic properties of these names. A declaration of
95
+ an entity X is a redeclaration of X if another declaration of X is
96
+ reachable from it [[module.reach]]; otherwise, it is a
97
+ *first declaration*.
98
+
99
+ [*Note 1*:
100
+
101
+ A declaration can also have effects including:
102
 
103
  - a static assertion [[dcl.pre]],
104
  - controlling template instantiation [[temp.explicit]],
105
  - guiding template argument deduction for constructors
106
  [[temp.deduct.guide]],
107
  - use of attributes [[dcl.attr]], and
108
  - nothing (in the case of an *empty-declaration*).
109
 
110
+ *end note*]
111
+
112
+ Each entity declared by a declaration is also *defined* by that
113
  declaration unless:
114
 
115
  - it declares a function without specifying the function’s body
116
  [[dcl.fct.def]],
117
  - it contains the `extern` specifier [[dcl.stc]] or a
 
119
  nor a *function-body*,
120
  - it declares a non-inline static data member in a class definition
121
  [[class.mem]], [[class.static]],
122
  - it declares a static data member outside a class definition and the
123
  variable was defined within the class with the `constexpr` specifier
124
+ [[class.static.data]] (this usage is deprecated; see
125
+ [[depr.static.constexpr]]),
126
  - it is an *elaborated-type-specifier* [[class.name]],
127
  - it is an *opaque-enum-declaration* [[dcl.enum]],
128
  - it is a *template-parameter* [[temp.param]],
129
  - it is a *parameter-declaration* [[dcl.fct]] in a function declarator
130
  that is not the *declarator* of a *function-definition*,
131
  - it is a `typedef` declaration [[dcl.typedef]],
132
  - it is an *alias-declaration* [[dcl.typedef]],
133
+ - it is a *namespace-alias-definition* [[namespace.alias]],
134
  - it is a *using-declaration* [[namespace.udecl]],
135
  - it is a *deduction-guide* [[temp.deduct.guide]],
136
  - it is a *static_assert-declaration* [[dcl.pre]],
137
+ - it is a *consteval-block-declaration*,
138
  - it is an *attribute-declaration* [[dcl.pre]],
139
  - it is an *empty-declaration* [[dcl.pre]],
140
  - it is a *using-directive* [[namespace.udir]],
141
  - it is a *using-enum-declaration* [[enum.udecl]],
142
  - it is a *template-declaration* [[temp.pre]] whose *template-head* is
143
  not followed by either a *concept-definition* or a *declaration* that
144
+ defines a function, a class, a variable, or a static data member,
145
  - it is an explicit instantiation declaration [[temp.explicit]], or
146
  - it is an explicit specialization [[temp.expl.spec]] whose
147
  *declaration* is not a definition.
148
 
149
  A declaration is said to be a *definition* of each entity that it
 
164
  X(): x(0) { } // defines a constructor of X
165
  };
166
  int X::y = 1; // defines X::y
167
  enum { up, down }; // defines up and down
168
  namespace N { int d; } // defines N and N::d
 
169
  X anX; // defines anX
170
  ```
171
 
172
  whereas these are just declarations:
173
 
 
175
  extern int a; // declares a
176
  extern const int c; // declares c
177
  int f(int); // declares f
178
  struct S; // declares S
179
  typedef int Int; // declares Int
180
+ namespace N1 = N; // declares N1
181
  extern X anotherX; // declares anotherX
182
  using N::d; // declares d
183
  ```
184
 
185
  — *end example*]
186
 
187
+ [*Note 2*: In some circumstances, C++ implementations implicitly
188
  define the default constructor [[class.default.ctor]], copy constructor,
189
  move constructor [[class.copy.ctor]], copy assignment operator, move
190
  assignment operator [[class.copy.assign]], or destructor [[class.dtor]]
191
  member functions. — *end note*]
192
 
 
225
  };
226
  ```
227
 
228
  — *end example*]
229
 
230
+ [*Note 3*: A class name can also be implicitly declared by an
231
  *elaborated-type-specifier* [[dcl.type.elab]]. — *end note*]
232
 
233
  In the definition of an object, the type of that object shall not be an
234
  incomplete type [[term.incomplete.type]], an abstract class type
235
  [[class.abstract]], or a (possibly multidimensional) array thereof.
 
254
  unevaluated operand [[expr.context]], a subexpression thereof, or a
255
  conversion in an initialization or conversion sequence in such a
256
  context. The set of *potential results* of an expression E is defined as
257
  follows:
258
 
259
+ - If E is an *id-expression* [[expr.prim.id]] or a *splice-expression*
260
+ [[expr.prim.splice]], the set contains only E.
261
  - If E is a subscripting operation [[expr.sub]] with an array operand,
262
  the set contains the potential results of that operand.
263
  - If E is a class member access expression [[expr.ref]] of the form E₁
264
  `.` `template`ₒₚₜ E₂ naming a non-static data member, the set
265
  contains the potential results of E₁.
 
276
  potential results of the right operand.
277
  - Otherwise, the set is empty.
278
 
279
  [*Note 1*:
280
 
281
+ This set is a (possibly-empty) set of *id-expression*s and
282
+ *splice-expression*s, each of which is either E or a subexpression of E.
283
 
284
  [*Example 1*:
285
 
286
  In the following example, the set of potential results of the
287
  initializer of `n` contains the first `S::x` subexpression, but not the
288
+ second `S::x` subexpression. The set of potential results of the
289
+ initializer of `o` contains the subexpression `[:^^ S::x:]`.
290
 
291
  ``` cpp
292
  struct S { static const int x = 0; };
293
  const int &f(const int &r);
294
  int n = b ? (1, S::x) // S::x is not odr-used here
295
  : f(S::x); // S::x is odr-used here, so a definition is required
296
+ int o = [:^^S::x:];
297
  ```
298
 
299
  — *end example*]
300
 
301
  — *end note*]
 
304
 
305
  - A function is named by an expression or conversion if it is the
306
  selected member of an overload set
307
  [[basic.lookup]], [[over.match]], [[over.over]] in an overload
308
  resolution performed as part of forming that expression or conversion,
309
+ and either it is not a pure virtual function or the expression is an
310
+ *id-expression* naming the function with an explicitly qualified name
311
+ that does not form a pointer to member [[expr.unary.op]].
312
  \[*Note 2*: This covers taking the address of functions
313
  [[conv.func]], [[expr.unary.op]], calls to named functions
314
  [[expr.call]], operator overloading [[over]], user-defined conversions
315
  [[class.conv.fct]], allocation functions for *new-expression*s
316
  [[expr.new]], as well as non-default initialization [[dcl.init]]. A
 
325
  - A deallocation function for a class is named by a *delete-expression*
326
  if it is the selected usual deallocation function as specified in 
327
  [[expr.delete]] and  [[class.free]].
328
 
329
  A variable is named by an expression if the expression is an
330
+ *id-expression* or *splice-expression* [[expr.prim.splice]] that
331
+ designates it. A variable `x` that is named by a potentially-evaluated
332
+ expression N that appears at a point P is *odr-used* by N unless
333
 
334
+ - `x` is a reference that is usable in constant expressions at P
335
+ [[expr.const]] or
336
+ - N is an element of the set of potential results of an expression E,
337
+ where
338
+ - E is a discarded-value expression [[expr.context]] to which the
339
+ lvalue-to-rvalue conversion is not applied or
340
+ - `x` is a non-volatile object that is usable in constant expressions
341
+ at P and has no mutable subobjects and
342
+ - E is a class member access expression [[expr.ref]] naming a
343
+ non-static data member of reference type and whose object
344
+ expression has non-volatile-qualified type or
345
+ - the lvalue-to-rvalue conversion [[conv.lval]] is applied to E and
346
+ E has non-volatile-qualified non-class type
347
 
348
+ [*Example 2*:
349
+
350
+ ``` cpp
351
+ int f(int);
352
+ int g(int&);
353
+ struct A {
354
+ int x;
355
+ };
356
+ struct B {
357
+ int& r;
358
+ };
359
+ int h(bool cond) {
360
+ constexpr A a = {1};
361
+ constexpr const volatile A& r = a; // odr-uses a
362
+ int _ = f(cond ? a.x : r.x); // does not odr-use a or r
363
+ int x, y;
364
+ constexpr B b1 = {x}, b2 = {y}; // odr-uses x and y
365
+ int _ = g(cond ? b1.r : b2.r); // does not odr-use b1 or b2
366
+ int _ = ((cond ? x : y), 0); // does not odr-use x or y
367
+ return [] {
368
+ return b1.r; // error: b1 is odr-used here because the object
369
+ // referred to by b1.r is not constexpr-referenceable here
370
+ }();
371
+ }
372
+ ```
373
+
374
+ — *end example*]
375
+
376
+ A structured binding is named by an expression if that expression is
377
+ either an *id-expression* or a *splice-expression* that designates that
378
+ structured binding. A structured binding is odr-used if it is named by a
379
  potentially-evaluated expression.
380
 
381
  `*this` is odr-used if `this` appears as a potentially-evaluated
382
+ expression (including as the result of any implicit transformation to a
383
+ class member access expression [[expr.prim.id.general]]).
384
 
385
  A virtual member function is odr-used if it is not pure. A function is
386
  odr-used if it is named by a potentially-evaluated expression or
387
  conversion. A non-placement allocation or deallocation function for a
388
  class is odr-used by the definition of a constructor of that class. A
 
390
  definition of the destructor of that class, or by being selected by the
391
  lookup at the point of definition of a virtual destructor
392
  [[class.dtor]].[^2]
393
 
394
  An assignment operator function in a class is odr-used by an
395
+ implicitly-defined copy assignment or move assignment function for
396
  another class as specified in  [[class.copy.assign]]. A constructor for
397
  a class is odr-used as specified in  [[dcl.init]]. A destructor for a
398
  class is odr-used if it is potentially invoked [[class.dtor]].
399
 
400
  A local entity [[basic.pre]] is *odr-usable* in a scope
401
+ [[basic.scope.scope]] if
402
 
403
  - either the local entity is not `*this`, or an enclosing class or
404
  non-lambda function parameter scope exists and, if the innermost such
405
  scope is a function parameter scope, it corresponds to a non-static
406
  member function, and
407
  - for each intervening scope [[basic.scope.scope]] between the point at
408
  which the entity is introduced and the scope (where `*this` is
409
  considered to be introduced within the innermost enclosing class or
410
+ non-lambda function definition scope), either
411
+ - the intervening scope is a block scope,
412
+ - the intervening scope is a contract-assertion scope
413
+ [[basic.scope.contract]],
414
  - the intervening scope is the function parameter scope of a
415
+ *lambda-expression* or *requires-expression*, or
416
+ - the intervening scope is the lambda scope of a *lambda-expression*
417
+ that has a *simple-capture* naming the entity or has a
418
+ *capture-default*, and the block scope of the *lambda-expression* is
419
+ also an intervening scope.
420
 
421
  If a local entity is odr-used in a scope in which it is not odr-usable,
422
  the program is ill-formed.
423
 
424
+ [*Example 3*:
425
 
426
  ``` cpp
427
  void f(int n) {
428
  [] { n = 1; }; // error: n is not odr-usable due to intervening lambda-expression
429
  struct A {
 
436
  }
437
  ```
438
 
439
  — *end example*]
440
 
441
+ [*Example 4*:
442
+
443
+ ``` cpp
444
+ void g() {
445
+ constexpr int x = 1;
446
+ auto lambda = [] <typename T, int = ((T)x, 0)> {}; // OK
447
+ lambda.operator()<int, 1>(); // OK, does not consider x at all
448
+ lambda.operator()<int>(); // OK, does not odr-use x
449
+ lambda.operator()<const int&>(); // error: odr-uses x from a context where x is not odr-usable
450
+ }
451
+
452
+ void h() {
453
+ constexpr int x = 1;
454
+ auto lambda = [] <typename T> { (T)x; }; // OK
455
+ lambda.operator()<int>(); // OK, does not odr-use x
456
+ lambda.operator()<void>(); // OK, does not odr-use x
457
+ lambda.operator()<const int&>(); // error: odr-uses x from a context where x is not odr-usable
458
+ }
459
+ ```
460
+
461
+ — *end example*]
462
+
463
  Every program shall contain at least one definition of every function or
464
  variable that is odr-used in that program outside of a discarded
465
  statement [[stmt.if]]; no diagnostic required. The definition can appear
466
  explicitly in the program, it can be found in the standard or a
467
  user-defined library, or (when appropriate) it is implicitly defined
468
  (see  [[class.default.ctor]], [[class.copy.ctor]], [[class.dtor]], and
469
  [[class.copy.assign]]).
470
 
471
+ [*Example 5*:
472
 
473
  ``` cpp
474
  auto f() {
475
  struct A {};
476
  return A{};
 
493
  discarded statement.
494
 
495
  A definition of a class shall be reachable in every context in which the
496
  class is used in a way that requires the class type to be complete.
497
 
498
+ [*Example 6*:
499
 
500
  The following complete translation unit is well-formed, even though it
501
  never defines `X`:
502
 
503
  ``` cpp
 
509
  — *end example*]
510
 
511
  [*Note 3*:
512
 
513
  The rules for declarations and expressions describe in which contexts
514
+ complete class types are required. A class type `T` must be complete if
515
 
516
  - an object of type `T` is defined [[basic.def]], or
517
  - a non-static class data member of type `T` is declared [[class.mem]],
518
  or
519
  - `T` is used as the allocated type or array element type in a
 
533
  - the `typeid` operator [[expr.typeid]] or the `sizeof` operator
534
  [[expr.sizeof]] is applied to an operand of type `T`, or
535
  - a function with a return type or argument type of type `T` is defined
536
  [[basic.def]] or called [[expr.call]], or
537
  - a class with a base class of type `T` is defined [[class.derived]], or
538
+ - an lvalue of type `T` is assigned to [[expr.assign]], or
539
  - the type `T` is the subject of an `alignof` expression
540
  [[expr.alignof]], or
541
  - an *exception-declaration* has type `T`, reference to `T`, or pointer
542
  to `T` [[except.handle]].
543
 
544
  — *end note*]
545
 
546
+ If a definable item `D` is defined in a translation unit by an injected
547
+ declaration X [[expr.const]] and another translation unit contains a
548
+ definition of `D`, that definition shall be an injected declaration
549
+ having the same characteristic sequence as X; a diagnostic is required
550
+ only if `D` is attached to a named module and a prior definition is
551
+ reachable at the point where a later definition occurs.
552
+
553
+ For any other definable item `D` with definitions in multiple
554
+ translation units,
555
 
556
  - if `D` is a non-inline non-templated function or variable, or
557
  - if the definitions in different translation units do not satisfy the
558
  following requirements,
559
 
 
568
  [[module.unit]].
569
  - Each such definition shall consist of the same sequence of tokens,
570
  where the definition of a closure type is considered to consist of the
571
  sequence of tokens of the corresponding *lambda-expression*.
572
  - In each such definition, corresponding names, looked up according to 
573
+ [[basic.lookup]], shall denote the same entity, after overload
574
  resolution [[over.match]] and after matching of partial template
575
+ specializations [[temp.spec.partial.match]], except that a name can
576
+ refer to
577
  - a non-volatile const object with internal or no linkage if the
578
  object
579
  - has the same literal type in all definitions of `D`,
580
  - is initialized with a constant expression [[expr.const]],
581
  - is not odr-used in any definition of `D`, and
582
  - has the same value in all definitions of `D`,
583
 
584
  or
585
  - a reference with internal or no linkage initialized with a constant
586
+ expression such that the reference refers to the same object or
587
+ function in all definitions of `D`.
588
  - In each such definition, except within the default arguments and
589
  default template arguments of `D`, corresponding *lambda-expression*s
590
  shall have the same closure type (see below).
591
  - In each such definition, corresponding entities shall have the same
592
  language linkage.
 
600
  implicit calls to conversion functions, constructors, operator new
601
  functions and operator delete functions, shall refer to the same
602
  function.
603
  - In each such definition, a default argument used by an (implicit or
604
  explicit) function call or a default template argument used by an
605
+ (implicit or explicit) *template-id*, *simple-template-id*, or
606
+ *splice-specialization-specifier* is treated as if its token sequence
607
+ were present in the definition of `D`; that is, the default argument
608
+ or default template argument is subject to the requirements described
609
+ in this paragraph (recursively).
610
+ - In each such definition, corresponding *reflect-expression*s
611
+ [[expr.reflect]] compute equivalent values [[expr.eq]].
612
+
613
+ For the purposes of the preceding requirements:
614
+
615
  - If `D` is a class with an implicitly-declared constructor
616
  [[class.default.ctor]], [[class.copy.ctor]], it is as if the
617
  constructor was implicitly defined in every translation unit where it
618
  is odr-used, and the implicit definition in every translation unit
619
  shall call the same constructor for a subobject of `D`.
620
+ \[*Example 7*:
621
  ``` cpp
622
  // translation unit 1:
623
  struct X {
624
  X(int, int);
625
  X(int, int, int);
 
647
  - If `D` is a class with a defaulted three-way comparison operator
648
  function [[class.spaceship]], it is as if the operator was implicitly
649
  defined in every translation unit where it is odr-used, and the
650
  implicit definition in every translation unit shall call the same
651
  comparison operators for each subobject of `D`.
652
+ - If `D` is a template and is defined in more than one translation unit,
653
+ the requirements apply both to names from the template’s enclosing
654
+ scope used in the template definition, and also to dependent names at
655
+ the point of instantiation [[temp.dep]].
656
 
657
+ These requirements also apply to corresponding entities defined within
658
+ each definition of `D` (including the closure types of
659
+ *lambda-expression*s, but excluding entities defined within default
660
+ arguments or default template arguments of either `D` or an entity not
661
+ defined within `D`). For each such entity and for `D` itself, the
662
+ behavior is as if there is a single entity with a single definition,
663
+ including in the application of these requirements to other entities.
 
 
 
 
664
 
665
  [*Note 4*: The entity is still declared in multiple translation units,
666
  and [[basic.link]] still applies to these declarations. In particular,
667
  *lambda-expression*s [[expr.prim.lambda]] appearing in the type of `D`
668
  can result in the different declarations having distinct types, and
669
  *lambda-expression*s appearing in a default argument of `D` might still
670
  denote different types in different translation units. — *end note*]
671
 
672
+ [*Example 8*:
673
 
674
  ``` cpp
675
  inline void f(bool cond, void (*p)()) {
676
  if (cond) f(false, []{});
677
  }
 
708
  ### General <a id="basic.scope.scope">[[basic.scope.scope]]</a>
709
 
710
  The declarations in a program appear in a number of *scopes* that are in
711
  general discontiguous. The *global scope* contains the entire program;
712
  every other scope S is introduced by a declaration,
713
+ *parameter-declaration-clause*, *statement*, *handler*, or contract
714
+ assertion (as described in the following subclauses of [[basic.scope]])
715
+ appearing in another scope, which thereby contains S. An
716
+ *enclosing scope* at a program point is any scope that contains it; the
717
+ smallest such scope is said to be the *immediate scope* at that point. A
718
+ scope *intervenes* between a program point P and a scope S (that does
719
+ not contain P) if it is or contains S but does not contain P.
720
 
721
  Unless otherwise specified:
722
 
723
  - The smallest scope that contains a scope S is the *parent scope* of S.
724
  - No two declarations (re)introduce the same entity.
 
726
  [[basic.scope.pdecl]].
727
  - A declaration’s *target scope* is the scope it inhabits.
728
  - Any names (re)introduced by a declaration are *bound* to it in its
729
  target scope.
730
 
731
+ The *host scope* of a declaration is the inhabited scope if that scope
732
+ is a block scope and the target scope otherwise. An entity *belongs* to
733
+ a scope S if S is the target scope of a declaration of the entity.
734
 
735
  [*Note 1*:
736
 
737
  Special cases include that:
738
 
 
740
  scopes [[basic.scope.temp]].
741
  - Corresponding declarations with appropriate linkage declare the same
742
  entity [[basic.link]].
743
  - The declaration in a *template-declaration* inhabits the same scope as
744
  the *template-declaration*.
745
+ - Friend declarations and declarations of template specializations do
746
+ not bind names [[dcl.meaning]]; those with qualified names target a
747
+ specified scope, and other friend declarations and certain
748
+ *elaborated-type-specifier*s [[dcl.type.elab]] target a larger
749
+ enclosing scope.
750
+ - Block-scope extern or function declarations target a larger enclosing
751
+ scope but bind a name in their immediate scope
752
+ [[dcl.meaning.general]].
753
  - The names of unscoped enumerators are bound in the two innermost
754
  enclosing scopes [[dcl.enum]].
755
  - A class’s name is also bound in its own scope [[class.pre]].
756
  - The names of the members of an anonymous union are bound in the
757
  union’s parent scope [[class.union.anon]].
758
 
759
  — *end note*]
760
 
761
  Two non-static member functions have *corresponding object parameters*
762
+ if
763
 
764
  - exactly one is an implicit object member function with no
765
  *ref-qualifier* and the types of their object parameters [[dcl.fct]],
766
+ after removing references, are the same, or
767
  - their object parameters have the same type.
768
 
769
  Two non-static member function templates have *corresponding object
770
+ parameters* if
771
 
772
  - exactly one is an implicit object member function with no
773
  *ref-qualifier* and the types of their object parameters, after
774
  removing any references, are equivalent, or
775
  - the types of their object parameters are equivalent.
 
782
 
783
  Two declarations *correspond* if they (re)introduce the same name, both
784
  declare constructors, or both declare destructors, unless
785
 
786
  - either is a *using-declarator*, or
787
+ - one declares a type (not a type alias) and the other declares a
788
  variable, non-static data member other than of an anonymous union
789
  [[class.union.anon]], enumerator, function, or function template, or
790
+ - each declares a function or function template and they do not declare
791
+ corresponding overloads.
792
+
793
+ Two function or function template declarations declare *corresponding
794
+ overloads* if
795
+
796
  - both declare functions with the same
797
  non-object-parameter-type-list,[^3] equivalent [[temp.over.link]]
798
  trailing *requires-clause*s (if any, except as specified in
799
  [[temp.friend]]), and, if both are non-static members, they have
800
  corresponding object parameters, or
801
  - both declare function templates with corresponding signatures and
802
+ equivalent *template-head*s and trailing *requires-clause*s (if any).
 
803
 
804
  [*Note 2*:
805
 
806
  Declarations can correspond even if neither binds a name.
807
 
 
845
  };
846
  ```
847
 
848
  — *end example*]
849
 
850
+ A declaration is *name-independent* if its name is `_`
851
+ (U+005f (low line)) and it declares
852
+
853
+ - a variable with automatic storage duration,
854
+ - a structured binding with no *storage-class-specifier* and not
855
+ inhabiting a namespace scope,
856
+ - a result binding [[dcl.contract.res]],
857
+ - the variable introduced by an *init-capture*, or
858
+ - a non-static data member of other than an anonymous union.
859
+
860
+ *Recommended practice:* Implementations should not emit a warning that a
861
+ name-independent declaration is used or unused.
862
+
863
  Two declarations *potentially conflict* if they correspond and cause
864
  their shared name to denote different entities [[basic.link]]. The
865
  program is ill-formed if, in any scope, a name is bound to two
866
+ declarations A and B that potentially conflict and A precedes B
867
+ [[basic.lookup]], unless B is name-independent.
868
 
869
+ [*Note 3*: An *id-expression* that names a unique name-independent
870
+ declaration is usable until an additional declaration of the same name
871
+ is introduced in the same scope [[basic.lookup.general]]. — *end note*]
872
+
873
+ [*Note 4*: Overload resolution can consider potentially conflicting
874
  declarations found in multiple scopes (e.g., via *using-directive*s or
875
  for operator functions), in which case it is often
876
  ambiguous. — *end note*]
877
 
878
  [*Example 3*:
 
888
  namespace B = A;
889
  namespace B = A; // OK, no effect
890
  namespace B = B; // OK, no effect
891
  namespace A = B; // OK, no effect
892
  namespace B {} // error: different entity for B
893
+
894
+ void g() {
895
+ int _;
896
+ _ = 0; // OK
897
+ int _; // OK, name-independent declaration
898
+ _ = 0; // error: two non-function declarations in the lookup set
899
+ }
900
+ void h () {
901
+ int _; // #1
902
+ _ ++; // OK
903
+ static int _; // error: conflicts with #1 because static variables are not name-independent
904
+ }
905
  ```
906
 
907
  — *end example*]
908
 
909
  A declaration is *nominable* in a class, class template, or namespace E
 
1026
  The locus of the declaration of a structured binding [[dcl.struct.bind]]
1027
  is immediately after the *identifier-list* of the structured binding
1028
  declaration.
1029
 
1030
  The locus of a *for-range-declaration* of a range-based `for` statement
1031
+ [[stmt.ranged]] is immediately after the *for-range-initializer*. The
1032
+ locus of a *for-range-declaration* of an *expansion-statement*
1033
+ [[stmt.expand]] is immediately after the *expansion-initializer*.
1034
 
1035
  The locus of a *template-parameter* is immediately after it.
1036
 
1037
  [*Example 5*:
1038
 
 
1044
  N = 0> struct A { };
1045
  ```
1046
 
1047
  — *end example*]
1048
 
1049
+ The locus of a *result-name-introducer* [[dcl.contract.res]] is
1050
+ immediately after it.
1051
+
1052
  The locus of a *concept-definition* is immediately after its
1053
+ *concept-name* [[temp.concept]].
1054
 
1055
  [*Note 3*: The *constraint-expression* cannot use the
1056
  *concept-name*. — *end note*]
1057
 
1058
  The locus of a *namespace-definition* with an *identifier* is
 
1073
 
1074
  ### Block scope <a id="basic.scope.block">[[basic.scope.block]]</a>
1075
 
1076
  Each
1077
 
1078
+ - selection, iteration, or expansion statement
1079
+ [[stmt.select]], [[stmt.iter]], [[stmt.expand]],
1080
  - substatement of such a statement,
1081
  - *handler* [[except.pre]], or
1082
  - compound statement [[stmt.block]] that is not the *compound-statement*
1083
  of a *handler*
1084
 
 
1101
  int j = i; // j = 42
1102
  ```
1103
 
1104
  — *end example*]
1105
 
1106
+ If a declaration that is not a name-independent declaration and that
1107
+ binds a name in the block scope S of a
1108
 
1109
  - *compound-statement* of a *lambda-expression*, *function-body*, or
1110
  *function-try-block*,
1111
  - substatement of a selection or iteration statement that is not itself
1112
  a selection or iteration statement, or
 
1148
  parameter scope is nested within its class’s scope. — *end note*]
1149
  - If P is associated with a *lambda-declarator*, its scope extends to
1150
  the end of the *compound-statement* in the *lambda-expression*.
1151
  - If P is associated with a *requirement-parameter-list*, its scope
1152
  extends to the end of the *requirement-body* of the
1153
+ *requires-expression*.
1154
  - If P is associated with a *deduction-guide*, its scope extends to the
1155
  end of the *deduction-guide*.
1156
 
1157
  ### Lambda scope <a id="basic.scope.lambda">[[basic.scope.lambda]]</a>
1158
 
 
1219
  that includes the *enumerator-list* of the *enum-specifier* for E (if
1220
  any).
1221
 
1222
  ### Template parameter scope <a id="basic.scope.temp">[[basic.scope.temp]]</a>
1223
 
1224
+ Each *type-tt-parameter*, *variable-tt-parameter*, and
1225
+ *concept-tt-parameter* introduces a *template parameter scope* that
1226
+ includes the *template-head* of the *template-parameter*.
1227
 
1228
  Each *template-declaration* D introduces a template parameter scope that
1229
  extends from the beginning of its *template-parameter-list* to the end
1230
  of the *template-declaration*. Any declaration outside the
1231
  *template-parameter-list* that would inhabit that scope instead inhabits
 
1235
 
1236
  [*Note 1*: Therefore, only template parameters belong to a template
1237
  parameter scope, and only template parameter scopes have a template
1238
  parameter scope as a parent scope. — *end note*]
1239
 
1240
+ ### Contract-assertion scope <a id="basic.scope.contract">[[basic.scope.contract]]</a>
1241
+
1242
+ Each contract assertion [[basic.contract]] C introduces a
1243
+ *contract-assertion scope* that includes C.
1244
+
1245
+ If a *result-name-introducer* [[dcl.contract.res]] that is not
1246
+ name-independent [[basic.scope.scope]] and whose enclosing postcondition
1247
+ assertion is associated with a function `F` potentially conflicts with a
1248
+ declaration whose target scope is
1249
+
1250
+ - the function parameter scope of `F` or
1251
+ - if associated with a *lambda-declarator*, the nearest enclosing lambda
1252
+ scope of the precondition assertion [[expr.prim.lambda]],
1253
+
1254
+ the program is ill-formed.
1255
+
1256
  ## Name lookup <a id="basic.lookup">[[basic.lookup]]</a>
1257
 
1258
  ### General <a id="basic.lookup.general">[[basic.lookup.general]]</a>
1259
 
1260
+ *Name lookup* associates the use of a name with a set of declarations
1261
+ [[basic.def]] of that name. The name lookup rules apply uniformly to all
1262
+ names (including *typedef-name*s [[dcl.typedef]], *namespace-name*s
1263
+ [[basic.namespace]], and *class-name*s [[class.name]]) wherever the
1264
+ grammar allows such names in the context discussed by a particular rule.
1265
  Unless otherwise specified, the program is ill-formed if no declarations
1266
  are found. If the declarations found by name lookup all denote functions
1267
  or function templates, the declarations are said to form an *overload
1268
  set*. Otherwise, if the declarations found by name lookup do not all
1269
  denote the same entity, they are *ambiguous* and the program is
 
1336
 
1337
  In certain contexts, only certain kinds of declarations are included.
1338
  After any such restriction, any declarations of classes or enumerations
1339
  are discarded if any other declarations are found.
1340
 
1341
+ [*Note 4*: A type (but not a type alias or template) is therefore
1342
  hidden by any other entity in its scope. — *end note*]
1343
 
1344
  However, if a lookup is *type-only*, only declarations of types and
1345
  templates whose specializations are types are considered; furthermore,
1346
+ if declarations of a type alias and of its underlying entity are found,
1347
+ the declaration of the type alias is discarded instead of the type
1348
+ declaration.
1349
 
1350
  ### Member name lookup <a id="class.member.lookup">[[class.member.lookup]]</a>
1351
 
1352
  A *search* in a scope X for a name M from a program point P is a single
1353
  search in X for M from P unless X is the scope of a class or class
 
1689
  - function declaration inhabiting a block scope, or
1690
  - declaration not of a function or function template
1691
 
1692
  then lookup for the name also includes the result of
1693
  *argument-dependent lookup* in a set of associated namespaces that
1694
+ depends on the types of the arguments (and for type template template
1695
  arguments, the namespace of the template argument), as specified below.
1696
 
1697
  [*Example 1*:
1698
 
1699
  ``` cpp
 
1755
 
1756
  — *end note*]
1757
 
1758
  For each argument type `T` in the function call, there is a set of zero
1759
  or more *associated entities* to be considered. The set of entities is
1760
+ determined entirely by the types of the function arguments (and any type
1761
  template template arguments). Any *typedef-name*s and
1762
  *using-declaration*s used to specify the types do not contribute to this
1763
  set. The set of entities is determined in the following way:
1764
 
1765
+ - If `T` is `std::meta::info` [[meta.syn]], its associated set of
1766
+ entities is the singleton containing the enumeration type
1767
+ `std::meta::operators` [[meta.reflection.operators]]. \[*Note 2*: The
1768
+ `std::meta::info` type is a type alias, so an explicit rule is needed
1769
+ to associate calls whose arguments are reflections with the namespace
1770
+ `std::meta`. — *end note*]
1771
+ - If `T` is any other fundamental type, its associated set of entities
1772
+ is empty.
1773
  - If `T` is a class type (including unions), its associated entities
1774
+ are: the class itself; the class of which it is a member, if any; and,
1775
+ if it is a complete type, its direct and indirect base classes.
1776
+ Furthermore, if `T` is a class template specialization, its associated
1777
+ entities also include: the entities associated with the types of the
1778
+ template arguments provided for template type parameters; the
1779
+ templates used as type template template arguments; and the classes of
1780
+ which any member templates used as type template template arguments
1781
+ are members. \[*Note 3*: Constant template arguments, variable
1782
+ template template arguments, and concept template arguments do not
1783
+ contribute to the set of associated entities. — *end note*]
1784
  - If `T` is an enumeration type, its associated entities are `T` and, if
1785
  it is a class member, the member’s class.
1786
  - If `T` is a pointer to `U` or an array of `U`, its associated entities
1787
  are those associated with `U`.
1788
  - If `T` is a function type, its associated entities are those
 
1798
  In addition, if the argument is an overload set or the address of such a
1799
  set, its associated entities are the union of those associated with each
1800
  of the members of the set, i.e., the entities associated with its
1801
  parameter types and return type. Additionally, if the aforementioned
1802
  overload set is named with a *template-id*, its associated entities also
1803
+ include its template template arguments and those associated with its
1804
+ type template arguments.
1805
 
1806
  The *associated namespaces* for a call are the innermost enclosing
1807
  non-inline namespaces for its associated entities as well as every
1808
  element of the inline namespace set [[namespace.def]] of those
1809
  namespaces. Argument-dependent lookup finds all declarations of
 
1872
  }
1873
  ```
1874
 
1875
  — *end example*]
1876
 
1877
+ [*Note 4*: The associated namespace can include namespaces already
1878
  considered by ordinary unqualified lookup. — *end note*]
1879
 
1880
  [*Example 3*:
1881
 
1882
  ``` cpp
 
1900
 
1901
  #### General <a id="basic.lookup.qual.general">[[basic.lookup.qual.general]]</a>
1902
 
1903
  Lookup of an *identifier* followed by a `::` scope resolution operator
1904
  considers only namespaces, types, and templates whose specializations
1905
+ are types. If a name, *template-id*, *splice-scope-specifier*, or
1906
+ *computed-type-specifier* is followed by a `::`, it shall either be a
1907
+ dependent *splice-scope-specifier* [[temp.dep.splice]] or it shall
1908
+ designate a namespace, class, enumeration, or dependent type, and the
1909
+ `::` is never interpreted as a complete *nested-name-specifier*.
1910
 
1911
  [*Example 1*:
1912
 
1913
  ``` cpp
1914
  class A {
 
1945
  - the terminal name of
1946
  - a *qualified-id*,
1947
  - a *using-declarator*,
1948
  - a *typename-specifier*,
1949
  - a *qualified-namespace-specifier*, or
1950
+ - a *nested-name-specifier*, *reflection-name*,
1951
+ *elaborated-type-specifier*, or *class-or-decltype* that has a
1952
+ *nested-name-specifier* [[expr.prim.id.qual]].
1953
 
1954
  The *lookup context* of a member-qualified name is the type of its
1955
  associated object expression (considered dependent if the object
1956
  expression is type-dependent). The lookup context of any other qualified
1957
  name is the type, template, or namespace nominated by the preceding
 
2314
 
2315
  In a *using-directive* or *namespace-alias-definition*, during the
2316
  lookup for a *namespace-name* or for a name in a *nested-name-specifier*
2317
  only namespace names are considered.
2318
 
2319
+ ## Splice specifiers <a id="basic.splice">[[basic.splice]]</a>
2320
+
2321
+ ``` bnf
2322
+ splice-specifier:
2323
+ '[:' constant-expression ':]'
2324
+ ```
2325
+
2326
+ ``` bnf
2327
+ splice-specialization-specifier:
2328
+ splice-specifier '<' template-argument-listₒₚₜ '>'
2329
+ ```
2330
+
2331
+ The *constant-expression* of a *splice-specifier* shall be a converted
2332
+ constant expression of type `std::meta::info` [[expr.const]]. A
2333
+ *splice-specifier* whose converted *constant-expression* represents a
2334
+ construct X is said to *designate* either
2335
+
2336
+ - the underlying entity of X if X is an entity [[basic.pre]], or
2337
+ - X otherwise.
2338
+
2339
+ [*Note 1*: A *splice-specifier* is dependent if the converted
2340
+ *constant-expression* is value-dependent
2341
+ [[temp.dep.splice]]. — *end note*]
2342
+
2343
+ A non-dependent *splice-specifier* of a
2344
+ *splice-specialization-specifier* shall designate a template.
2345
+
2346
+ [*Note 2*:
2347
+
2348
+ A `<` following a *splice-specifier* is interpreted as the delimiter of
2349
+ a *template-argument-list* when the *splice-specifier* is preceded by
2350
+ the keyword `template` or the keyword `typename`, or when it appears in
2351
+ a type-only context [[temp.names]].
2352
+
2353
+ [*Example 1*:
2354
+
2355
+ ``` cpp
2356
+ constexpr int v = 1;
2357
+ template<int V> struct TCls {
2358
+ static constexpr int s = V + 1;
2359
+ };
2360
+
2361
+ using alias = [:^^TCls:]<([:^^v:])>;
2362
+ // OK, a splice-specialization-specifier with a parenthesized splice-expression as a template argument
2363
+
2364
+ static_assert(alias::s == 2);
2365
+
2366
+ auto o1 = [:^^TCls:]<([:^^v:])>(); // error: < means less than
2367
+ auto o2 = typename [:^^TCls:]<([:^^v:])>(); // OK, o2 is an object of type TCls<1>
2368
+
2369
+ consteval int bad_splice(std::meta::info v) {
2370
+ return [:v:]; // error: v is not constant
2371
+ }
2372
+ ```
2373
+
2374
+ — *end example*]
2375
+
2376
+ — *end note*]
2377
+
2378
  ## Program and linkage <a id="basic.link">[[basic.link]]</a>
2379
 
2380
+ A *program* consists of one or more translation units [[lex.phases]]
2381
  linked together. A translation unit consists of a sequence of
2382
  declarations.
2383
 
2384
  ``` bnf
2385
  translation-unit:
2386
  declaration-seqₒₚₜ
2387
  global-module-fragmentₒₚₜ module-declaration declaration-seqₒₚₜ private-module-fragmentₒₚₜ
2388
  ```
2389
 
2390
+ A name has *external linkage*, *module linkage*, *internal linkage*, or
2391
+ *no linkage*, as determined by the rules below.
 
2392
 
2393
+ [*Note 1*: All declarations of an entity with a name with internal
2394
+ linkage appear in the same translation unit. All declarations of an
2395
+ entity with module linkage are attached to the same
2396
+ module. *end note*]
 
 
 
 
 
 
 
2397
 
2398
  The name of an entity that belongs to a namespace scope
2399
  [[basic.scope.namespace]] has internal linkage if it is the name of
2400
 
2401
  - a variable, variable template, function, or function template that is
 
2407
  - it is inline, or
2408
  - it was previously declared and the prior declaration did not have
2409
  internal linkage; or
2410
  - a data member of an anonymous union.
2411
 
2412
+ [*Note 2*: An instantiated variable template that has const-qualified
2413
  type can have external or module linkage, even if not declared
2414
  `extern`. — *end note*]
2415
 
2416
  An unnamed namespace or a namespace declared directly or indirectly
2417
  within an unnamed namespace has internal linkage. All other namespaces
2418
  have external linkage. The name of an entity that belongs to a namespace
2419
+ scope, that has not been given internal linkage above, and that is the
2420
  name of
2421
 
2422
  - a variable; or
2423
  - a function; or
2424
  - a named class [[class.pre]], or an unnamed class defined in a typedef
 
2431
  purposes [[dcl.enum]]; or
2432
  - a template
2433
 
2434
  has its linkage determined as follows:
2435
 
2436
+ - if the entity is a function or function template first declared in a
2437
+ friend declaration and that declaration is a definition and the
2438
+ enclosing class is defined within an *export-declaration*, the name
2439
+ has the same linkage, if any, as the name of the enclosing class
2440
+ [[class.friend]];
2441
+ - otherwise, if the entity is a function or function template declared
2442
+ in a friend declaration and a corresponding non-friend declaration is
2443
+ reachable, the name has the linkage determined from that prior
2444
+ declaration,
2445
+ - otherwise, if the enclosing namespace has internal linkage, the name
2446
+ has internal linkage;
2447
  - otherwise, if the declaration of the name is attached to a named
2448
  module [[module.unit]] and is not exported [[module.interface]], the
2449
  name has module linkage;
2450
  - otherwise, the name has external linkage.
2451
 
 
2486
 
2487
  Two declarations of entities declare the same entity if, considering
2488
  declarations of unnamed types to introduce their names for linkage
2489
  purposes, if any [[dcl.typedef]], [[dcl.enum]], they correspond
2490
  [[basic.scope.scope]], have the same target scope that is not a function
2491
+ or template parameter scope, neither is a name-independent declaration,
2492
+ and either
2493
 
2494
  - they appear in the same translation unit, or
2495
+ - they both declare type aliases or namespace aliases that have the same
2496
+ underlying entity, or
2497
  - they both declare names with module linkage and are attached to the
2498
  same module, or
2499
  - they both declare names with external linkage.
2500
 
2501
+ [*Note 3*: There are other circumstances in which declarations declare
2502
  the same entity
2503
  [[dcl.link]], [[temp.type]], [[temp.spec.partial]]. — *end note*]
2504
 
2505
  If a declaration H that declares a name with internal linkage precedes a
2506
  declaration D in another translation unit U and would declare the same
2507
  entity as D if it appeared in U, the program is ill-formed.
2508
 
2509
+ [*Note 4*: Such an H can appear only in a header unit. — *end note*]
2510
 
2511
  If two declarations of an entity are attached to different modules, the
2512
  program is ill-formed; no diagnostic is required if neither is reachable
2513
  from the other.
2514
 
 
2555
  - If one declares E to be a namespace, the other shall do so.
2556
  - If one declares E to be a type, the other shall declare E to be a type
2557
  of the same kind [[dcl.type.elab]].
2558
  - If one declares E to be a class template, the other shall do so with
2559
  the same kind and an equivalent *template-head* [[temp.over.link]].
2560
+ \[*Note 5*: The declarations can supply different default template
2561
  arguments. — *end note*]
2562
  - If one declares E to be a function template or a (partial
2563
  specialization of a) variable template, the other shall declare E to
2564
  be one with an equivalent *template-head* and type.
2565
  - If one declares E to be an alias template, the other shall declare E
 
2583
  namespace h {} // error: same entity as #2, but not a function
2584
  ```
2585
 
2586
  — *end example*]
2587
 
2588
+ [*Note 6*: Linkage to non-C++ declarations can be achieved using a
2589
  *linkage-specification* [[dcl.link]]. — *end note*]
2590
 
2591
  A declaration D *names* an entity E if
2592
 
2593
  - D contains a *lambda-expression* whose closure type is E,
2594
+ - D contains a *reflect-expression* or a *splice-specifier* that,
2595
+ respectively, represents or designates E,
2596
+ - D is an injected declaration [[expr.const]] whose characteristic
2597
+ sequence contains a reflection that represents a data member
2598
+ description (T, N, A, W, NUA) [[class.mem.general]] for which T is E,
2599
  - E is not a function or function template and D contains an
2600
  *id-expression*, *type-specifier*, *nested-name-specifier*,
2601
  *template-name*, or *concept-name* denoting E, or
2602
  - E is a function or function template and D contains an expression that
2603
  names E [[basic.def.odr]] or an *id-expression* that refers to a set
2604
+ of overloads that contains E. \[*Note 7*: Non-dependent names in an
2605
  instantiated declaration do not refer to a set of overloads
2606
  [[temp.res]]. — *end note*]
2607
 
2608
  A declaration is an *exposure* if it either names a TU-local entity
2609
  (defined below), ignoring
 
2620
  not an odr-use [[term.odr.use]],
2621
 
2622
  or defines a constexpr variable initialized to a TU-local value (defined
2623
  below).
2624
 
2625
+ [*Note 8*: An inline function template can be an exposure even though
2626
  certain explicit specializations of it would be usable in other
2627
  translation units. — *end note*]
2628
 
2629
  An entity is *TU-local* if it is
2630
 
2631
+ - a type, type alias, namespace, namespace alias, function, variable, or
2632
+ template that
2633
  - has a name with internal linkage, or
2634
  - does not have a name with linkage and is declared, or introduced by
2635
  a *lambda-expression*, within the definition of a TU-local entity,
2636
  - a type with no name that is defined outside a *class-specifier*,
2637
  function body, or *initializer* or is introduced by a
2638
  *defining-type-specifier* that is used to declare only TU-local
2639
  entities,
2640
  - a specialization of a TU-local template,
2641
  - a specialization of a template with any TU-local template argument, or
2642
  - a specialization of a template whose (possibly instantiated)
2643
+ declaration is an exposure. \[*Note 9*: A specialization can be
2644
  produced by implicit or explicit instantiation. — *end note*]
2645
 
2646
  A value or object is *TU-local* if either
2647
 
2648
+ - it is of TU-local type,
2649
  - it is, or is a pointer to, a TU-local function or the object
2650
+ associated with a TU-local variable,
2651
  - it is an object of class or array type and any of its subobjects or
2652
  any of the objects or functions to which its non-static data members
2653
  of reference type refer is TU-local and is usable in constant
2654
+ expressions, or
2655
+ - it is a reflection value [[basic.fundamental]] that represents
2656
+ - an entity, value, or object that is TU-local,
2657
+ - a direct base class relationship (D, B) [[class.derived.general]]
2658
+ for which either D or B is TU-local, or
2659
+ - a data member description (T, N, A, W, NUA) [[class.mem.general]]
2660
+ for which T is TU-local.
2661
 
2662
  If a (possibly instantiated) declaration of, or a deduction guide for, a
2663
  non-TU-local entity in a module interface unit (outside the
2664
  *private-module-fragment*, if any) or module partition [[module.unit]]
2665
  is an exposure, the program is ill-formed. Such a declaration in any
 
2702
  static void adl(int);
2703
  }
2704
  void adl(double);
2705
 
2706
  inline void h(auto x) { adl(x); } // OK, but certain specializations are exposures
2707
+
2708
+ constexpr std::meta::info r1 = ^^g<0>; // OK
2709
+ namespace N2 {
2710
+ static constexpr std::meta::info r2 = ^^g<1>; // OK, r2 is TU-local
2711
+ }
2712
+ constexpr std::meta::info r3 = ^^f; // error: r3 is an exposure of f
2713
+
2714
+ constexpr auto ctx = std::meta::access_context::current();
2715
+ constexpr std::meta::info r4 =
2716
+ std::meta::members_of(^^N2, ctx)[0]; // error: r4 is an exposure of N2::r2
2717
  ```
2718
 
2719
  Translation unit #2
2720
 
2721
  ``` cpp
 
2738
  ### Memory model <a id="intro.memory">[[intro.memory]]</a>
2739
 
2740
  The fundamental storage unit in the C++ memory model is the *byte*. A
2741
  byte is at least large enough to contain the ordinary literal encoding
2742
  of any element of the basic literal character set [[lex.charset]] and
2743
+ the eight-bit code units of the Unicode UTF-8 encoding form and is
2744
+ composed of a contiguous sequence of bits,[^5]
2745
 
2746
+ the number of which is *implementation-defined*. The memory available to
2747
+ a C++ program consists of one or more sequences of contiguous bytes.
2748
+ Every byte has a unique address.
 
 
 
 
 
2749
 
2750
  [*Note 1*: The representation of types is described in 
2751
  [[basic.types.general]]. — *end note*]
2752
 
2753
+ A *memory location* is the storage occupied by the object representation
2754
+ of either an object of scalar type that is not a bit-field or a maximal
2755
+ sequence of adjacent bit-fields all having nonzero width.
2756
 
2757
  [*Note 2*: Various features of the language, such as references and
2758
  virtual functions, might involve additional memory locations that are
2759
  not accessible to programs but are managed by the
2760
  implementation. — *end note*]
 
2825
  be a *member subobject* [[class.mem]], a *base class subobject*
2826
  [[class.derived]], or an array element. An object that is not a
2827
  subobject of any other object is called a *complete object*. If an
2828
  object is created in storage associated with a member subobject or array
2829
  element *e* (which may or may not be within its lifetime), the created
2830
+ object is a subobject of *e*’s containing object if
2831
 
2832
  - the lifetime of *e*’s containing object has begun and not ended, and
2833
  - the storage for the new object exactly overlays the storage location
2834
  associated with *e*, and
2835
  - the new object is of the same type as *e* (ignoring cv-qualification).
2836
 
2837
  If a complete object is created [[expr.new]] in storage associated with
2838
  another object *e* of type “array of N `unsigned char`” or of type
2839
  “array of N `std::byte`” [[cstddef.syn]], that array *provides storage*
2840
+ for the created object if
2841
 
2842
  - the lifetime of *e* has begun and not ended, and
2843
  - the storage for the new object fits entirely within *e*, and
2844
  - there is no array object that satisfies these constraints nested
2845
  within *e*.
 
2849
  reused [[basic.life]]. — *end note*]
2850
 
2851
  [*Example 1*:
2852
 
2853
  ``` cpp
2854
+ // assumes that sizeof(int) is equal to 4
2855
+
2856
  template<typename ...T>
2857
  struct AlignedUnion {
2858
  alignas(T...) unsigned char data[max(sizeof(T)...)];
2859
  };
2860
  int f() {
 
2865
  return *c + *d; // OK
2866
  }
2867
 
2868
  struct A { unsigned char a[32]; };
2869
  struct B { unsigned char b[16]; };
2870
+ alignas(int) A a;
2871
  B *b = new (a.a + 8) B; // a.a provides storage for *b
2872
  int *p = new (b->b + 4) int; // b->b provides storage for *p
2873
  // a.a does not provide storage for *p (directly),
2874
  // but *p is nested within a (see below)
2875
  ```
2876
 
2877
  — *end example*]
2878
 
2879
+ An object *a* is *nested within* another object *b* if
2880
 
2881
  - *a* is a subobject of *b*, or
2882
  - *b* provides storage for *a*, or
2883
  - there exists an object *c* where *a* is nested within *c*, and *c* is
2884
  nested within *b*.
 
2919
  object with nonzero size shall occupy one or more bytes of storage,
2920
  including every byte that is occupied in full or in part by any of its
2921
  subobjects. An object of trivially copyable or standard-layout type
2922
  [[basic.types.general]] shall occupy contiguous bytes of storage.
2923
 
2924
+ An object is a *potentially non-unique object* if it is
2925
+
2926
+ - a string literal object [[lex.string]],
2927
+ - the backing array of an initializer list [[dcl.init.ref]], or
2928
+ - the object introduced by a call to `std::meta::reflect_constant_array`
2929
+ or `std::meta::reflect_constant_string` [[meta.define.static]], or
2930
+ - a subobject thereof.
2931
+
2932
  Unless an object is a bit-field or a subobject of zero size, the address
2933
  of that object is the address of the first byte it occupies. Two objects
2934
  with overlapping lifetimes that are not bit-fields may have the same
2935
+ address if
2936
+
2937
+ - one is nested within the other,
2938
+ - at least one is a subobject of zero size and they are not of similar
2939
+ types [[conv.qual]], or
2940
+ - they are both potentially non-unique objects;
2941
+
2942
+ otherwise, they have distinct addresses and occupy disjoint bytes of
2943
+ storage.[^6]
2944
 
2945
  [*Example 2*:
2946
 
2947
  ``` cpp
2948
  static const char test1 = 'x';
2949
  static const char test2 = 'x';
2950
  const bool b = &test1 != &test2; // always true
2951
+
2952
+ static const char (&r) [] = "x";
2953
+ static const char *s = "x";
2954
+ static std::initializer_list<char> il = { 'x' };
2955
+ const bool b2 = r != il.begin(); // unspecified result
2956
+ const bool b3 = r != s; // unspecified result
2957
+ const bool b4 = il.begin() != &test1; // always true
2958
+ const bool b5 = r != &test1; // always true
2959
  ```
2960
 
2961
  — *end example*]
2962
 
2963
  The address of a non-bit-field subobject of zero size is the address of
 
2966
 
2967
  Some operations are described as *implicitly creating objects* within a
2968
  specified region of storage. For each operation that is specified as
2969
  implicitly creating objects, that operation implicitly creates and
2970
  starts the lifetime of zero or more objects of implicit-lifetime types
2971
+ [[term.implicit.lifetime.type]] in its specified region of storage if
2972
+ doing so would result in the program having defined behavior. If no such
2973
+ set of objects would give the program defined behavior, the behavior of
2974
+ the program is undefined. If multiple such sets of objects would give
2975
+ the program defined behavior, it is unspecified which such set of
2976
+ objects is created.
2977
 
2978
  [*Note 4*: Such operations do not start the lifetimes of subobjects of
2979
  such objects that are not themselves of implicit-lifetime
2980
  types. — *end note*]
2981
 
 
3008
  }
3009
  ```
3010
 
3011
  — *end example*]
3012
 
3013
+ Except during constant evaluation, an operation that begins the lifetime
3014
+ of an array of `unsigned char` or `std::byte` implicitly creates objects
3015
+ within the region of storage occupied by the array.
3016
 
3017
  [*Note 5*: The array object provides storage for these
3018
  objects. — *end note*]
3019
 
3020
+ Except during constant evaluation, any implicit or explicit invocation
3021
+ of a function named `operator new` or `operator new[]` implicitly
3022
+ creates objects in the returned region of storage and returns a pointer
3023
+ to a suitable created object.
3024
 
3025
  [*Note 6*: Some functions in the C++ standard library implicitly create
3026
  objects
3027
+ [[obj.lifetime]], [[c.malloc]], [[mem.res.public]], [[bit.cast]], [[cstring.syn]]. — *end note*]
3028
+
3029
+ ### Alignment <a id="basic.align">[[basic.align]]</a>
3030
+
3031
+ Object types have *alignment requirements*
3032
+ [[basic.fundamental]], [[basic.compound]] which place restrictions on
3033
+ the addresses at which an object of that type may be allocated. An
3034
+ *alignment* is an *implementation-defined* integer value representing
3035
+ the number of bytes between successive addresses at which a given object
3036
+ can be allocated. An object type imposes an alignment requirement on
3037
+ every object of that type; stricter alignment can be requested using the
3038
+ alignment specifier [[dcl.align]]. Attempting to create an object
3039
+ [[intro.object]] in storage that does not meet the alignment
3040
+ requirements of the object’s type is undefined behavior.
3041
+
3042
+ A *fundamental alignment* is represented by an alignment less than or
3043
+ equal to the greatest alignment supported by the implementation in all
3044
+ contexts, which is equal to `alignof(std::max_align_t)`
3045
+ [[support.types]]. The alignment required for a type may be different
3046
+ when it is used as the type of a complete object and when it is used as
3047
+ the type of a subobject.
3048
+
3049
+ [*Example 1*:
3050
+
3051
+ ``` cpp
3052
+ struct B { long double d; };
3053
+ struct D : virtual B { char c; };
3054
+ ```
3055
+
3056
+ When `D` is the type of a complete object, it will have a subobject of
3057
+ type `B`, so it must be aligned appropriately for a `long double`. If
3058
+ `D` appears as a subobject of another object that also has `B` as a
3059
+ virtual base class, the `B` subobject might be part of a different
3060
+ subobject, reducing the alignment requirements on the `D` subobject.
3061
+
3062
+ — *end example*]
3063
+
3064
+ The result of the `alignof` operator reflects the alignment requirement
3065
+ of the type in the complete-object case.
3066
+
3067
+ An *extended alignment* is represented by an alignment greater than
3068
+ `alignof(std::max_align_t)`. It is *implementation-defined* whether any
3069
+ extended alignments are supported and the contexts in which they are
3070
+ supported [[dcl.align]]. A type having an extended alignment requirement
3071
+ is an *over-aligned type*.
3072
+
3073
+ [*Note 1*: Every over-aligned type is or contains a class type to which
3074
+ extended alignment applies (possibly through a non-static data
3075
+ member). — *end note*]
3076
+
3077
+ A *new-extended alignment* is represented by an alignment greater than
3078
+ `__STDCPP_DEFAULT_NEW_ALIGNMENT__` [[cpp.predefined]].
3079
+
3080
+ Alignments are represented as values of the type `std::size_t`. Valid
3081
+ alignments include only those values returned by an `alignof` expression
3082
+ for the fundamental types plus an additional *implementation-defined*
3083
+ set of values, which may be empty. Every alignment value shall be a
3084
+ non-negative integral power of two.
3085
+
3086
+ Alignments have an order from *weaker* to *stronger* or *stricter*
3087
+ alignments. Stricter alignments have larger alignment values. An address
3088
+ that satisfies an alignment requirement also satisfies any weaker valid
3089
+ alignment requirement.
3090
+
3091
+ The alignment requirement of a complete type can be queried using an
3092
+ `alignof` expression [[expr.alignof]]. Furthermore, the narrow character
3093
+ types [[basic.fundamental]] shall have the weakest alignment
3094
+ requirement.
3095
+
3096
+ [*Note 2*: This enables the ordinary character types to be used as the
3097
+ underlying type for an aligned memory area [[dcl.align]]. — *end note*]
3098
+
3099
+ Comparing alignments is meaningful and provides the obvious results:
3100
+
3101
+ - Two alignments are equal when their numeric values are equal.
3102
+ - Two alignments are different when their numeric values are not equal.
3103
+ - When an alignment is larger than another it represents a stricter
3104
+ alignment.
3105
+
3106
+ [*Note 3*: The runtime pointer alignment function [[ptr.align]] can be
3107
+ used to obtain an aligned pointer within a buffer; an
3108
+ *alignment-specifier* [[dcl.align]] can be used to align storage
3109
+ explicitly. — *end note*]
3110
+
3111
+ If a request for a specific extended alignment in a specific context is
3112
+ not supported by an implementation, the program is ill-formed.
3113
 
3114
  ### Lifetime <a id="basic.life">[[basic.life]]</a>
3115
 
3116
+ In this subclause, “before” and “after” refer to the “happens before”
3117
+ relation [[intro.multithread]].
3118
+
3119
  The *lifetime* of an object or reference is a runtime property of the
3120
  object or reference. A variable is said to have *vacuous initialization*
3121
+ if it is default-initialized, no other initialization is performed, and,
3122
+ if it is of class type or a (possibly multidimensional) array thereof, a
3123
+ trivial constructor of that class type is selected for the
3124
+ default-initialization. The lifetime of an object of type `T` begins
3125
+ when:
3126
 
3127
  - storage with the proper alignment and size for type `T` is obtained,
3128
  and
3129
  - its initialization (if any) is complete (including vacuous
3130
  initialization) [[dcl.init]],
 
3139
  - if `T` is a non-class type, the object is destroyed, or
3140
  - if `T` is a class type, the destructor call starts, or
3141
  - the storage which the object occupies is released, or is reused by an
3142
  object that is not nested within *o* [[intro.object]].
3143
 
3144
+ When evaluating a *new-expression*, storage is considered reused after
3145
+ it is returned from the allocation function, but before the evaluation
3146
+ of the *new-initializer* [[expr.new]].
3147
+
3148
+ [*Example 1*:
3149
+
3150
+ ``` cpp
3151
+ struct S {
3152
+ int m;
3153
+ };
3154
+
3155
+ void f() {
3156
+ S x{1};
3157
+ new(&x) S(x.m); // undefined behavior
3158
+ }
3159
+ ```
3160
+
3161
+ — *end example*]
3162
+
3163
  The lifetime of a reference begins when its initialization is complete.
3164
  The lifetime of a reference ends as if it were a scalar object requiring
3165
  storage.
3166
 
3167
  [*Note 1*: [[class.base.init]] describes the lifetime of base and
 
3190
 
3191
  [*Note 4*: The correct behavior of a program often depends on the
3192
  destructor being invoked for each object of class type. — *end note*]
3193
 
3194
  Before the lifetime of an object has started but after the storage which
3195
+ the object will occupy has been allocated[^7]
3196
 
3197
+ or after the lifetime of an object has ended and before the storage
3198
  which the object occupied is reused or released, any pointer that
3199
  represents the address of the storage location where the object will be
3200
  or was located may be used but only in limited ways. For an object under
3201
  construction or destruction, see  [[class.cdtor]]. Otherwise, such a
3202
  pointer refers to allocated storage [[basic.stc.dynamic.allocation]],
3203
  and using the pointer as if the pointer were of type `void*` is
3204
  well-defined. Indirection through such a pointer is permitted but the
3205
  resulting lvalue may only be used in limited ways, as described below.
3206
+ The program has undefined behavior if
3207
 
3208
  - the pointer is used as the operand of a *delete-expression*,
3209
  - the pointer is used to access a non-static data member or call a
3210
  non-static member function of the object, or
3211
  - the pointer is implicitly converted [[conv.ptr]] to a pointer to a
 
3215
  cv `void`, or to pointer to cv `void` and subsequently to pointer to
3216
  cv `char`, cv `unsigned char`, or cv `std::byte` [[cstddef.syn]], or
3217
  - the pointer is used as the operand of a `dynamic_cast`
3218
  [[expr.dynamic.cast]].
3219
 
3220
+ [*Example 2*:
3221
 
3222
  ``` cpp
3223
  #include <cstdlib>
3224
 
3225
  struct B {
 
3248
  ```
3249
 
3250
  — *end example*]
3251
 
3252
  Similarly, before the lifetime of an object has started but after the
3253
+ storage which the object will occupy has been allocated or after the
3254
  lifetime of an object has ended and before the storage which the object
3255
  occupied is reused or released, any glvalue that refers to the original
3256
  object may be used but only in limited ways. For an object under
3257
  construction or destruction, see  [[class.cdtor]]. Otherwise, such a
3258
  glvalue refers to allocated storage [[basic.stc.dynamic.allocation]],
3259
  and using the properties of the glvalue that do not depend on its value
3260
+ is well-defined. The program has undefined behavior if
3261
 
3262
  - the glvalue is used to access the object, or
3263
  - the glvalue is used to call a non-static member function of the
3264
  object, or
3265
  - the glvalue is bound to a reference to a virtual base class
3266
  [[dcl.init.ref]], or
3267
  - the glvalue is used as the operand of a `dynamic_cast`
3268
  [[expr.dynamic.cast]] or as the operand of `typeid`.
3269
 
3270
+ [*Note 5*: Therefore, undefined behavior results if an object that is
3271
+ being constructed in one thread is referenced from another thread
3272
+ without adequate synchronization. *end note*]
3273
+
3274
+ An object o₁ is *transparently replaceable* by an object o₂ if
 
 
 
 
3275
 
3276
  - the storage that o₂ occupies exactly overlays the storage that o₁
3277
  occupied, and
3278
  - o₁ and o₂ are of the same type (ignoring the top-level cv-qualifiers),
3279
  and
 
3282
  [[intro.object]], and
3283
  - either o₁ and o₂ are both complete objects, or o₁ and o₂ are direct
3284
  subobjects of objects p₁ and p₂, respectively, and p₁ is transparently
3285
  replaceable by p₂.
3286
 
3287
+ After the lifetime of an object has ended and before the storage which
3288
+ the object occupied is reused or released, if a new object is created at
3289
+ the storage location which the original object occupied and the original
3290
+ object was transparently replaceable by the new object, a pointer that
3291
+ pointed to the original object, a reference that referred to the
3292
+ original object, or the name of the original object will automatically
3293
+ refer to the new object and, once the lifetime of the new object has
3294
+ started, can be used to manipulate the new object.
3295
+
3296
+ [*Example 3*:
3297
 
3298
  ``` cpp
3299
  struct C {
3300
  int i;
3301
  void f();
 
3317
  c1.f(); // well-defined; c1 refers to a new object of type C
3318
  ```
3319
 
3320
  — *end example*]
3321
 
3322
+ [*Note 6*: If these conditions are not met, a pointer to the new object
3323
  can be obtained from a pointer that represents the address of its
3324
  storage by calling `std::launder` [[ptr.launder]]. — *end note*]
3325
 
3326
  If a program ends the lifetime of an object of type `T` with static
3327
  [[basic.stc.static]], thread [[basic.stc.thread]], or automatic
3328
  [[basic.stc.auto]] storage duration and if `T` has a non-trivial
3329
+ destructor,[^8]
3330
 
3331
  and another object of the original type does not occupy that same
3332
  storage location when the implicit destructor call takes place, the
3333
  behavior of the program is undefined. This is true even if the block is
3334
  exited with an exception.
3335
 
3336
+ [*Example 4*:
3337
 
3338
  ``` cpp
3339
  class T { };
3340
  struct B {
3341
  ~B();
 
3352
  Creating a new object within the storage that a const, complete object
3353
  with static, thread, or automatic storage duration occupies, or within
3354
  the storage that such a const object used to occupy before its lifetime
3355
  ended, results in undefined behavior.
3356
 
3357
+ [*Example 5*:
3358
 
3359
  ``` cpp
3360
  struct B {
3361
  B();
3362
  ~B();
 
3370
  }
3371
  ```
3372
 
3373
  — *end example*]
3374
 
3375
+ ### Indeterminate and erroneous values <a id="basic.indet">[[basic.indet]]</a>
 
 
 
 
 
 
 
3376
 
3377
  When storage for an object with automatic or dynamic storage duration is
3378
+ obtained, the bytes comprising the storage for the object have the
3379
+ following initial value:
 
3380
 
3381
+ - If the object has dynamic storage duration, or is the object
3382
+ associated with a variable or function parameter whose first
3383
+ declaration is marked with the `[[indeterminate]]` attribute
3384
+ [[dcl.attr.indet]], the bytes have *indeterminate values*;
3385
+ - otherwise, the bytes have *erroneous values*, where each value is
3386
+ determined by the implementation independently of the state of the
3387
+ program.
3388
+
3389
+ If no initialization is performed for an object (including subobjects),
3390
+ such a byte retains its initial value until that value is replaced
3391
+ [[dcl.init.general]], [[expr.assign]]. If any bit in the value
3392
+ representation has an indeterminate value, the object has an
3393
+ indeterminate value; otherwise, if any bit in the value representation
3394
+ has an erroneous value, the object has an erroneous value.
3395
+
3396
+ [*Note 1*: Lvalue-to-rvalue conversion has undefined behavior if the
3397
+ erroneous value of an object is not valid for its type
3398
+ [[conv.lval]]. — *end note*]
3399
+
3400
+ [*Note 2*: Objects with static or thread storage duration are
3401
  zero-initialized, see  [[basic.start.static]]. — *end note*]
3402
 
3403
+ Except in the following cases, if an indeterminate value is produced by
3404
+ an evaluation, the behavior is undefined, and if an erroneous value is
3405
+ produced by an evaluation, the behavior is erroneous and the result of
3406
+ the evaluation is the value so produced but is not erroneous:
3407
 
3408
+ - If an indeterminate or erroneous value of unsigned ordinary character
3409
+ type [[basic.fundamental]] or `std::byte` type [[cstddef.syn]] is
3410
+ produced by the evaluation of:
3411
  - the second or third operand of a conditional expression
3412
  [[expr.cond]],
3413
  - the right operand of a comma expression [[expr.comma]],
3414
  - the operand of a cast or conversion
3415
  [[conv.integral]], [[expr.type.conv]], [[expr.static.cast]], [[expr.cast]]
3416
  to an unsigned ordinary character type or `std::byte` type
3417
  [[cstddef.syn]], or
3418
  - a discarded-value expression [[expr.context]],
3419
 
3420
+ then the result of the operation is an indeterminate value or that
3421
+ erroneous value, respectively.
3422
+ - If an indeterminate or erroneous value of unsigned ordinary character
3423
+ type or `std::byte` type is produced by the evaluation of the right
3424
+ operand of a simple assignment operator [[expr.assign]] whose first
3425
+ operand is an lvalue of unsigned ordinary character type or
3426
+ `std::byte` type, an indeterminate value or that erroneous value,
3427
+ respectively, replaces the value of the object referred to by the left
3428
+ operand.
3429
+ - If an indeterminate or erroneous value of unsigned ordinary character
3430
+ type is produced by the evaluation of the initialization expression
3431
+ when initializing an object of unsigned ordinary character type, that
3432
+ object is initialized to an indeterminate value or that erroneous
3433
+ value, respectively.
3434
  - If an indeterminate value of unsigned ordinary character type or
3435
  `std::byte` type is produced by the evaluation of the initialization
3436
  expression when initializing an object of `std::byte` type, that
3437
+ object is initialized to an indeterminate value or that erroneous
3438
+ value, respectively.
3439
+
3440
+ Converting an indeterminate or erroneous value of unsigned ordinary
3441
+ character type or `std::byte` type produces an indeterminate or
3442
+ erroneous value, respectively. In the latter case, the result of the
3443
+ conversion is the value of the converted operand.
3444
 
3445
  [*Example 1*:
3446
 
3447
  ``` cpp
3448
  int f(bool b) {
3449
+ unsigned char *c = new unsigned char;
3450
+ unsigned char d = *c; // OK, d has an indeterminate value
3451
  int e = d; // undefined behavior
3452
  return b ? d : 0; // undefined behavior if b is true
3453
  }
3454
+
3455
+ int g(bool b) {
3456
+ unsigned char c;
3457
+ unsigned char d = c; // no erroneous behavior, but d has an erroneous value
3458
+
3459
+ assert(c == d); // holds, both integral promotions have erroneous behavior
3460
+
3461
+ int e = d; // erroneous behavior
3462
+ return b ? d : 0; // erroneous behavior if b is true
3463
+ }
3464
+
3465
+ void h() {
3466
+ int d1, d2;
3467
+
3468
+ int e1 = d1; // erroneous behavior
3469
+ int e2 = d1; // erroneous behavior
3470
+
3471
+ assert(e1 == e2); // holds
3472
+ assert(e1 == d1); // holds, erroneous behavior
3473
+ assert(e2 == d1); // holds, erroneous behavior
3474
+
3475
+ std::memcpy(&d2, &d1, sizeof(int)); // no erroneous behavior, but d2 has an erroneous value
3476
+ assert(e1 == d2); // holds, erroneous behavior
3477
+ assert(e2 == d2); // holds, erroneous behavior
3478
+ }
3479
  ```
3480
 
3481
  — *end example*]
3482
 
3483
  ### Storage duration <a id="basic.stc">[[basic.stc]]</a>
 
3492
  - static storage duration
3493
  - thread storage duration
3494
  - automatic storage duration
3495
  - dynamic storage duration
3496
 
3497
+ [*Note 1*: After the duration of a region of storage has ended, the use
3498
+ of pointers to that region of storage is limited
3499
+ [[basic.compound]]. — *end note*]
3500
+
3501
  Static, thread, and automatic storage durations are associated with
3502
+ objects introduced by declarations [[basic.def]] and with temporary
3503
+ objects [[class.temporary]]. The dynamic storage duration is associated
3504
+ with objects created by a *new-expression* [[expr.new]] or with
3505
+ implicitly created objects [[intro.object]].
3506
 
3507
  The storage duration categories apply to references as well.
3508
 
3509
+ The storage duration of subobjects and reference members is that of
3510
+ their complete object [[intro.object]].
 
 
 
 
 
3511
 
3512
  #### Static storage duration <a id="basic.stc.static">[[basic.stc.static]]</a>
3513
 
3514
  All variables which
3515
 
 
3546
  [[stmt.dcl]] and, if constructed, is destroyed on thread exit
3547
  [[basic.start.term]]. — *end note*]
3548
 
3549
  #### Automatic storage duration <a id="basic.stc.auto">[[basic.stc.auto]]</a>
3550
 
3551
+ Variables that belong to a block scope and are not explicitly declared
3552
+ `static`, `thread_local`, or `extern` have *automatic storage duration*.
3553
+ The storage for such variables lasts until the block in which they are
3554
+ created exits.
3555
 
3556
  [*Note 1*: These variables are initialized and destroyed as described
3557
  in  [[stmt.dcl]]. — *end note*]
3558
 
3559
+ Variables that belong to a parameter scope also have automatic storage
3560
+ duration. The storage for a function parameter lasts until immediately
3561
+ after its destruction [[expr.call]].
3562
+
3563
  If a variable with automatic storage duration has initialization or a
3564
  destructor with side effects, an implementation shall not destroy it
3565
  before the end of its block nor eliminate it as an optimization, even if
3566
  it appears to be unused, except that a class object or its copy/move may
3567
  be eliminated as specified in  [[class.copy.elision]].
 
3582
  [[new.delete.placement]] do not perform allocation or
3583
  deallocation. — *end note*]
3584
 
3585
  The library provides default definitions for the global allocation and
3586
  deallocation functions. Some global allocation and deallocation
3587
+ functions are replaceable [[term.replaceable.function]]. The following
3588
+ allocation and deallocation functions [[support.dynamic]] are implicitly
3589
+ declared in global scope in each translation unit of a program.
 
 
 
 
3590
 
3591
  ``` cpp
3592
+ void* operator new(std::size_t);
3593
+ void* operator new(std::size_t, std::align_val_t);
3594
 
3595
  void operator delete(void*) noexcept;
3596
  void operator delete(void*, std::size_t) noexcept;
3597
  void operator delete(void*, std::align_val_t) noexcept;
3598
  void operator delete(void*, std::size_t, std::align_val_t) noexcept;
3599
 
3600
+ void* operator new[](std::size_t);
3601
+ void* operator new[](std::size_t, std::align_val_t);
3602
 
3603
  void operator delete[](void*) noexcept;
3604
  void operator delete[](void*, std::size_t) noexcept;
3605
  void operator delete[](void*, std::align_val_t) noexcept;
3606
  void operator delete[](void*, std::size_t, std::align_val_t) noexcept;
 
3655
  subsequently passed to a replaceable deallocation function. Furthermore,
3656
  for the library allocation functions in  [[new.delete.single]] and 
3657
  [[new.delete.array]], `p0` represents the address of a block of storage
3658
  disjoint from the storage for any other object accessible to the caller.
3659
  The effect of indirecting through a pointer returned from a request for
3660
+ zero size is undefined.[^9]
3661
 
3662
  For an allocation function other than a reserved placement allocation
3663
  function [[new.delete.placement]], the pointer returned on a successful
3664
  call shall represent the address of storage that is aligned as follows:
3665
 
 
3674
 
3675
  An allocation function that fails to allocate storage can invoke the
3676
  currently installed new-handler function [[new.handler]], if any.
3677
 
3678
  [*Note 3*: A program-supplied allocation function can obtain the
3679
+ currently installed `new_handler` using the `std::get_new_handler`
3680
+ function [[get.new.handler]]. — *end note*]
3681
 
3682
  An allocation function that has a non-throwing exception specification
3683
  [[except.spec]] indicates failure by returning a null pointer value. Any
3684
  other allocation function never returns a null pointer value and
3685
  indicates failure only by throwing an exception [[except.throw]] of a
 
3694
 
3695
  [*Note 4*: In particular, a global allocation function is not called to
3696
  allocate storage for objects with static storage duration
3697
  [[basic.stc.static]], for objects or references with thread storage
3698
  duration [[basic.stc.thread]], for objects of type `std::type_info`
3699
+ [[expr.typeid]], for an object of type
3700
+ `std::contracts::contract_violation` when a contract violation occurs
3701
+ [[basic.contract.eval]], or for an exception object
3702
  [[except.throw]]. — *end note*]
3703
 
3704
  ##### Deallocation functions <a id="basic.stc.dynamic.deallocation">[[basic.stc.dynamic.deallocation]]</a>
3705
 
3706
  A deallocation function that is not a class member function shall belong
 
3720
  parameter shall be `void*`. A deallocation function may have more than
3721
  one parameter. A *usual deallocation function* is a deallocation
3722
  function whose parameters after the first are
3723
 
3724
  - optionally, a parameter of type `std::destroying_delete_t`, then
3725
+ - optionally, a parameter of type `std::size_t`,[^10] then
3726
  - optionally, a parameter of type `std::align_val_t`.
3727
 
3728
  A destroying operator delete shall be a usual deallocation function. A
3729
  deallocation function may be an instance of a function template. Neither
3730
  the first parameter nor the return type shall depend on a template
 
3741
  If the argument given to a deallocation function in the standard library
3742
  is a pointer that is not the null pointer value [[basic.compound]], the
3743
  deallocation function shall deallocate the storage referenced by the
3744
  pointer, ending the duration of the region of storage.
3745
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3746
  ### Temporary objects <a id="class.temporary">[[class.temporary]]</a>
3747
 
3748
+ A *temporary object* is an object created
3749
 
3750
+ - when a prvalue is converted to an xvalue [[conv.rval]] and
3751
  - when needed by the implementation to pass or return an object of
3752
+ suitable type (see below).
 
 
3753
 
3754
  Even when the creation of the temporary object is unevaluated
3755
  [[expr.context]], all the semantic restrictions shall be respected as if
3756
  the temporary object had been created and later destroyed.
3757
 
3758
+ [*Note 1*: This includes accessibility [[class.access]] and whether it
3759
  is deleted, for the constructor selected and for the destructor.
3760
  However, in the special case of the operand of a *decltype-specifier*
3761
  [[dcl.type.decltype]], no temporary is introduced, so the foregoing does
3762
  not apply to such a prvalue. — *end note*]
3763
 
3764
  The materialization of a temporary object is generally delayed as long
3765
  as possible in order to avoid creating unnecessary temporary objects.
3766
 
3767
+ [*Note 2*:
3768
 
3769
  Temporary objects are materialized:
3770
 
3771
  - when binding a reference to a prvalue
3772
  [[dcl.init.ref]], [[expr.type.conv]], [[expr.dynamic.cast]], [[expr.static.cast]], [[expr.const.cast]], [[expr.cast]],
3773
+ - when performing certain member accesses on a class prvalue
3774
  [[expr.ref]], [[expr.mptr.oper]],
3775
+ - when invoking an implicit object member function on a class prvalue
3776
+ [[expr.call]],
3777
  - when performing an array-to-pointer conversion or subscripting on an
3778
  array prvalue [[conv.array]], [[expr.sub]],
3779
  - when initializing an object of type `std::initializer_list<T>` from a
3780
  *braced-init-list* [[dcl.init.list]],
3781
  - for certain unevaluated operands [[expr.typeid]], [[expr.sizeof]], and
 
3823
  materialized so that the reference parameter of `X::operator=(const X&)`
3824
  can bind to it.
3825
 
3826
  — *end example*]
3827
 
3828
+ When an object of type `X` is passed to or returned from a
3829
+ potentially-evaluated function call, if `X` is
 
 
 
 
 
 
 
 
 
3830
 
3831
+ - a scalar type or
3832
+ - a class type that has at least one eligible copy or move constructor
3833
+ [[special]], where each such constructor is trivial, and the
3834
+ destructor of `X` is either trivial or deleted,
3835
 
3836
+ implementations are permitted to create temporary objects to hold the
3837
+ function parameter or result object, as follows:
 
 
 
 
 
 
 
 
 
3838
 
3839
+ - The first such temporary object is constructed from the function
3840
+ argument or return value, respectively.
3841
+ - Each successive temporary object is initialized from the previous one
3842
+ as if by direct-initialization if `X` is a scalar type, otherwise by
3843
+ using an eligible trivial constructor.
3844
+ - The function parameter or return object is initialized from the final
3845
+ temporary as if by direct-initialization if `X` is a scalar type,
3846
+ otherwise by using an eligible trivial constructor.
3847
+
3848
+ (In all cases, the eligible constructor is used even if that constructor
3849
+ is inaccessible or would not be selected by overload resolution to
3850
+ perform a copy or move of the object).
3851
+
3852
+ [*Note 3*: This latitude is granted to allow objects to be passed to or
3853
+ returned from functions in registers. — *end note*]
3854
+
3855
+ Temporary objects are destroyed as the last step in evaluating the
3856
+ full-expression [[intro.execution]] that (lexically) contains the point
3857
+ where they were created. This is true even if that evaluation ends in
3858
+ throwing an exception. The value computations and side effects of
3859
+ destroying a temporary object are associated only with the
3860
+ full-expression, not with any specific subexpression.
3861
+
3862
+ Temporary objects are destroyed at a different point than the end of the
3863
+ full-expression in the following contexts: The first context is when a
3864
+ default constructor is called to initialize an element of an array with
3865
+ no corresponding initializer [[dcl.init]]. The second context is when a
3866
+ copy constructor is called to copy an element of an array while the
3867
+ entire array is copied
3868
  [[expr.prim.lambda.capture]], [[class.copy.ctor]]. In either case, if
3869
  the constructor has one or more default arguments, the destruction of
3870
  every temporary created in a default argument is sequenced before the
3871
  construction of the next array element, if any.
3872
 
3873
+ The third context is when a reference binds to a temporary object.[^11]
3874
 
3875
  The temporary object to which the reference is bound or the temporary
3876
  object that is the complete object of a subobject to which the reference
3877
  is bound persists for the lifetime of the reference if the glvalue to
3878
  which the reference is bound was obtained through one of the following:
 
3914
  // exactly one of the two temporaries is lifetime-extended
3915
  ```
3916
 
3917
  — *end example*]
3918
 
3919
+ [*Note 4*:
3920
 
3921
  An explicit type conversion [[expr.type.conv]], [[expr.cast]] is
3922
  interpreted as a sequence of elementary casts, covered above.
3923
 
3924
  [*Example 3*:
 
3929
 
3930
  — *end example*]
3931
 
3932
  — *end note*]
3933
 
3934
+ [*Note 5*:
3935
 
3936
  If a temporary object has a reference member initialized by another
3937
  temporary object, lifetime extension applies recursively to such a
3938
  member’s initializer.
3939
 
 
3957
  containing the call.
3958
  - A temporary object bound to a reference element of an aggregate of
3959
  class type initialized from a parenthesized *expression-list*
3960
  [[dcl.init]] persists until the completion of the full-expression
3961
  containing the *expression-list*.
 
 
 
3962
  - A temporary bound to a reference in a *new-initializer* [[expr.new]]
3963
  persists until the completion of the full-expression containing the
3964
  *new-initializer*.
3965
+ \[*Note 6*: This might introduce a dangling reference. — *end note*]
3966
  \[*Example 5*:
3967
  ``` cpp
3968
  struct S { int mi; const std::pair<int,int>& mp; };
3969
  S a { 1, {2,3} };
3970
  S* p = new S{ 1, {2,3} }; // creates dangling reference
3971
  ```
3972
 
3973
  — *end example*]
3974
 
3975
+ The fourth context is when a temporary object is created in the
3976
+ *for-range-initializer* of either a range-based `for` statement or an
3977
+ enumerating expansion statement [[stmt.expand]]. If such a temporary
3978
+ object would otherwise be destroyed at the end of the
3979
+ *for-range-initializer* full-expression, the object persists for the
3980
+ lifetime of the reference initialized by the *for-range-initializer*.
3981
 
3982
+ The fifth context is when a temporary object is created in the
3983
+ *expansion-initializer* of an iterating or destructuring expansion
3984
+ statement. If such a temporary object would otherwise be destroyed at
3985
+ the end of that *expansion-initializer*, the object persists for the
3986
+ lifetime of the reference initialized by the *expansion-initializer*, if
3987
+ any.
3988
+
3989
+ The sixth context is when a temporary object is created in a structured
3990
+ binding declaration [[dcl.struct.bind]]. Any temporary objects
3991
+ introduced by the *initializer*s for the variables with unique names are
3992
+ destroyed at the end of the structured binding declaration.
3993
+
3994
+ Let `x` and `y` each be either a temporary object whose lifetime is not
3995
+ extended, or a function parameter. If the lifetimes of `x` and `y` end
3996
+ at the end of the same full-expression, and `x` is initialized before
3997
+ `y`, then the destruction of `y` is sequenced before that of `x`. If the
3998
+ lifetime of two or more temporaries with lifetimes extending beyond the
3999
+ full-expressions in which they were created ends at the same point,
4000
+ these temporaries are destroyed at that point in the reverse order of
4001
+ the completion of their construction. In addition, the destruction of
4002
+ such temporaries shall take into account the ordering of destruction of
4003
+ objects with static, thread, or automatic storage duration
4004
  [[basic.stc.static]], [[basic.stc.thread]], [[basic.stc.auto]]; that is,
4005
  if `obj1` is an object with the same storage duration as the temporary
4006
  and created before the temporary is created the temporary shall be
4007
  destroyed before `obj1` is destroyed; if `obj2` is an object with the
4008
  same storage duration as the temporary and created after the temporary
 
4054
 
4055
  For any object (other than a potentially-overlapping subobject) of
4056
  trivially copyable type `T`, whether or not the object holds a valid
4057
  value of type `T`, the underlying bytes [[intro.memory]] making up the
4058
  object can be copied into an array of `char`, `unsigned char`, or
4059
+ `std::byte` [[cstddef.syn]].[^12]
4060
 
4061
  If the content of that array is copied back into the object, the object
4062
  shall subsequently hold its original value.
4063
 
4064
  [*Example 1*:
 
4074
  — *end example*]
4075
 
4076
  For two distinct objects `obj1` and `obj2` of trivially copyable type
4077
  `T`, where neither `obj1` nor `obj2` is a potentially-overlapping
4078
  subobject, if the underlying bytes [[intro.memory]] making up `obj1` are
4079
+ copied into `obj2`,[^13]
4080
 
4081
  `obj2` shall subsequently hold the same value as `obj1`.
4082
 
4083
  [*Example 2*:
4084
 
 
4091
  // the same value as the corresponding subobject in *t2p
4092
  ```
4093
 
4094
  — *end example*]
4095
 
4096
+ The *object representation* of a complete object type `T` is the
4097
+ sequence of *N* `unsigned char` objects taken up by a non-bit-field
4098
+ complete object of type `T`, where *N* equals `sizeof(T)`. The *value
4099
+ representation* of a type `T` is the set of bits in the object
4100
+ representation of `T` that participate in representing a value of type
4101
+ `T`. The object and value representation of a non-bit-field complete
4102
+ object of type `T` are the bytes and bits, respectively, of the object
4103
+ corresponding to the object and value representation of its type. The
4104
+ object representation of a bit-field object is the sequence of *N* bits
4105
+ taken up by the object, where *N* is the width of the bit-field
4106
+ [[class.bit]]. The value representation of a bit-field object is the set
4107
+ of bits in the object representation that participate in representing
4108
+ its value. Bits in the object representation of a type or object that
4109
+ are not part of the value representation are *padding bits*. For
4110
+ trivially copyable types, the value representation is a set of bits in
4111
+ the object representation that determines a *value*, which is one
4112
+ discrete element of an *implementation-defined* set of values.[^14]
4113
 
4114
  A class that has been declared but not defined, an enumeration type in
4115
  certain contexts [[dcl.enum]], or an array of unknown bound or of
4116
+ incomplete element type, is an *incompletely-defined object type*.[^15]
4117
 
4118
  Incompletely-defined object types and cv `void` are *incomplete types*
4119
  [[basic.fundamental]].
4120
 
4121
  [*Note 2*: Objects cannot be defined to have an incomplete type
 
4173
 
4174
  An *object type* is a (possibly cv-qualified) type that is not a
4175
  function type, not a reference type, and not cv `void`.
4176
 
4177
  Arithmetic types [[basic.fundamental]], enumeration types, pointer
4178
+ types, pointer-to-member types [[basic.compound]], `std::meta::{}info`,
4179
+ `std::nullptr_t`, and cv-qualified [[basic.type.qualifier]] versions of
4180
+ these types are collectively called *scalar types*. Scalar types,
4181
+ trivially copyable class types [[class.prop]], arrays of such types, and
4182
+ cv-qualified versions of these types are collectively called *trivially
4183
+ copyable types*. Scalar types, trivially relocatable class types
4184
+ [[class.prop]], arrays of such types, and cv-qualified versions of these
4185
+ types are collectively called *trivially relocatable types*.
4186
+ Cv-unqualified scalar types, replaceable class types [[class.prop]], and
4187
+ arrays of such types are collectively called *replaceable types*. Scalar
4188
+ types, standard-layout class types [[class.prop]], arrays of such types,
4189
+ and cv-qualified versions of these types are collectively called
4190
+ *standard-layout types*. Scalar types, implicit-lifetime class types
4191
+ [[class.prop]], array types, and cv-qualified versions of these types
4192
+ are collectively called *implicit-lifetime types*.
4193
 
4194
  A type is a *literal type* if it is:
4195
 
4196
  - cv `void`; or
4197
  - a scalar type; or
4198
  - a reference type; or
4199
  - an array of literal type; or
4200
  - a possibly cv-qualified class type [[class]] that has all of the
4201
  following properties:
4202
  - it has a constexpr destructor [[dcl.constexpr]],
4203
+ - all of its non-variant non-static data members and base classes are
4204
  of non-volatile literal types, and
4205
  - it
4206
  - is a closure type [[expr.prim.lambda.closure]],
4207
  - is an aggregate union type that has either no variant members or
4208
  at least one variant member of non-volatile literal type,
 
4222
  Two types *cv1* `T1` and *cv2* `T2` are *layout-compatible types* if
4223
  `T1` and `T2` are the same type, layout-compatible enumerations
4224
  [[dcl.enum]], or layout-compatible standard-layout class types
4225
  [[class.mem]].
4226
 
4227
+ A type is *consteval-only* if it is either `std::meta::info` or a type
4228
+ compounded from a consteval-only type [[basic.compound]]. Every object
4229
+ of consteval-only type shall be
4230
+
4231
+ - the object associated with a constexpr variable or a subobject
4232
+ thereof,
4233
+ - a template parameter object [[temp.param]] or a subobject thereof, or
4234
+ - an object whose lifetime begins and ends during the evaluation of a
4235
+ core constant expression.
4236
+
4237
  ### Fundamental types <a id="basic.fundamental">[[basic.fundamental]]</a>
4238
 
4239
  There are five *standard signed integer types*: “`signed char`”,
4240
  “`short int`”, “`int`”, “`long int`”, and “`long long int`”. In this
4241
  list, each type provides at least as much storage as those preceding it
4242
  in the list. There may also be *implementation-defined* *extended signed
4243
  integer types*. The standard and extended signed integer types are
4244
  collectively called *signed integer types*. The range of representable
4245
+ values for a signed integer type is -2ᴺ⁻¹ to 2ᴺ⁻¹-1 (inclusive), where N
4246
+ is called the *width* of the type.
4247
 
4248
  [*Note 1*: Plain `int`s are intended to have the natural width
4249
  suggested by the architecture of the execution environment; the other
4250
  signed integer types are provided to meet special needs. — *end note*]
4251
 
 
4267
  An unsigned integer type has the same object representation, value
4268
  representation, and alignment requirements [[basic.align]] as the
4269
  corresponding signed integer type. For each value x of a signed integer
4270
  type, the value of the corresponding unsigned integer type congruent to
4271
  x modulo 2ᴺ has the same value of corresponding bits in its value
4272
+ representation.[^16]
4273
 
4274
  [*Example 1*: The value -1 of a signed integer type has the same
4275
  representation as the largest value of the corresponding unsigned
4276
  type. — *end example*]
4277
 
 
4284
  | `int` | 16 |
4285
  | `long int` | 32 |
4286
  | `long long int` | 64 |
4287
 
4288
 
4289
+ The width of each standard signed integer type shall not be less than
4290
+ the values specified in [[basic.fundamental.width]]. The value
4291
+ representation of a signed or unsigned integer type comprises N bits,
4292
+ where N is the respective width. Each set of values for any padding bits
4293
  [[basic.types.general]] in the object representation are alternative
4294
  representations of the value specified by the value representation.
4295
 
4296
  [*Note 3*: Padding bits have unspecified value, but cannot cause traps.
4297
+ In contrast, see ISO/IEC 9899:2018 (C) 6.2.6.2. — *end note*]
4298
 
4299
  [*Note 4*: The signed and unsigned integer types satisfy the
4300
+ constraints given in ISO/IEC 9899:2018 (C) 5.3.5.3.2. — *end note*]
4301
 
4302
  Except as specified above, the width of a signed or unsigned integer
4303
  type is *implementation-defined*.
4304
 
4305
  Each value x of an unsigned integer type with width N has a unique
 
4337
  Type `wchar_t` is a distinct type that has an *implementation-defined*
4338
  signed or unsigned integer type as its underlying type.
4339
 
4340
  Type `char8_t` denotes a distinct type whose underlying type is
4341
  `unsigned char`. Types `char16_t` and `char32_t` denote distinct types
4342
+ whose underlying types are `std::uint_least16_t` and
4343
+ `std::uint_least32_t`, respectively, in `<cstdint>`.
4344
 
4345
  Type `bool` is a distinct type that has the same object representation,
4346
  value representation, and alignment requirements as an
4347
  *implementation-defined* unsigned integer type. The values of type
4348
  `bool` are `true` and `false`.
 
4382
 
4383
  Except as specified in [[basic.extended.fp]], the object and value
4384
  representations and accuracy of operations of floating-point types are
4385
  *implementation-defined*.
4386
 
4387
+ The minimum range of representable values for a floating-point type is
4388
+ the most negative finite floating-point number representable in that
4389
+ type through the most positive finite floating-point number
4390
+ representable in that type. In addition, if negative infinity is
4391
+ representable in a type, the range of that type is extended to all
4392
+ negative real numbers; likewise, if positive infinity is representable
4393
+ in a type, the range of that type is extended to all positive real
4394
+ numbers.
4395
+
4396
+ [*Note 10*: Since negative and positive infinity are representable in
4397
+ ISO/IEC 60559 formats, all real numbers lie within the range of
4398
+ representable values of a floating-point type adhering to ISO/IEC
4399
+ 60559. — *end note*]
4400
+
4401
  Integral and floating-point types are collectively termed *arithmetic
4402
  types*.
4403
 
4404
+ [*Note 11*: Properties of the arithmetic types, such as their minimum
4405
  and maximum representable value, can be queried using the facilities in
4406
  the standard library headers `<limits>`, `<climits>`, and
4407
  `<cfloat>`. — *end note*]
4408
 
4409
  A type cv `void` is an incomplete type that cannot be completed; such a
4410
  type has an empty set of values. It is used as the return type for
4411
+ functions that do not return a value. An expression of type cv `void`
4412
+ shall be used only as
4413
+
4414
+ - an expression statement [[stmt.expr]],
4415
+ - the expression in a `return` statement [[stmt.return]] for a function
4416
+ with the return type cv `void`,
4417
+ - an operand of a comma expression [[expr.comma]],
4418
+ - the second or third operand of `?:` [[expr.cond]],
4419
+ - the operand of a `typeid` expression [[expr.typeid]],
4420
+ - the operand of a `noexcept` operator [[expr.unary.noexcept]],
4421
+ - the operand of a `decltype` specifier [[dcl.type.decltype]], or
4422
+ - the operand of an explicit conversion to type cv `void`
4423
+ [[expr.type.conv]], [[expr.static.cast]], [[expr.cast]].
4424
+
4425
+ The types denoted by cv `std::nullptr_t` are distinct types. A prvalue
4426
+ of type `std::nullptr_t` is a null pointer constant [[conv.ptr]]. Such
4427
+ values participate in the pointer and the pointer-to-member conversions
4428
+ [[conv.ptr]], [[conv.mem]]. `sizeof(std::nullptr_t)` shall be equal to
4429
+ `sizeof(void*)`.
4430
+
4431
+ A value of type `std::meta::info` is called a *reflection*. There exists
4432
+ a unique *null reflection*; every other reflection is a representation
4433
+ of
4434
+
4435
+ - a value of scalar type [[temp.param]],
4436
+ - an object with static storage duration [[basic.stc]],
4437
+ - a variable [[basic.pre]],
4438
+ - a structured binding [[dcl.struct.bind]],
4439
+ - a function [[dcl.fct]],
4440
+ - a function parameter,
4441
+ - an enumerator [[dcl.enum]],
4442
+ - an annotation [[dcl.attr.grammar]],
4443
+ - a type alias [[dcl.typedef]],
4444
+ - a type [[basic.types]],
4445
+ - a class member [[class.mem]],
4446
+ - an unnamed bit-field [[class.bit]],
4447
+ - a class template [[temp.pre]],
4448
+ - a function template,
4449
+ - a variable template,
4450
+ - an alias template [[temp.alias]],
4451
+ - a concept [[temp.concept]],
4452
+ - a namespace alias [[namespace.alias]],
4453
+ - a namespace [[basic.namespace.general]],
4454
+ - a direct base class relationship [[class.derived.general]], or
4455
+ - a data member description [[class.mem.general]].
4456
+
4457
+ A reflection is said to *represent* the corresponding construct.
4458
+
4459
+ [*Note 12*: A reflection of a value can be produced by library
4460
+ functions such as `std::meta::constant_of` and
4461
+ `std::meta::reflect_constant`. — *end note*]
4462
+
4463
+ [*Example 2*:
4464
+
4465
+ ``` cpp
4466
+ int arr[] = {1, 2, 3};
4467
+ auto [a1, a2, a3] = arr;
4468
+ [[=1]] void fn(int n);
4469
+ enum Enum { A };
4470
+ using Alias = int;
4471
+ struct B {};
4472
+ struct S : B {
4473
+ int mem;
4474
+ int : 0;
4475
+ };
4476
+ template<auto> struct TCls {};
4477
+ template<auto> void TFn();
4478
+ template<auto> int TVar;
4479
+ template<auto N> using TAlias = TCls<N>;
4480
+ template<auto> concept Concept = requires { true; };
4481
+ namespace NS {};
4482
+ namespace NSAlias = NS;
4483
+
4484
+ constexpr auto ctx = std::meta::access_context::current();
4485
+
4486
+ constexpr auto r1 = std::meta::reflect_constant(42); // represents int value of 42
4487
+ constexpr auto r2 = std::meta::reflect_object(arr[1]); // represents int object
4488
+ constexpr auto r3 = ^^arr; // represents a variable
4489
+ constexpr auto r4 = ^^a3; // represents a structured binding
4490
+ constexpr auto r5 = ^^fn; // represents a function
4491
+ constexpr auto r6 = std::meta::parameters_of(^^fn)[0]; // represents a function parameter
4492
+ constexpr auto r7 = ^^Enum::A; // represents an enumerator
4493
+ constexpr auto r8 = std::meta::annotations_of(^^fn)[0]; // represents an annotation
4494
+ constexpr auto r9 = ^^Alias; // represents a type alias
4495
+ constexpr auto r10 = ^^S; // represents a type
4496
+ constexpr auto r11 = ^^S::mem; // represents a class member
4497
+ constexpr auto r12 = std::meta::members_of(^^S, ctx)[1]; // represents an unnamed bit-field
4498
+ constexpr auto r13 = ^^TCls; // represents a class template
4499
+ constexpr auto r14 = ^^TFn; // represents a function template
4500
+ constexpr auto r15 = ^^TVar; // represents a variable template
4501
+ constexpr auto r16 = ^^TAlias; // represents an alias template
4502
+ constexpr auto r17 = ^^Concept; // represents a concept
4503
+ constexpr auto r18 = ^^NSAlias; // represents a namespace alias
4504
+ constexpr auto r19 = ^^NS; // represents a namespace
4505
+ constexpr auto r20 = std::meta::bases_of(^^S, ctx)[0]; // represents a direct base class relationship
4506
+ constexpr auto r21 =
4507
+ std::meta::data_member_spec(^^int, {.name="member"}); // represents a data member description
4508
+ ```
4509
+
4510
+ — *end example*]
4511
+
4512
+ *Recommended practice:* Implementations should not represent other
4513
+ constructs specified in this document, such as *using-declarator*s,
4514
+ partial template specializations, attributes, placeholder types,
4515
+ statements, or expressions, as values of type `std::meta::info`.
4516
+
4517
+ [*Note 13*: Future revisions of this document can specify semantics for
4518
+ reflections representing any such constructs. — *end note*]
4519
 
4520
  The types described in this subclause are called *fundamental types*.
4521
 
4522
+ [*Note 14*: Even if the implementation defines two or more fundamental
4523
  types to have the same value representation, they are nevertheless
4524
  different types. — *end note*]
4525
 
4526
  ### Optional extended floating-point types <a id="basic.extended.fp">[[basic.extended.fp]]</a>
4527
 
4528
  If the implementation supports an extended floating-point type
4529
+ [[basic.fundamental]] whose properties are specified by the ISO/IEC
4530
  60559 floating-point interchange format binary16, then the
4531
+ *typedef-name* `std::float16_t` is declared in the header `<stdfloat>`
4532
  and names such a type, the macro `__STDCPP_FLOAT16_T__` is defined
4533
  [[cpp.predefined]], and the floating-point literal suffixes `f16` and
4534
  `F16` are supported [[lex.fcon]].
4535
 
4536
  If the implementation supports an extended floating-point type whose
4537
+ properties are specified by the ISO/IEC 60559 floating-point interchange
4538
+ format binary32, then the *typedef-name* `std::float32_t` is declared in
4539
+ the header `<stdfloat>` and names such a type, the macro
4540
  `__STDCPP_FLOAT32_T__` is defined, and the floating-point literal
4541
  suffixes `f32` and `F32` are supported.
4542
 
4543
  If the implementation supports an extended floating-point type whose
4544
+ properties are specified by the ISO/IEC 60559 floating-point interchange
4545
+ format binary64, then the *typedef-name* `std::float64_t` is declared in
4546
+ the header `<stdfloat>` and names such a type, the macro
4547
  `__STDCPP_FLOAT64_T__` is defined, and the floating-point literal
4548
  suffixes `f64` and `F64` are supported.
4549
 
4550
  If the implementation supports an extended floating-point type whose
4551
+ properties are specified by the ISO/IEC 60559 floating-point interchange
4552
+ format binary128, then the *typedef-name* `std::float128_t` is declared
4553
+ in the header `<stdfloat>` and names such a type, the macro
4554
  `__STDCPP_FLOAT128_T__` is defined, and the floating-point literal
4555
  suffixes `f128` and `F128` are supported.
4556
 
4557
  If the implementation supports an extended floating-point type with the
4558
+ properties, as specified by ISO/IEC 60559, of radix (b) of 2, storage
4559
+ width in bits (k) of 16, precision in bits (p) of 8, maximum exponent
4560
+ (emax) of 127, and exponent field width in bits (w) of 8, then the
4561
+ *typedef-name* `std::bfloat16_t` is declared in the header `<stdfloat>`
4562
+ and names such a type, the macro `__STDCPP_BFLOAT16_T__` is defined, and
4563
+ the floating-point literal suffixes `bf16` and `BF16` are supported.
 
4564
 
4565
  [*Note 1*: A summary of the parameters for each type is given in
4566
  [[basic.extended.fp]]. The precision p includes the implicit 1 bit at
4567
+ the beginning of the significand, so the storage used for the
4568
+ significand is p-1 bits. ISO/IEC 60559 does not assign a name for a type
4569
+ having the parameters specified for `std::bfloat16_t`. — *end note*]
4570
 
4571
  **Table: Properties of named extended floating-point types** <a id="basic.extended.fp">[basic.extended.fp]</a>
4572
 
4573
  | Parameter | `float16_t` | `float32_t` | `float64_t` | `float128_t` | `bfloat16_t` |
4574
  | --------------------------------- | ----------- | ----------- | ----------- | ------------ | ------------ |
4575
+ | ISO/IEC 60559 name | binary16 | binary32 | binary64 | binary128 | |
4576
  | $k$, storage width in bits | 16 | 32 | 64 | 128 | 16 |
4577
  | $p$, precision in bits | 11 | 24 | 53 | 113 | 8 |
4578
  | $emax$, maximum exponent | 15 | 127 | 1023 | 16383 | 127 |
4579
  | $w$, exponent field width in bits | 5 | 8 | 11 | 15 | 8 |
4580
 
4581
 
4582
  *Recommended practice:* Any names that the implementation provides for
4583
  the extended floating-point types described in this subsection that are
4584
+ in addition to the names declared in the `<stdfloat>` header should be
4585
  chosen to increase compatibility and interoperability with the
4586
  interchange types `_Float16`, `_Float32`, `_Float64`, and `_Float128`
4587
+ defined in ISO/IEC TS 18661-3 and with future versions of \IsoCUndated.
 
4588
 
4589
  ### Compound types <a id="basic.compound">[[basic.compound]]</a>
4590
 
4591
  Compound types can be constructed in the following ways:
4592
 
4593
  - *arrays* of objects of a given type, [[dcl.array]];
4594
  - *functions*, which have parameters of given types and return `void` or
4595
+ a result of a given type, [[dcl.fct]];
4596
  - *pointers* to cv `void` or objects or functions (including static
4597
  members of classes) of a given type, [[dcl.ptr]];
4598
  - *references* to objects or functions of a given type, [[dcl.ref]].
4599
  There are two types of references:
4600
  - lvalue reference
4601
  - rvalue reference
4602
+ - *classes* containing a sequence of class members
4603
+ [[class]], [[class.mem]], and a set of restrictions on the access to
 
4604
  these entities [[class.access]];
4605
  - *unions*, which are classes capable of containing objects of different
4606
  types at different times, [[class.union]];
4607
  - *enumerations*, which comprise a set of named constant values,
4608
  [[dcl.enum]];
4609
+ - *pointers to non-static class members*,[^17] which identify members of
4610
  a given type within objects of a given class, [[dcl.mptr]]. Pointers
4611
  to data members and pointers to member functions are collectively
4612
  called *pointer-to-member* types.
4613
 
4614
  These methods of constructing types can be applied recursively;
 
4632
  “pointer to `X`”. — *end example*]
4633
 
4634
  Except for pointers to static members, text referring to “pointers” does
4635
  not apply to pointers to members. Pointers to incomplete types are
4636
  allowed although there are restrictions on what can be done with them
4637
+ [[basic.types.general]]. Every value of pointer type is one of the
4638
+ following:
4639
 
4640
  - a *pointer to* an object or function (the pointer is said to *point*
4641
  to the object or function), or
4642
  - a *pointer past the end of* an object [[expr.add]], or
4643
  - the *null pointer value* for that type, or
4644
  - an *invalid pointer value*.
4645
 
4646
  A value of a pointer type that is a pointer to or past the end of an
4647
  object *represents the address* of the first byte in memory
4648
+ [[intro.memory]] occupied by the object[^18]
4649
 
4650
  or the first byte in memory after the end of the storage occupied by the
4651
  object, respectively.
4652
 
4653
  [*Note 2*: A pointer past the end of an object [[expr.add]] is not
4654
  considered to point to an unrelated object of the object’s type, even if
4655
+ the unrelated object is located at that address. *end note*]
 
 
4656
 
4657
  For purposes of pointer arithmetic [[expr.add]] and comparison
4658
  [[expr.rel]], [[expr.eq]], a pointer past the end of the last element of
4659
  an array `x` of n elements is considered to be equivalent to a pointer
4660
+ to a hypothetical array element n of `x`, and an object of type `T` that
4661
  is not an array element is considered to belong to an array with one
4662
  element of type `T`. The value representation of pointer types is
4663
  *implementation-defined*. Pointers to layout-compatible types shall have
4664
  the same value representation and alignment requirements
4665
  [[basic.align]].
4666
 
4667
  [*Note 3*: Pointers to over-aligned types [[basic.align]] have no
4668
  special representation, but their range of valid values is restricted by
4669
  the extended alignment requirement. — *end note*]
4670
 
4671
+ A pointer value P is *valid in the context of* an evaluation E if P is a
4672
+ pointer to function or a null pointer value, or if it is a pointer to or
4673
+ past the end of an object O and E happens before the end of the duration
4674
+ of the region of storage for O. If a pointer value P is used in an
4675
+ evaluation E and P is not valid in the context of E, then the behavior
4676
+ is undefined if E is an indirection [[expr.unary.op]] or an invocation
4677
+ of a deallocation function [[basic.stc.dynamic.deallocation]], and
4678
+ *implementation-defined* otherwise.[^19]
4679
+
4680
+ [*Note 4*: P can be valid in the context of E even if it points to a
4681
+ type unrelated to that of O or if O is not within its lifetime, although
4682
+ further restrictions apply to such pointer values
4683
+ [[basic.life]], [[basic.lval]], [[expr.add]]. — *end note*]
4684
+
4685
+ Two objects *a* and *b* are *pointer-interconvertible* if
4686
 
4687
  - they are the same object, or
4688
  - one is a union object and the other is a non-static data member of
4689
  that object [[class.union]], or
4690
  - one is a standard-layout class object and the other is the first
 
4696
 
4697
  If two objects are pointer-interconvertible, then they have the same
4698
  address, and it is possible to obtain a pointer to one from a pointer to
4699
  the other via a `reinterpret_cast` [[expr.reinterpret.cast]].
4700
 
4701
+ [*Note 5*: An array object and its first element are not
4702
  pointer-interconvertible, even though they have the same
4703
  address. — *end note*]
4704
 
4705
  A byte of storage *b* is *reachable through* a pointer value that points
4706
  to an object *x* if there is an object *y*, pointer-interconvertible
 
4717
  Each type other than a function or reference type is part of a group of
4718
  four distinct, but related, types: a *cv-unqualified* version, a
4719
  *const-qualified* version, a *volatile-qualified* version, and a
4720
  *const-volatile-qualified* version. The types in each such group shall
4721
  have the same representation and alignment requirements
4722
+ [[basic.align]].[^20]
4723
 
4724
  A function or reference type is always cv-unqualified.
4725
 
4726
  - A *const object* is an object of type `const T` or a non-mutable
4727
  subobject of a const object.
 
4829
  [[expr.arith.conv]]. — *end note*]
4830
 
4831
  Every floating-point type has a *floating-point conversion rank* defined
4832
  as follows:
4833
 
4834
+ - The rank of a floating-point type `T` is greater than the rank of any
4835
  floating-point type whose set of values is a proper subset of the set
4836
  of values of `T`.
4837
  - The rank of `long double` is greater than the rank of `double`, which
4838
  is greater than the rank of `float`.
4839
  - Two extended floating-point types with the same set of values have
 
4841
  - An extended floating-point type with the same set of values as exactly
4842
  one cv-unqualified standard floating-point type has a rank equal to
4843
  the rank of that standard floating-point type.
4844
  - An extended floating-point type with the same set of values as more
4845
  than one cv-unqualified standard floating-point type has a rank equal
4846
+ to the rank of `double`.\begin{tailnote}
4847
+ The treatment of \texttt{std::float64_t} differs from
4848
+ that of the analogous \texttt{\_Float64} in C,
4849
+ for example on platforms where all of
4850
+ \texttt{\texttt{long} \texttt{double}},
4851
+ \texttt{double}, and
4852
+ \texttt{std::float64_t}
4853
+ have the same set of values (see ISO/IEC 9899:2018 (C)H.4.3).
4854
+ \end{tailnote}
4855
 
4856
  [*Note 2*: The conversion ranks of floating-point types `T1` and `T2`
4857
  are unordered if the set of values of `T1` is neither a subset nor a
4858
  superset of the set of values of `T2`. This can happen when one type has
4859
  both a larger range and a lower precision than the other. — *end note*]
 
4936
  A *full-expression* is
4937
 
4938
  - an unevaluated operand [[expr.context]],
4939
  - a *constant-expression* [[expr.const]],
4940
  - an immediate invocation [[expr.const]],
4941
+ - an *init-declarator* [[dcl.decl]] (including such introduced by a
4942
+ structured binding [[dcl.struct.bind]]) or a *mem-initializer*
4943
  [[class.base.init]], including the constituent expressions of the
4944
  initializer,
4945
  - an invocation of a destructor generated at the end of the lifetime of
4946
  an object other than a temporary object [[class.temporary]] whose
4947
+ lifetime has not been extended,
4948
+ - the predicate of a contract assertion [[basic.contract]], or
4949
  - an expression that is not a subexpression of another expression and
4950
  that is not otherwise part of a full-expression.
4951
 
4952
  If a language construct is defined to produce an implicit call of a
4953
  function, a use of the language construct is considered to be an
 
4974
  void f() {
4975
  S s2 = 2; // full-expression comprises call of S::S(int)
4976
  if (S(3).v()) // full-expression includes lvalue-to-rvalue and int to bool conversions,
4977
  // performed before temporary is deleted at end of full-expression
4978
  { }
4979
+ bool b = noexcept(S(4)); // exception specification of destructor of S considered for noexcept
4980
 
4981
  // full-expression is destruction of s2 at end of block
4982
  }
4983
  struct B {
4984
  B(S = S(0));
 
4995
  default arguments [[dcl.fct.default]] are considered to be created in
4996
  the expression that calls the function, not the expression that defines
4997
  the default argument. — *end note*]
4998
 
4999
  Reading an object designated by a `volatile` glvalue [[basic.lval]],
5000
+ modifying an object, producing an injected declaration [[expr.const]],
5001
+ calling a library I/O function, or calling a function that does any of
5002
+ those operations are all *side effects*, which are changes in the state
5003
+ of the execution or translation environment. *Evaluation* of an
5004
+ expression (or a subexpression) in general includes both value
5005
  computations (including determining the identity of an object for
5006
  glvalue evaluation and fetching a value previously assigned to an object
5007
  for prvalue evaluation) and initiation of side effects. When a call to a
5008
  library I/O function returns or an access through a volatile glvalue is
5009
+ evaluated, the side effect is considered complete, even though some
5010
  external actions implied by the call (such as the I/O itself) or by the
5011
  `volatile` access may not have completed yet.
5012
 
5013
  *Sequenced before* is an asymmetric, transitive, pair-wise relation
5014
  between evaluations executed by a single thread [[intro.multithread]],
 
5033
  expression *X* is sequenced before every value computation and every
5034
  side effect associated with the expression *Y*.
5035
 
5036
  Every value computation and side effect associated with a
5037
  full-expression is sequenced before every value computation and side
5038
+ effect associated with the next full-expression to be evaluated.[^21]
5039
 
5040
  Except where noted, evaluations of operands of individual operators and
5041
  of subexpressions of individual expressions are unsequenced.
5042
 
5043
  [*Note 5*: In an expression that is evaluated more than once during the
5044
  execution of a program, unsequenced and indeterminately sequenced
5045
  evaluations of its subexpressions need not be performed consistently in
5046
  different evaluations. — *end note*]
5047
 
5048
  The value computations of the operands of an operator are sequenced
5049
+ before the value computation of the result of the operator. The behavior
5050
+ is undefined if
5051
+
5052
+ - a side effect on a memory location [[intro.memory]] or
5053
+ - starting or ending the lifetime of an object in a memory location
5054
+
5055
+ is unsequenced relative to
5056
+
5057
+ - another side effect on the same memory location,
5058
+ - starting or ending the lifetime of an object occupying storage that
5059
+ overlaps with the memory location, or
5060
+ - a value computation using the value of any object in the same memory
5061
+ location,
5062
+
5063
+ and the two evaluations are not potentially concurrent
5064
+ [[intro.multithread]].
5065
+
5066
+ [*Note 6*: Starting the lifetime of an object in a memory location can
5067
+ end the lifetime of objects in other memory locations
5068
+ [[basic.life]]. — *end note*]
5069
+
5070
+ [*Note 7*: The next subclause imposes similar, but more complex
5071
  restrictions on potentially concurrent computations. — *end note*]
5072
 
5073
  [*Example 3*:
5074
 
5075
  ``` cpp
 
5077
  i = 7, i++, i++; // i becomes 9
5078
 
5079
  i = i++ + 1; // the value of i is incremented
5080
  i = i++ + i; // undefined behavior
5081
  i = i + 1; // the value of i is incremented
5082
+
5083
+ union U { int x, y; } u;
5084
+ (u.x = 1, 0) + (u.y = 2, 0); // undefined behavior
5085
  }
5086
  ```
5087
 
5088
  — *end example*]
5089
 
5090
+ When invoking a function *f* (whether or not the function is inline),
5091
+ every argument expression and the postfix expression designating *f* are
5092
+ sequenced before every precondition assertion of *f*
5093
+ [[dcl.contract.func]], which in turn are sequenced before every
5094
+ expression or statement in the body of *f*, which in turn are sequenced
5095
+ before every postcondition assertion of *f*.
5096
+
5097
+ For each
5098
+
5099
+ - function invocation,
5100
+ - evaluation of an *await-expression* [[expr.await]], or
5101
+ - evaluation of a *throw-expression* [[expr.throw]]
5102
+
5103
+ *F*, each evaluation that does not occur within *F* but is evaluated on
5104
+ the same thread and as part of the same signal handler (if any) is
5105
+ either sequenced before all evaluations that occur within *F* or
5106
+ sequenced after all evaluations that occur within *F*;[^22]
5107
 
5108
  if *F* invokes or resumes a coroutine [[expr.await]], only evaluations
5109
  subsequent to the previous suspension (if any) and prior to the next
5110
  suspension (if any) are considered to occur within *F*.
5111
 
 
5124
 
5125
  If a signal handler is executed as a result of a call to the
5126
  `std::raise` function, then the execution of the handler is sequenced
5127
  after the invocation of the `std::raise` function and before its return.
5128
 
5129
+ [*Note 8*: When a signal is received for another reason, the execution
5130
  of the signal handler is usually unsequenced with respect to the rest of
5131
  the program. — *end note*]
5132
 
5133
+ During the evaluation of an expression as a core constant expression
5134
+ [[expr.const]], evaluations of operands of individual operators and of
5135
+ subexpressions of individual expressions that are otherwise either
5136
+ unsequenced or indeterminately sequenced are evaluated in lexical order.
5137
+
5138
  ### Multi-threaded executions and data races <a id="intro.multithread">[[intro.multithread]]</a>
5139
 
5140
  #### General <a id="intro.multithread.general">[[intro.multithread.general]]</a>
5141
 
5142
  A *thread of execution* (also known as a *thread*) is a single flow of
 
5146
 
5147
  [*Note 1*: When one thread creates another, the initial call to the
5148
  top-level function of the new thread is executed by the new thread, not
5149
  by the creating thread. — *end note*]
5150
 
5151
+ Every thread in a program can potentially use every object and function
5152
+ in a program.[^23]
5153
 
5154
  Under a hosted implementation, a C++ program can have more than one
5155
  thread running concurrently. The execution of each thread proceeds as
5156
  defined by the remainder of this document. The execution of the entire
5157
  program consists of an execution of all of its threads.
 
5179
  Much of this subclause is motivated by the desire to support atomic
5180
  operations with explicit and detailed visibility constraints. However,
5181
  it also implicitly supports a simpler view for more restricted
5182
  programs. — *end note*]
5183
 
5184
+ Two expression evaluations *conflict* if one of them
5185
+
5186
+ - modifies [[defns.access]] a memory location [[intro.memory]] or
5187
+ - starts or ends the lifetime of an object in a memory location
5188
+
5189
+ and the other one
5190
+
5191
+ - reads or modifies the same memory location or
5192
+ - starts or ends the lifetime of an object occupying storage that
5193
+ overlaps with the memory location.
5194
+
5195
+ [*Note 2*: A modification can still conflict even if it does not alter
5196
+ the value of any bits. — *end note*]
5197
 
5198
  The library defines a number of atomic operations [[atomics]] and
5199
  operations on mutexes [[thread]] that are specially identified as
5200
  synchronization operations. These operations play a special role in
5201
  making assignments in one thread visible to another. A synchronization
5202
+ operation on one or more memory locations is either an acquire
5203
+ operation, a release operation, or both an acquire and release
5204
+ operation. A synchronization operation without an associated memory
5205
+ location is a fence and can be either an acquire fence, a release fence,
5206
+ or both an acquire and release fence. In addition, there are relaxed
5207
+ atomic operations, which are not synchronization operations, and atomic
5208
+ read-modify-write operations, which have special characteristics.
5209
 
5210
+ [*Note 3*: For example, a call that acquires a mutex will perform an
5211
  acquire operation on the locations comprising the mutex.
5212
  Correspondingly, a call that releases the same mutex will perform a
5213
  release operation on those same locations. Informally, performing a
5214
  release operation on A forces prior side effects on other memory
5215
  locations to become visible to other threads that later perform a
 
5218
  operations, they cannot contribute to data races. — *end note*]
5219
 
5220
  All modifications to a particular atomic object M occur in some
5221
  particular total order, called the *modification order* of M.
5222
 
5223
+ [*Note 4*: There is a separate order for each atomic object. There is
5224
  no requirement that these can be combined into a single total order for
5225
  all objects. In general this will be impossible since different threads
5226
  can observe modifications to different objects in inconsistent
5227
  orders. — *end note*]
5228
 
 
5234
  Certain library calls *synchronize with* other library calls performed
5235
  by another thread. For example, an atomic store-release synchronizes
5236
  with a load-acquire that takes its value from the store
5237
  [[atomics.order]].
5238
 
5239
+ [*Note 5*: Except in the specified cases, reading a later value does
5240
  not necessarily ensure visibility as described below. Such a requirement
5241
  would sometimes interfere with efficient implementation. — *end note*]
5242
 
5243
+ [*Note 6*: The specifications of the synchronization operations define
5244
  when one reads the value written by another. For atomic objects, the
5245
  definition is clear. All operations on a given mutex occur in a single
5246
  total order. Each mutex acquisition “reads the value written” by the
5247
  last mutex release. — *end note*]
5248
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5249
  An evaluation A *happens before* an evaluation B (or, equivalently, B
5250
+ happens after A) if either
 
 
 
 
 
 
 
 
 
 
 
5251
 
5252
  - A is sequenced before B, or
5253
  - A synchronizes with B, or
5254
+ - A happens before X and X happens before B.
5255
 
5256
+ [*Note 7*: An evaluation does not happen before itself. *end note*]
 
5257
 
5258
  An evaluation A *strongly happens before* an evaluation D if, either
5259
 
5260
  - A is sequenced before D, or
5261
  - A synchronizes with D, and both A and D are sequentially consistent
5262
  atomic operations [[atomics.order]], or
5263
  - there are evaluations B and C such that A is sequenced before B, B
5264
+ happens before C, and C is sequenced before D, or
5265
  - there is an evaluation B such that A strongly happens before B, and B
5266
  strongly happens before D.
5267
 
5268
+ [*Note 8*: Informally, if A strongly happens before B, then A appears
5269
+ to be evaluated before B in all contexts. *end note*]
 
5270
 
5271
  A *visible side effect* A on a scalar object or bit-field M with respect
5272
  to a value computation B of M satisfies the conditions:
5273
 
5274
  - A happens before B and
5275
  - there is no other side effect X to M such that A happens before X and
5276
  X happens before B.
5277
 
5278
  The value of a non-atomic scalar object or bit-field M, as determined by
5279
+ evaluation B, is the value stored by the visible side effect A.
5280
 
5281
+ [*Note 9*: If there is ambiguity about which side effect to a
5282
  non-atomic object or bit-field is visible, then the behavior is either
5283
  unspecified or undefined. — *end note*]
5284
 
5285
+ [*Note 10*: This states that operations on ordinary objects are not
5286
  visibly reordered. This is not actually detectable without data races,
5287
+ but is needed to ensure that data races, as defined below, and with
5288
+ suitable restrictions on the use of atomics, correspond to data races in
5289
+ a simple interleaved (sequentially consistent) execution. — *end note*]
 
5290
 
5291
+ The value of an atomic object M, as determined by evaluation B, is the
5292
+ value stored by some unspecified side effect A that modifies M, where B
5293
+ does not happen before A.
5294
 
5295
+ [*Note 11*: The set of such side effects is also restricted by the rest
5296
  of the rules described here, and in particular, by the coherence
5297
  requirements below. — *end note*]
5298
 
5299
  If an operation A that modifies an atomic object M happens before an
5300
+ operation B that modifies M, then A is earlier than B in the
5301
  modification order of M.
5302
 
5303
+ [*Note 12*: This requirement is known as write-write
5304
  coherence. — *end note*]
5305
 
5306
  If a value computation A of an atomic object M happens before a value
5307
  computation B of M, and A takes its value from a side effect X on M,
5308
+ then the value computed by B is either the value stored by X or the
5309
+ value stored by a side effect Y on M, where Y follows X in the
5310
  modification order of M.
5311
 
5312
+ [*Note 13*: This requirement is known as read-read
5313
  coherence. — *end note*]
5314
 
5315
  If a value computation A of an atomic object M happens before an
5316
+ operation B that modifies M, then A takes its value from a side effect X
5317
+ on M, where X precedes B in the modification order of M.
5318
 
5319
+ [*Note 14*: This requirement is known as read-write
5320
  coherence. — *end note*]
5321
 
5322
  If a side effect X on an atomic object M happens before a value
5323
+ computation B of M, then the evaluation B takes its value from X or from
5324
+ a side effect Y that follows X in the modification order of M.
5325
 
5326
+ [*Note 15*: This requirement is known as write-read
5327
  coherence. — *end note*]
5328
 
5329
+ [*Note 16*: The four preceding coherence requirements effectively
5330
  disallow compiler reordering of atomic operations to a single object,
5331
  even if both operations are relaxed loads. This effectively makes the
5332
  cache coherence guarantee provided by most hardware available to C++
5333
  atomic operations. — *end note*]
5334
 
5335
+ [*Note 17*: The value observed by a load of an atomic depends on the
5336
  “happens before” relation, which depends on the values observed by loads
5337
  of atomics. The intended reading is that there must exist an association
5338
  of atomic loads with modifications they observe that, together with
5339
  suitably chosen modification orders and the “happens before” relation
5340
  derived as described above, satisfy the resulting constraints as imposed
 
5350
  potentially concurrent conflicting actions, at least one of which is not
5351
  atomic, and neither happens before the other, except for the special
5352
  case for signal handlers described below. Any such data race results in
5353
  undefined behavior.
5354
 
5355
+ [*Note 18*: It can be shown that programs that correctly use mutexes
5356
  and `memory_order::seq_cst` operations to prevent all data races and use
5357
  no other synchronization operations behave as if the operations executed
5358
  by their constituent threads were simply interleaved, with each value
5359
  computation of an object being taken from the last side effect on that
5360
  object in that interleaving. This is normally referred to as “sequential
5361
  consistency”. However, this applies only to data-race-free programs, and
5362
  data-race-free programs cannot observe most program transformations that
5363
  do not change single-threaded program semantics. In fact, most
5364
+ single-threaded program transformations remain possible, since any
5365
+ program that behaves differently as a result has undefined
5366
  behavior. — *end note*]
5367
 
5368
+ Two accesses to the same non-bit-field object of type
5369
+ `volatile std::sig_atomic_t` do not result in a data race if both occur
5370
+ in the same thread, even if one or more occurs in a signal handler. For
5371
+ each signal handler invocation, evaluations performed by the thread
5372
+ invoking a signal handler can be divided into two groups A and B, such
5373
+ that no evaluations in B happen before evaluations in A, and the
5374
+ evaluations of such `volatile std::sig_atomic_t` objects take values as
5375
+ though all evaluations in A happened before the execution of the signal
5376
+ handler and the execution of the signal handler happened before all
5377
+ evaluations in B.
5378
 
5379
+ [*Note 19*: Compiler transformations that introduce assignments to a
5380
  potentially shared memory location that would not be modified by the
5381
  abstract machine are generally precluded by this document, since such an
5382
  assignment might overwrite another assignment by a different thread in
5383
  cases in which an abstract machine execution would not have encountered
5384
  a data race. This includes implementations of data member assignment
5385
  that overwrite adjacent members in separate memory locations. Reordering
5386
  of atomic loads in cases in which the atomics in question might alias is
5387
  also generally precluded, since this could violate the coherence
5388
  rules. — *end note*]
5389
 
5390
+ [*Note 20*: It is possible that transformations that introduce a
5391
+ speculative read of a potentially shared memory location do not preserve
5392
+ the semantics of the C++ program as defined in this document, since they
5393
+ potentially introduce a data race. However, they are typically valid in
5394
+ the context of an optimizing compiler that targets a specific machine
5395
+ with well-defined semantics for data races. They would be invalid for a
5396
  hypothetical machine that is not tolerant of races or provides hardware
5397
  race detection. — *end note*]
5398
 
5399
  #### Forward progress <a id="intro.progress">[[intro.progress]]</a>
5400
 
5401
  The implementation may assume that any thread will eventually do one of
5402
  the following:
5403
 
5404
  - terminate,
5405
+ - invoke the function `std::this_thread::yield` [[thread.thread.this]],
5406
  - make a call to a library I/O function,
5407
+ - perform an access through a volatile glvalue,
5408
+ - perform an atomic or synchronization operation other than an atomic
5409
+ modify-write operation [[atomics.order]], or
5410
+ - continue execution of a trivial infinite loop [[stmt.iter.general]].
5411
 
5412
  [*Note 1*: This is intended to allow compiler transformations such as
5413
+ removal, merging, and reordering of empty loops, even when termination
5414
+ cannot be proven. An affordance is made for trivial infinite loops,
5415
+ which cannot be removed nor reordered. — *end note*]
5416
 
5417
  Executions of atomic functions that are either defined to be lock-free
5418
  [[atomics.flag]] or indicated as lock-free [[atomics.lockfree]] are
5419
  *lock-free executions*.
5420
 
 
5438
 
5439
  During the execution of a thread of execution, each of the following is
5440
  termed an *execution step*:
5441
 
5442
  - termination of the thread of execution,
5443
+ - performing an access through a volatile glvalue,
5444
+ - completion of a call to a library I/O function, or
5445
+ - completion of an atomic or synchronization operation other than an
5446
+ atomic modify-write operation [[atomics.order]].
5447
 
5448
  An invocation of a standard library function that blocks [[defns.block]]
5449
  is considered to continuously execute execution steps while waiting for
5450
  the condition that it blocks on to be satisfied.
5451
 
 
5467
 
5468
  For a thread of execution providing *concurrent forward progress
5469
  guarantees*, the implementation ensures that the thread will eventually
5470
  make progress for as long as it has not terminated.
5471
 
5472
+ [*Note 5*: This applies regardless of whether or not other threads of
5473
+ execution (if any) have been or are making progress. To eventually
5474
  fulfill this requirement means that this will happen in an unspecified
5475
  but finite amount of time. — *end note*]
5476
 
5477
  It is *implementation-defined* whether the implementation-created thread
5478
  of execution that executes `main` [[basic.start.main]] and the threads
 
5585
  arguments passed to the program from the environment in which the
5586
  program is run. If `argc` is nonzero these arguments shall be supplied
5587
  in `argv[0]` through `argv[argc - 1]` as pointers to the initial
5588
  characters of null-terminated multibyte strings (NTMBSs)
5589
  [[multibyte.strings]] and `argv[0]` shall be the pointer to the initial
5590
+ character of an NTMBS that represents the name used to invoke the
5591
+ program or `""`. The value of `argc` shall be non-negative. The value of
5592
  `argv[argc]` shall be 0.
5593
 
5594
  *Recommended practice:* Any further (optional) parameters should be
5595
  added after `argv`.
5596
 
5597
+ The function `main` shall not be named by an expression. The linkage
5598
  [[basic.link]] of `main` is *implementation-defined*. A program that
5599
  defines `main` as deleted or that declares `main` to be `inline`,
5600
  `static`, `constexpr`, or `consteval` is ill-formed. The function `main`
5601
  shall not be a coroutine [[dcl.fct.def.coroutine]]. The `main` function
5602
+ shall not be declared with a *linkage-specification* [[dcl.link]] other
5603
+ than `"C++"`. A program that declares
5604
 
5605
  - a variable `main` that belongs to the global scope, or
5606
  - a function `main` that belongs to the global scope and is attached to
5607
  a named module, or
5608
  - a function template `main` that belongs to the global scope, or
 
5618
  destroy any objects with automatic storage duration [[class.dtor]]. If
5619
  `std::exit` is invoked during the destruction of an object with static
5620
  or thread storage duration, the program has undefined behavior.
5621
 
5622
  A `return` statement [[stmt.return]] in `main` has the effect of leaving
5623
+ the `main` function (destroying any objects with automatic storage
5624
+ duration and evaluating any postcondition assertions of `main`) and
5625
+ calling `std::exit` with the return value as the argument. If control
5626
+ flows off the end of the *compound-statement* of `main`, the effect is
5627
+ equivalent to a `return` with operand `0` (see also [[except.handle]]).
5628
 
5629
  #### Static initialization <a id="basic.start.static">[[basic.start.static]]</a>
5630
 
5631
  Variables with static storage duration are initialized as a consequence
5632
  of program initiation. Variables with thread storage duration are
5633
  initialized as a consequence of thread execution. Within each of these
5634
  phases of initiation, initialization occurs as follows.
5635
 
5636
+ *Constant initialization* is performed if a variable with static or
5637
+ thread storage duration is constant-initialized [[expr.const]]. If
5638
+ constant initialization is not performed, a variable with static storage
5639
+ duration [[basic.stc.static]] or thread storage duration
5640
+ [[basic.stc.thread]] is zero-initialized [[dcl.init]]. Together,
5641
+ zero-initialization and constant initialization are called
5642
  *static initialization*; all other initialization is
5643
  *dynamic initialization*. All static initialization strongly happens
5644
  before [[intro.races]] any dynamic initialization.
5645
 
5646
  [*Note 1*: The dynamic initialization of non-block variables is
 
5733
  It is *implementation-defined* whether the dynamic initialization of a
5734
  non-block non-inline variable with static storage duration is sequenced
5735
  before the first statement of `main` or is deferred. If it is deferred,
5736
  it strongly happens before any non-initialization odr-use of any
5737
  non-inline function or non-inline variable defined in the same
5738
+ translation unit as the variable to be initialized.[^24]
5739
 
5740
  It is *implementation-defined* in which threads and at which points in
5741
  the program such deferred dynamic initialization occurs.
5742
 
5743
  *Recommended practice:* An implementation should choose such points in a
 
5873
 
5874
  Calling the function `std::abort()` declared in `<cstdlib>` terminates
5875
  the program without executing any destructors and without calling the
5876
  functions passed to `std::atexit()` or `std::at_quick_exit()`.
5877
 
5878
+ ## Contract assertions <a id="basic.contract">[[basic.contract]]</a>
5879
+
5880
+ ### General <a id="basic.contract.general">[[basic.contract.general]]</a>
5881
+
5882
+ *Contract assertions* allow the programmer to specify properties of the
5883
+ state of the program that are expected to hold at certain points during
5884
+ execution. Contract assertions are introduced by
5885
+ *precondition-specifier*s, *postcondition-specifier*s
5886
+ [[dcl.contract.func]], and *assertion-statement*s
5887
+ [[stmt.contract.assert]].
5888
+
5889
+ Each contract assertion has a *contract-assertion predicate*, which is
5890
+ an expression of type `bool`.
5891
+
5892
+ [*Note 1*: The value of the predicate is used to identify program
5893
+ states that are expected. — *end note*]
5894
+
5895
+ An invocation of the macro `va_start` [[cstdarg.syn]] shall not be a
5896
+ subexpression of the predicate of a contract assertion, no diagnostic
5897
+ required.
5898
+
5899
+ [*Note 2*: Within the predicate of a contract assertion,
5900
+ *id-expression*s referring to variables declared outside the contract
5901
+ assertion are `const` [[expr.prim.id.unqual]], `this` is a pointer to
5902
+ `const` [[expr.prim.this]], and the result object can be named if a
5903
+ *result-name-introducer* [[dcl.contract.res]] has been
5904
+ specified. — *end note*]
5905
+
5906
+ ### Evaluation <a id="basic.contract.eval">[[basic.contract.eval]]</a>
5907
+
5908
+ An evaluation of a contract assertion uses one of the following four
5909
+ *evaluation semantics*: *ignore*, *observe*, *enforce*, or
5910
+ *quick-enforce*. Observe, enforce, and quick-enforce are *checking
5911
+ semantics*; enforce and quick-enforce are *terminating semantics*.
5912
+
5913
+ It is *implementation-defined* which evaluation semantic is used for any
5914
+ given evaluation of a contract assertion.
5915
+
5916
+ [*Note 1*: The range and flexibility of available choices of evaluation
5917
+ semantics depends on the implementation and need not allow all four
5918
+ evaluation semantics as possibilities. The evaluation semantics can
5919
+ differ for different evaluations of the same contract assertion,
5920
+ including evaluations during constant evaluation. — *end note*]
5921
+
5922
+ *Recommended practice:* An implementation should provide the option to
5923
+ translate a program such that all evaluations of contract assertions use
5924
+ the ignore semantic as well as the option to translate a program such
5925
+ that all evaluations of contract assertions use the enforce semantic. By
5926
+ default, evaluations of contract assertions should use the enforce
5927
+ semantic.
5928
+
5929
+ The evaluation of a contract assertion using the ignore semantic has no
5930
+ effect.
5931
+
5932
+ [*Note 2*: The predicate is potentially evaluated [[basic.def.odr]],
5933
+ but not evaluated. — *end note*]
5934
+
5935
+ The evaluation A of a contract assertion using a checking semantic
5936
+ determines the value of the predicate. It is unspecified whether the
5937
+ predicate is evaluated. Let B be the value that would result from
5938
+ evaluating the predicate.
5939
+
5940
+ [*Note 3*:
5941
+
5942
+ To determine whether a predicate would evaluate to `true` or `false`, an
5943
+ alternative evaluation that produces the same value as the predicate but
5944
+ has no side effects can occur.
5945
+
5946
+ [*Example 1*:
5947
+
5948
+ ``` cpp
5949
+ struct S {
5950
+ mutable int g = 5;
5951
+ } s;
5952
+ void f()
5953
+ pre(( s.g++, false )); // #1
5954
+ void g()
5955
+ {
5956
+ f(); // Increment of s.g might not occur, even if #1 uses a checking semantic.
5957
+ }
5958
+ ```
5959
+
5960
+ — *end example*]
5961
+
5962
+ — *end note*]
5963
+
5964
+ There is an observable checkpoint [[intro.abstract]] C that happens
5965
+ before A such that any other operation O that happens before A also
5966
+ happens before C.
5967
+
5968
+ A *contract violation* occurs when
5969
+
5970
+ - B is `false`,
5971
+ - the evaluation of the predicate exits via an exception, or
5972
+ - the evaluation of the predicate is performed in a context that is
5973
+ manifestly constant-evaluated [[expr.const]] and the predicate is not
5974
+ a core constant expression.
5975
+
5976
+ [*Note 4*: If B is `true`, no contract violation occurs and control
5977
+ flow continues normally after the point of evaluation of the contract
5978
+ assertion. The evaluation of the predicate can fail to produce a value
5979
+ without causing a contract violation, for example, by calling `longjmp`
5980
+ [[csetjmp.syn]] or terminating the program. — *end note*]
5981
+
5982
+ If a contract violation occurs in a context that is manifestly
5983
+ constant-evaluated [[expr.const]], and the evaluation semantic is a
5984
+ terminating semantic, the program is ill-formed.
5985
+
5986
+ [*Note 5*: A diagnostic is produced if the evaluation semantic is
5987
+ observe [[intro.compliance]]. — *end note*]
5988
+
5989
+ [*Note 6*:
5990
+
5991
+ Different evaluation semantics chosen for the same contract assertion in
5992
+ different translation units can result in violations of the
5993
+ one-definition rule [[basic.def.odr]] when a contract assertion has side
5994
+ effects that alter the value produced by a constant expression.
5995
+
5996
+ [*Example 2*:
5997
+
5998
+ ``` cpp
5999
+ constexpr int f(int i)
6000
+ {
6001
+ contract_assert((++const_cast<int&>(i), true));
6002
+ return i;
6003
+ }
6004
+ inline void g()
6005
+ {
6006
+ int a[f(1)]; // size dependent on the evaluation semantic of contract_assert above
6007
+ }
6008
+ ```
6009
+
6010
+ — *end example*]
6011
+
6012
+ — *end note*]
6013
+
6014
+ When the program is *contract-terminated*, it is
6015
+ *implementation-defined* (depending on context) whether
6016
+
6017
+ - `std::terminate` is called,
6018
+ - `std::abort` is called, or
6019
+ - execution is terminated. \[*Note 7*: No further execution steps occur
6020
+ [[intro.progress]]. — *end note*]
6021
+
6022
+ [*Note 8*: Performing the actions of `std::terminate` or `std::abort`
6023
+ without actually making a library call is a conforming implementation of
6024
+ contract-termination [[intro.abstract]]. — *end note*]
6025
+
6026
+ If a contract violation occurs in a context that is not manifestly
6027
+ constant-evaluated and the evaluation semantic is quick-enforce, the
6028
+ program is contract-terminated.
6029
+
6030
+ If a contract violation occurs in a context that is not manifestly
6031
+ constant-evaluated and the evaluation semantic is enforce or observe,
6032
+ the contract-violation handler [[basic.contract.handler]] is invoked
6033
+ with an lvalue referring to an object `v` of type
6034
+ `const std::contracts::contract_violation`
6035
+ [[support.contract.violation]] containing information about the contract
6036
+ violation. Storage for `v` is allocated in an unspecified manner except
6037
+ as noted in [[basic.stc.dynamic.allocation]]. The lifetime of `v`
6038
+ persists for the duration of the invocation of the contract-violation
6039
+ handler.
6040
+
6041
+ If the contract violation occurred because the evaluation of the
6042
+ predicate exited via an exception, the contract-violation handler is
6043
+ invoked from within an active implicit handler for that exception
6044
+ [[except.handle]]. If the contract-violation handler returns normally
6045
+ and the evaluation semantic is observe, that implicit handler is no
6046
+ longer considered active.
6047
+
6048
+ [*Note 9*: The exception can be inspected or rethrown within the
6049
+ contract-violation handler. — *end note*]
6050
+
6051
+ If the contract-violation handler returns normally and the evaluation
6052
+ semantic is enforce, the program is contract-terminated; if violation
6053
+ occurred as the result of an uncaught exception from the evaluation of
6054
+ the predicate, the implicit handler remains active when contract
6055
+ termination occurs.
6056
+
6057
+ [*Note 10*: If the contract-violation handler returns normally and the
6058
+ evaluation semantic is observe, control flow continues normally after
6059
+ the point of evaluation of the contract assertion. — *end note*]
6060
+
6061
+ There is an observable checkpoint [[intro.abstract]] C that happens
6062
+ after the contract-violation handler returns normally such that any
6063
+ other operation O that happens after the contract-violation handler
6064
+ returns also happens after C.
6065
+
6066
+ [*Note 11*: The terminating semantics terminate the program if
6067
+ execution would otherwise continue normally past a contract violation:
6068
+ the enforce semantic provides the opportunity to log information about
6069
+ the contract violation before terminating the program or to throw an
6070
+ exception to avoid termination, and the quick-enforce semantic is
6071
+ intended to terminate the program as soon as possible as well as to
6072
+ minimize the impact of contract checks on the generated code size.
6073
+ Conversely, the observe semantic provides the opportunity to log
6074
+ information about the contract violation without having to terminate the
6075
+ program. — *end note*]
6076
+
6077
+ If a contract-violation handler invoked from the evaluation of a
6078
+ function contract assertion [[dcl.contract.func]] exits via an
6079
+ exception, the behavior is as if the function body exits via that same
6080
+ exception.
6081
+
6082
+ [*Note 12*: A *function-try-block* [[except.pre]] is the function body
6083
+ when present and thus does not have an opportunity to catch the
6084
+ exception. If the function has a non-throwing exception specification,
6085
+ the function `std::terminate` is invoked
6086
+ [[except.terminate]]. — *end note*]
6087
+
6088
+ [*Note 13*: If a contract-violation handler invoked from an
6089
+ *assertion-statement* [[stmt.contract.assert]] exits via an exception,
6090
+ the search for a handler continues from the execution of that
6091
+ statement. — *end note*]
6092
+
6093
+ To *evaluate in sequence* a list R of contract assertions:
6094
+
6095
+ - Construct a list of contract assertions S such that
6096
+ - all elements of R are in S,
6097
+ - each element of R may be repeated an *implementation-defined* number
6098
+ of times within S, and
6099
+ - if a contract assertion A precedes another contract assertion B in
6100
+ R, then the first occurrence of A precedes the first occurrence of B
6101
+ in S.
6102
+ - Evaluate each element of S such that, if a contract assertion A
6103
+ precedes a contract assertion B in S, then the evaluation of A is
6104
+ sequenced before the evaluation of B.
6105
+
6106
+ [*Example 3*:
6107
+
6108
+ ``` cpp
6109
+ void f(int i)
6110
+ {
6111
+ contract_assert(i > 0); // #1
6112
+ contract_assert(i < 10); // #2
6113
+ // valid sequence of evaluations: #1 #2
6114
+ // valid sequence of evaluations: #1 #1 #2 #2
6115
+ // valid sequence of evaluations: #1 #2 #1 #2
6116
+ // valid sequence of evaluations: #1 #2 #2 #1
6117
+ // invalid sequence of evaluations: #2 #1
6118
+ }
6119
+ ```
6120
+
6121
+ — *end example*]
6122
+
6123
+ *Recommended practice:* An implementation should provide an option to
6124
+ perform a specified number of repeated evaluations for contract
6125
+ assertions. By default, no repeated evaluations should be performed.
6126
+
6127
+ ### Contract-violation handler <a id="basic.contract.handler">[[basic.contract.handler]]</a>
6128
+
6129
+ The *contract-violation handler* of a program is a function named
6130
+ `::handle_contract_violation`. The contract-violation handler shall have
6131
+ a single parameter of type “lvalue reference to `const`
6132
+ `std::contracts::contract_violation`” and shall return `void`. The
6133
+ contract-violation handler may have a non-throwing exception
6134
+ specification. The implementation shall provide a definition of the
6135
+ contract-violation handler, called the
6136
+ *default contract-violation handler*.
6137
+
6138
+ [*Note 1*: No declaration for the default contract-violation handler is
6139
+ provided by any standard library header. — *end note*]
6140
+
6141
+ *Recommended practice:* The default contract-violation handler should
6142
+ produce diagnostic output that suitably formats the most relevant
6143
+ contents of the `std::contracts::contract_violation` object,
6144
+ rate-limited for potentially repeated violations of observed contract
6145
+ assertions, and then return normally.
6146
+
6147
+ It is *implementation-defined* whether the contract-violation handler is
6148
+ replaceable [[term.replaceable.function]]. If the contract-violation
6149
+ handler is not replaceable, a declaration of a replacement function for
6150
+ the contract-violation handler is ill-formed, no diagnostic required.
6151
+
6152
  <!-- Link reference definitions -->
6153
  [allocator.members]: mem.md#allocator.members
 
6154
  [atomics]: thread.md#atomics
6155
  [atomics.flag]: thread.md#atomics.flag
6156
  [atomics.lockfree]: thread.md#atomics.lockfree
6157
  [atomics.order]: thread.md#atomics.order
6158
  [bad.alloc]: support.md#bad.alloc
6159
  [basic]: #basic
6160
  [basic.align]: #basic.align
6161
  [basic.compound]: #basic.compound
6162
+ [basic.contract]: #basic.contract
6163
+ [basic.contract.eval]: #basic.contract.eval
6164
+ [basic.contract.general]: #basic.contract.general
6165
+ [basic.contract.handler]: #basic.contract.handler
6166
  [basic.def]: #basic.def
6167
  [basic.def.odr]: #basic.def.odr
6168
  [basic.exec]: #basic.exec
6169
  [basic.extended.fp]: #basic.extended.fp
6170
  [basic.fundamental]: #basic.fundamental
 
6181
  [basic.lookup.udir]: #basic.lookup.udir
6182
  [basic.lookup.unqual]: #basic.lookup.unqual
6183
  [basic.lval]: expr.md#basic.lval
6184
  [basic.memobj]: #basic.memobj
6185
  [basic.namespace]: dcl.md#basic.namespace
6186
+ [basic.namespace.general]: dcl.md#basic.namespace.general
6187
  [basic.pre]: #basic.pre
6188
  [basic.scope]: #basic.scope
6189
  [basic.scope.block]: #basic.scope.block
6190
  [basic.scope.class]: #basic.scope.class
6191
+ [basic.scope.contract]: #basic.scope.contract
6192
  [basic.scope.enum]: #basic.scope.enum
6193
  [basic.scope.lambda]: #basic.scope.lambda
6194
  [basic.scope.namespace]: #basic.scope.namespace
6195
  [basic.scope.param]: #basic.scope.param
6196
  [basic.scope.pdecl]: #basic.scope.pdecl
6197
  [basic.scope.scope]: #basic.scope.scope
6198
  [basic.scope.temp]: #basic.scope.temp
6199
+ [basic.splice]: #basic.splice
6200
  [basic.start]: #basic.start
6201
  [basic.start.dynamic]: #basic.start.dynamic
6202
  [basic.start.main]: #basic.start.main
6203
  [basic.start.static]: #basic.start.static
6204
  [basic.start.term]: #basic.start.term
 
6207
  [basic.stc.dynamic]: #basic.stc.dynamic
6208
  [basic.stc.dynamic.allocation]: #basic.stc.dynamic.allocation
6209
  [basic.stc.dynamic.deallocation]: #basic.stc.dynamic.deallocation
6210
  [basic.stc.dynamic.general]: #basic.stc.dynamic.general
6211
  [basic.stc.general]: #basic.stc.general
 
6212
  [basic.stc.static]: #basic.stc.static
6213
  [basic.stc.thread]: #basic.stc.thread
6214
  [basic.type.qualifier]: #basic.type.qualifier
6215
  [basic.type.qualifier.rel]: #basic.type.qualifier.rel
6216
  [basic.types]: #basic.types
 
6228
  [class.copy.assign]: class.md#class.copy.assign
6229
  [class.copy.ctor]: class.md#class.copy.ctor
6230
  [class.copy.elision]: class.md#class.copy.elision
6231
  [class.default.ctor]: class.md#class.default.ctor
6232
  [class.derived]: class.md#class.derived
6233
+ [class.derived.general]: class.md#class.derived.general
6234
  [class.dtor]: class.md#class.dtor
6235
  [class.free]: class.md#class.free
6236
  [class.friend]: class.md#class.friend
6237
  [class.mem]: class.md#class.mem
6238
+ [class.mem.general]: class.md#class.mem.general
6239
  [class.member.lookup]: #class.member.lookup
 
 
6240
  [class.name]: class.md#class.name
6241
  [class.pre]: class.md#class.pre
6242
  [class.prop]: class.md#class.prop
6243
  [class.qual]: #class.qual
6244
  [class.spaceship]: class.md#class.spaceship
 
6254
  [conv.integral]: expr.md#conv.integral
6255
  [conv.lval]: expr.md#conv.lval
6256
  [conv.mem]: expr.md#conv.mem
6257
  [conv.prom]: expr.md#conv.prom
6258
  [conv.ptr]: expr.md#conv.ptr
6259
+ [conv.qual]: expr.md#conv.qual
6260
  [conv.rank]: #conv.rank
6261
  [conv.rval]: expr.md#conv.rval
6262
  [cpp.predefined]: cpp.md#cpp.predefined
6263
+ [csetjmp.syn]: support.md#csetjmp.syn
6264
+ [cstdarg.syn]: support.md#cstdarg.syn
6265
  [cstddef.syn]: support.md#cstddef.syn
6266
  [cstring.syn]: strings.md#cstring.syn
6267
  [dcl.align]: dcl.md#dcl.align
6268
  [dcl.array]: dcl.md#dcl.array
6269
  [dcl.attr]: dcl.md#dcl.attr
6270
+ [dcl.attr.grammar]: dcl.md#dcl.attr.grammar
6271
+ [dcl.attr.indet]: dcl.md#dcl.attr.indet
6272
  [dcl.attr.nouniqueaddr]: dcl.md#dcl.attr.nouniqueaddr
6273
  [dcl.constexpr]: dcl.md#dcl.constexpr
6274
+ [dcl.contract.func]: dcl.md#dcl.contract.func
6275
+ [dcl.contract.res]: dcl.md#dcl.contract.res
6276
  [dcl.decl]: dcl.md#dcl.decl
6277
  [dcl.enum]: dcl.md#dcl.enum
6278
  [dcl.fct]: dcl.md#dcl.fct
6279
  [dcl.fct.def]: dcl.md#dcl.fct.def
6280
  [dcl.fct.def.coroutine]: dcl.md#dcl.fct.def.coroutine
6281
  [dcl.fct.def.general]: dcl.md#dcl.fct.def.general
6282
  [dcl.fct.default]: dcl.md#dcl.fct.default
6283
  [dcl.init]: dcl.md#dcl.init
6284
  [dcl.init.aggr]: dcl.md#dcl.init.aggr
6285
+ [dcl.init.general]: dcl.md#dcl.init.general
6286
  [dcl.init.list]: dcl.md#dcl.init.list
6287
  [dcl.init.ref]: dcl.md#dcl.init.ref
6288
  [dcl.link]: dcl.md#dcl.link
6289
  [dcl.meaning]: dcl.md#dcl.meaning
6290
+ [dcl.meaning.general]: dcl.md#dcl.meaning.general
6291
  [dcl.mptr]: dcl.md#dcl.mptr
6292
  [dcl.name]: dcl.md#dcl.name
6293
  [dcl.pre]: dcl.md#dcl.pre
6294
  [dcl.ptr]: dcl.md#dcl.ptr
6295
  [dcl.ref]: dcl.md#dcl.ref
 
6298
  [dcl.stc]: dcl.md#dcl.stc
6299
  [dcl.struct.bind]: dcl.md#dcl.struct.bind
6300
  [dcl.type.decltype]: dcl.md#dcl.type.decltype
6301
  [dcl.type.elab]: dcl.md#dcl.type.elab
6302
  [dcl.typedef]: dcl.md#dcl.typedef
6303
+ [defns.access]: intro.md#defns.access
6304
  [defns.block]: intro.md#defns.block
6305
  [depr.local]: future.md#depr.local
6306
  [depr.static.constexpr]: future.md#depr.static.constexpr
6307
  [diff.cpp11.basic]: compatibility.md#diff.cpp11.basic
6308
  [enum.udecl]: dcl.md#enum.udecl
 
6312
  [except.terminate]: except.md#except.terminate
6313
  [except.throw]: except.md#except.throw
6314
  [expr.add]: expr.md#expr.add
6315
  [expr.alignof]: expr.md#expr.alignof
6316
  [expr.arith.conv]: expr.md#expr.arith.conv
6317
+ [expr.assign]: expr.md#expr.assign
6318
  [expr.await]: expr.md#expr.await
6319
  [expr.call]: expr.md#expr.call
6320
  [expr.cast]: expr.md#expr.cast
6321
  [expr.comma]: expr.md#expr.comma
6322
  [expr.cond]: expr.md#expr.cond
 
6324
  [expr.const.cast]: expr.md#expr.const.cast
6325
  [expr.context]: expr.md#expr.context
6326
  [expr.delete]: expr.md#expr.delete
6327
  [expr.dynamic.cast]: expr.md#expr.dynamic.cast
6328
  [expr.eq]: expr.md#expr.eq
 
 
6329
  [expr.mptr.oper]: expr.md#expr.mptr.oper
6330
  [expr.new]: expr.md#expr.new
6331
  [expr.pre]: expr.md#expr.pre
6332
  [expr.prim.id]: expr.md#expr.prim.id
6333
+ [expr.prim.id.general]: expr.md#expr.prim.id.general
6334
  [expr.prim.id.qual]: expr.md#expr.prim.id.qual
6335
  [expr.prim.id.unqual]: expr.md#expr.prim.id.unqual
6336
  [expr.prim.lambda]: expr.md#expr.prim.lambda
6337
  [expr.prim.lambda.capture]: expr.md#expr.prim.lambda.capture
6338
  [expr.prim.lambda.closure]: expr.md#expr.prim.lambda.closure
6339
+ [expr.prim.splice]: expr.md#expr.prim.splice
6340
  [expr.prim.this]: expr.md#expr.prim.this
6341
  [expr.prop]: expr.md#expr.prop
6342
  [expr.ref]: expr.md#expr.ref
6343
+ [expr.reflect]: expr.md#expr.reflect
6344
  [expr.reinterpret.cast]: expr.md#expr.reinterpret.cast
6345
  [expr.rel]: expr.md#expr.rel
6346
  [expr.sizeof]: expr.md#expr.sizeof
6347
  [expr.static.cast]: expr.md#expr.static.cast
6348
  [expr.sub]: expr.md#expr.sub
6349
+ [expr.throw]: expr.md#expr.throw
6350
  [expr.type.conv]: expr.md#expr.type.conv
6351
  [expr.typeid]: expr.md#expr.typeid
6352
+ [expr.unary.noexcept]: expr.md#expr.unary.noexcept
6353
  [expr.unary.op]: expr.md#expr.unary.op
6354
  [get.new.handler]: support.md#get.new.handler
6355
  [headers]: library.md#headers
6356
+ [intro.abstract]: intro.md#intro.abstract
6357
+ [intro.compliance]: intro.md#intro.compliance
6358
  [intro.execution]: #intro.execution
6359
  [intro.memory]: #intro.memory
6360
  [intro.multithread]: #intro.multithread
6361
  [intro.multithread.general]: #intro.multithread.general
6362
  [intro.object]: #intro.object
6363
  [intro.progress]: #intro.progress
6364
  [intro.races]: #intro.races
6365
  [lex.charset]: lex.md#lex.charset
6366
  [lex.fcon]: lex.md#lex.fcon
6367
  [lex.name]: lex.md#lex.name
6368
+ [lex.phases]: lex.md#lex.phases
6369
+ [lex.string]: lex.md#lex.string
6370
+ [mem.res.public]: mem.md#mem.res.public
6371
+ [meta.define.static]: meta.md#meta.define.static
6372
+ [meta.reflection.operators]: meta.md#meta.reflection.operators
6373
+ [meta.syn]: meta.md#meta.syn
6374
  [module.context]: module.md#module.context
6375
  [module.global.frag]: module.md#module.global.frag
6376
  [module.interface]: module.md#module.interface
6377
  [module.reach]: module.md#module.reach
6378
  [module.unit]: module.md#module.unit
6379
  [multibyte.strings]: library.md#multibyte.strings
6380
+ [namespace.alias]: dcl.md#namespace.alias
6381
  [namespace.def]: dcl.md#namespace.def
6382
  [namespace.qual]: #namespace.qual
6383
  [namespace.udecl]: dcl.md#namespace.udecl
6384
  [namespace.udir]: dcl.md#namespace.udir
6385
  [namespace.unnamed]: dcl.md#namespace.unnamed
 
6386
  [new.delete.array]: support.md#new.delete.array
6387
  [new.delete.placement]: support.md#new.delete.placement
6388
  [new.delete.single]: support.md#new.delete.single
6389
  [new.handler]: support.md#new.handler
6390
  [new.syn]: support.md#new.syn
 
6395
  [over.match.funcs]: over.md#over.match.funcs
6396
  [over.oper]: over.md#over.oper
6397
  [over.over]: over.md#over.over
6398
  [ptr.align]: mem.md#ptr.align
6399
  [ptr.launder]: support.md#ptr.launder
 
6400
  [special]: class.md#special
6401
  [std.modules]: library.md#std.modules
6402
  [stdfloat.syn]: support.md#stdfloat.syn
6403
  [stmt.block]: stmt.md#stmt.block
6404
+ [stmt.contract.assert]: stmt.md#stmt.contract.assert
6405
  [stmt.dcl]: stmt.md#stmt.dcl
6406
+ [stmt.expand]: stmt.md#stmt.expand
6407
  [stmt.expr]: stmt.md#stmt.expr
6408
  [stmt.if]: stmt.md#stmt.if
6409
  [stmt.iter]: stmt.md#stmt.iter
6410
+ [stmt.iter.general]: stmt.md#stmt.iter.general
6411
  [stmt.pre]: stmt.md#stmt.pre
6412
  [stmt.ranged]: stmt.md#stmt.ranged
6413
  [stmt.return]: stmt.md#stmt.return
6414
  [stmt.select]: stmt.md#stmt.select
6415
+ [support.contract.violation]: support.md#support.contract.violation
6416
  [support.dynamic]: support.md#support.dynamic
6417
  [support.runtime]: support.md#support.runtime
6418
  [support.start.term]: support.md#support.start.term
6419
  [support.types]: support.md#support.types
6420
+ [temp.alias]: temp.md#temp.alias
6421
  [temp.concept]: temp.md#temp.concept
6422
  [temp.deduct.guide]: temp.md#temp.deduct.guide
6423
  [temp.dep]: temp.md#temp.dep
6424
  [temp.dep.candidate]: temp.md#temp.dep.candidate
6425
  [temp.dep.constexpr]: temp.md#temp.dep.constexpr
6426
+ [temp.dep.splice]: temp.md#temp.dep.splice
6427
  [temp.dep.type]: temp.md#temp.dep.type
6428
  [temp.expl.spec]: temp.md#temp.expl.spec
6429
  [temp.explicit]: temp.md#temp.explicit
6430
  [temp.friend]: temp.md#temp.friend
6431
  [temp.local]: temp.md#temp.local
 
6436
  [temp.point]: temp.md#temp.point
6437
  [temp.pre]: temp.md#temp.pre
6438
  [temp.res]: temp.md#temp.res
6439
  [temp.spec]: temp.md#temp.spec
6440
  [temp.spec.partial]: temp.md#temp.spec.partial
6441
+ [temp.spec.partial.match]: temp.md#temp.spec.partial.match
6442
  [temp.type]: temp.md#temp.type
6443
+ [term.implicit.lifetime.type]: #term.implicit.lifetime.type
6444
  [term.incomplete.type]: #term.incomplete.type
6445
  [term.odr.use]: #term.odr.use
6446
+ [term.replaceable.function]: dcl.md#term.replaceable.function
6447
  [term.unevaluated.operand]: expr.md#term.unevaluated.operand
6448
  [thread]: thread.md#thread
6449
  [thread.jthread.class]: thread.md#thread.jthread.class
6450
  [thread.thread.class]: thread.md#thread.thread.class
6451
+ [thread.thread.this]: thread.md#thread.thread.this
6452
  [thread.threads]: thread.md#thread.threads
6453
 
6454
  [^1]: Appearing inside the brace-enclosed *declaration-seq* in a
6455
  *linkage-specification* does not affect whether a declaration is a
6456
  definition.
 
6464
 
6465
  [^4]: Lookups in which function names are ignored include names
6466
  appearing in a *nested-name-specifier*, an
6467
  *elaborated-type-specifier*, or a *base-specifier*.
6468
 
6469
+ [^5]: The number of bits in a byte is reported by the macro `CHAR_BIT`
 
 
 
 
 
6470
  in the header `<climits>`.
6471
 
6472
+ [^6]: Under the “as-if” rule an implementation is allowed to store two
6473
  objects at the same machine address or not store an object at all if
6474
  the program cannot observe the difference [[intro.execution]].
6475
 
6476
+ [^7]: For example, before the dynamic initialization of an object with
6477
  static storage duration [[basic.start.dynamic]].
6478
 
6479
+ [^8]: That is, an object for which a destructor will be called
6480
  implicitly—upon exit from the block for an object with automatic
6481
  storage duration, upon exit from the thread for an object with
6482
  thread storage duration, or upon exit from the program for an object
6483
  with static storage duration.
6484
 
6485
+ [^9]: The intent is to have `operator new()` implementable by calling
 
 
 
6486
  `std::malloc()` or `std::calloc()`, so the rules are substantially
6487
  the same. C++ differs from C in requiring a zero request to return a
6488
  non-null pointer.
6489
 
6490
+ [^10]: The global `operator delete(void*, std::size_t)` precludes use of
6491
  an allocation function `void operator new(std::size_t, std::size_t)`
6492
  as a placement allocation function [[diff.cpp11.basic]].
6493
 
6494
+ [^11]: The same rules apply to initialization of an `initializer_list`
6495
  object [[dcl.init.list]] with its underlying temporary array.
6496
 
6497
+ [^12]: By using, for example, the library functions [[headers]]
6498
  `std::memcpy` or `std::memmove`.
6499
 
6500
+ [^13]: By using, for example, the library functions [[headers]]
6501
  `std::memcpy` or `std::memmove`.
6502
 
6503
+ [^14]: The intent is that the memory model of C++ is compatible with
6504
+ that of the C programming language.
6505
 
6506
+ [^15]: The size and layout of an instance of an incompletely-defined
6507
  object type is unknown.
6508
 
6509
+ [^16]: This is also known as two’s complement representation.
6510
 
6511
+ [^17]: Static class members are objects or functions, and pointers to
6512
  them are ordinary pointers to objects or functions.
6513
 
6514
+ [^18]: For an object that is not within its lifetime, this is the first
6515
  byte in memory that it will occupy or used to occupy.
6516
 
6517
+ [^19]: Some implementations might define that copying such a pointer
6518
+ value causes a system-generated runtime fault.
6519
+
6520
+ [^20]: The same representation and alignment requirements are meant to
6521
  imply interchangeability as arguments to functions, return values
6522
  from functions, and non-static data members of unions.
6523
 
6524
+ [^21]: As specified in  [[class.temporary]], after a full-expression is
6525
  evaluated, a sequence of zero or more invocations of destructor
6526
  functions for temporary objects takes place, usually in reverse
6527
  order of the construction of each temporary object.
6528
 
6529
+ [^22]: In other words, function executions do not interleave with each
6530
  other.
6531
 
6532
+ [^23]: An object with automatic or thread storage duration [[basic.stc]]
6533
  is associated with one specific thread, and can be accessed by a
6534
  different thread only indirectly through a pointer or reference
6535
  [[basic.compound]].
6536
 
6537
+ [^24]: A non-block variable with static storage duration having
6538
  initialization with side effects is initialized in this case, even
6539
  if it is not itself odr-used [[term.odr.use]], [[basic.stc.static]].