From Jason Turner

[dcl.dcl]

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

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp6vlduq3n/{from.md → to.md} +1410 -1500
tmp/tmp6vlduq3n/{from.md → to.md} RENAMED
@@ -11,25 +11,35 @@ declaration-seq:
11
  declaration-seq declaration
12
  ```
13
 
14
  ``` bnf
15
  declaration:
 
 
 
 
 
 
16
  block-declaration
17
  nodeclspec-function-declaration
18
  function-definition
19
  template-declaration
20
  deduction-guide
21
- explicit-instantiation
22
- explicit-specialization
23
- export-declaration
24
  linkage-specification
25
  namespace-definition
26
  empty-declaration
27
  attribute-declaration
28
  module-import-declaration
29
  ```
30
 
 
 
 
 
 
 
 
31
  ``` bnf
32
  block-declaration:
33
  simple-declaration
34
  asm-declaration
35
  namespace-alias-definition
@@ -81,10 +91,16 @@ attribute-declaration:
81
  [[temp.deduct.guide]]; *namespace-definition*s are described in 
82
  [[namespace.def]], *using-declaration*s are described in 
83
  [[namespace.udecl]] and *using-directive*s are described in 
84
  [[namespace.udir]]. — *end note*]
85
 
 
 
 
 
 
 
86
  A *simple-declaration* or *nodeclspec-function-declaration* of the form
87
 
88
  ``` bnf
89
  attribute-specifier-seqₒₚₜ decl-specifier-seqₒₚₜ init-declarator-listₒₚₜ ';'
90
  ```
@@ -95,116 +111,155 @@ are described in  [[dcl.spec]]. *declarator*s, the components of an
95
  *init-declarator-list*, are described in [[dcl.decl]]. The
96
  *attribute-specifier-seq* appertains to each of the entities declared by
97
  the *declarator*s of the *init-declarator-list*.
98
 
99
  [*Note 2*: In the declaration for an entity, attributes appertaining to
100
- that entity may appear at the start of the declaration and after the
101
  *declarator-id* for that declaration. — *end note*]
102
 
103
  [*Example 1*:
104
 
105
  ``` cpp
106
  [[noreturn]] void f [[noreturn]] (); // OK
107
  ```
108
 
109
  — *end example*]
110
 
111
- Except where otherwise specified, the meaning of an
112
- *attribute-declaration* is *implementation-defined*.
113
 
114
- A declaration occurs in a scope [[basic.scope]]; the scope rules are
115
- summarized in  [[basic.lookup]]. A declaration that declares a function
116
- or defines a class, namespace, template, or function also has one or
117
- more scopes nested within it. These nested scopes, in turn, can have
118
- declarations nested within them. Unless otherwise stated, utterances in
119
- [[dcl.dcl]] about components in, of, or contained by a declaration or
120
- subcomponent thereof refer only to those components of the declaration
121
- that are *not* nested within scopes nested within the declaration.
122
 
123
  In a *simple-declaration*, the optional *init-declarator-list* can be
124
- omitted only when declaring a class [[class]] or enumeration
125
  [[dcl.enum]], that is, when the *decl-specifier-seq* contains either a
126
  *class-specifier*, an *elaborated-type-specifier* with a *class-key*
127
  [[class.name]], or an *enum-specifier*. In these cases and whenever a
128
  *class-specifier* or *enum-specifier* is present in the
129
- *decl-specifier-seq*, the identifiers in these specifiers are among the
130
- names being declared by the declaration (as *class-name*s, *enum-name*s,
131
- or *enumerator*s, depending on the syntax). In such cases, the
132
- *decl-specifier-seq* shall introduce one or more names into the program,
133
- or shall redeclare a name introduced by a previous declaration.
134
 
135
  [*Example 2*:
136
 
137
  ``` cpp
138
  enum { }; // error
139
  typedef class { }; // error
140
  ```
141
 
142
  — *end example*]
143
 
144
- In a *static_assert-declaration*, the *constant-expression* shall be a
145
- contextually converted constant expression of type `bool`
146
- [[expr.const]]. If the value of the expression when so converted is
147
- `true`, the declaration has no effect. Otherwise, the program is
148
- ill-formed, and the resulting diagnostic message [[intro.compliance]]
149
- shall include the text of the *string-literal*, if one is supplied,
150
- except that characters not in the basic source character set
151
- [[lex.charset]] are not required to appear in the diagnostic message.
152
-
153
- [*Example 3*:
154
-
155
- ``` cpp
156
- static_assert(sizeof(int) == sizeof(void*), "wrong pointer size");
157
- ```
158
-
159
- — *end example*]
160
-
161
- An *empty-declaration* has no effect.
162
-
163
  A *simple-declaration* with an *identifier-list* is called a *structured
164
- binding declaration* [[dcl.struct.bind]]. If the *decl-specifier-seq*
165
- contains any *decl-specifier* other than `static`, `thread_local`,
166
- `auto` [[dcl.spec.auto]], or *cv-qualifier*s, the program is ill-formed.
 
 
 
 
 
 
 
 
 
 
 
167
  The *initializer* shall be of the form “`=` *assignment-expression*”, of
168
  the form “`{` *assignment-expression* `}`”, or of the form “`(`
169
  *assignment-expression* `)`”, where the *assignment-expression* is of
170
  array or non-union class type.
171
 
172
- Each *init-declarator* in the *init-declarator-list* contains exactly
173
- one *declarator-id*, which is the name declared by that
174
- *init-declarator* and hence one of the names declared by the
175
- declaration. The *defining-type-specifier*s [[dcl.type]] in the
176
- *decl-specifier-seq* and the recursive *declarator* structure of the
177
- *init-declarator* describe a type [[dcl.meaning]], which is then
178
- associated with the name being declared by the *init-declarator*.
179
-
180
  If the *decl-specifier-seq* contains the `typedef` specifier, the
181
- declaration is called a *typedef declaration* and the name of each
182
- *init-declarator* is declared to be a *typedef-name*, synonymous with
183
- its associated type [[dcl.typedef]]. If the *decl-specifier-seq*
184
- contains no `typedef` specifier, the declaration is called a *function
185
- declaration* if the type associated with the name is a function type
186
- [[dcl.fct]] and an *object declaration* otherwise.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
 
188
  Syntactic components beyond those found in the general form of
189
- declaration are added to a function declaration to make a
190
  *function-definition*. An object declaration, however, is also a
191
  definition unless it contains the `extern` specifier and has no
192
  initializer [[basic.def]]. An object definition causes storage of
193
  appropriate size and alignment to be reserved and any appropriate
194
  initialization [[dcl.init]] to be done.
195
 
196
  A *nodeclspec-function-declaration* shall declare a constructor,
197
  destructor, or conversion function.
198
 
199
- [*Note 3*: A *nodeclspec-function-declaration* can only be used in a
 
 
200
  *template-declaration* [[temp.pre]], *explicit-instantiation*
201
  [[temp.explicit]], or *explicit-specialization*
202
  [[temp.expl.spec]]. — *end note*]
203
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  ## Specifiers <a id="dcl.spec">[[dcl.spec]]</a>
205
 
 
 
206
  The specifiers that can be used in a declaration are
207
 
208
  ``` bnf
209
  decl-specifier:
210
  storage-class-specifier
@@ -296,15 +351,14 @@ At most one *storage-class-specifier* shall appear in a given
296
  `static` or `extern`. If `thread_local` appears in any declaration of a
297
  variable it shall be present in all declarations of that entity. If a
298
  *storage-class-specifier* appears in a *decl-specifier-seq*, there can
299
  be no `typedef` specifier in the same *decl-specifier-seq* and the
300
  *init-declarator-list* or *member-declarator-list* of the declaration
301
- shall not be empty (except for an anonymous union declared in a named
302
- namespace or in the global namespace, which shall be declared `static`
303
- [[class.union.anon]]). The *storage-class-specifier* applies to the name
304
- declared by each *init-declarator* in the list and not to any names
305
- declared by other specifiers.
306
 
307
  [*Note 1*: See [[temp.expl.spec]] and [[temp.explicit]] for
308
  restrictions in explicit specializations and explicit instantiations,
309
  respectively. — *end note*]
310
 
@@ -340,14 +394,15 @@ a name declared with an `extern` specifier, see  [[basic.link]].
340
 
341
  [*Note 3*: The `extern` keyword can also be used in
342
  *explicit-instantiation*s and *linkage-specification*s, but it is not a
343
  *storage-class-specifier* in such contexts. — *end note*]
344
 
345
- The linkages implied by successive declarations for a given entity shall
346
- agree. That is, within a given scope, each declaration declaring the
347
- same variable name or the same overloading of a function name shall
348
- imply the same linkage.
 
349
 
350
  [*Example 1*:
351
 
352
  ``` cpp
353
  static char* f(); // f() has internal linkage
@@ -418,15 +473,15 @@ class X {
418
  };
419
  ```
420
 
421
  — *end example*]
422
 
423
- [*Note 4*: The `mutable` specifier on a class data member nullifies a
424
  `const` specifier applied to the containing class object and permits
425
  modification of the mutable class member even though the rest of the
426
- object is const ([[basic.type.qualifier]],
427
- [[dcl.type.cv]]). — *end note*]
428
 
429
  ### Function specifiers <a id="dcl.fct.spec">[[dcl.fct.spec]]</a>
430
 
431
  A *function-specifier* can be used only in a function declaration.
432
 
@@ -441,11 +496,11 @@ explicit-specifier:
441
  explicit '(' constant-expression ')'
442
  explicit
443
  ```
444
 
445
  The `virtual` specifier shall be used only in the initial declaration of
446
- a non-static class member function; see  [[class.virtual]].
447
 
448
  An *explicit-specifier* shall be used only in the declaration of a
449
  constructor or conversion function within its class definition; see 
450
  [[class.conv.ctor]] and  [[class.conv.fct]].
451
 
@@ -456,10 +511,21 @@ shall be a contextually converted constant expression of type `bool`
456
  `explicit(true)`. If the constant expression evaluates to `true`, the
457
  function is explicit. Otherwise, the function is not explicit. A `(`
458
  token that follows `explicit` is parsed as part of the
459
  *explicit-specifier*.
460
 
 
 
 
 
 
 
 
 
 
 
 
461
  ### The `typedef` specifier <a id="dcl.typedef">[[dcl.typedef]]</a>
462
 
463
  Declarations containing the *decl-specifier* `typedef` declare
464
  identifiers that can be used later for naming fundamental
465
  [[basic.fundamental]] or compound [[basic.compound]] types. The
@@ -502,118 +568,43 @@ are all correct declarations; the type of `distance` is `int` and that
502
  of `metricp` is “pointer to `int`”.
503
 
504
  — *end example*]
505
 
506
  A *typedef-name* can also be introduced by an *alias-declaration*. The
507
- *identifier* following the `using` keyword becomes a *typedef-name* and
508
- the optional *attribute-specifier-seq* following the *identifier*
509
- appertains to that *typedef-name*. Such a *typedef-name* has the same
510
- semantics as if it were introduced by the `typedef` specifier. In
511
- particular, it does not define a new type.
512
 
513
  [*Example 2*:
514
 
515
  ``` cpp
516
  using handler_t = void (*)(int);
517
  extern handler_t ignore;
518
  extern void (*ignore)(int); // redeclare ignore
519
- using cell = pair<void*, cell*>; // error
 
520
  ```
521
 
522
  — *end example*]
523
 
524
  The *defining-type-specifier-seq* of the *defining-type-id* shall not
525
  define a class or enumeration if the *alias-declaration* is the
526
  *declaration* of a *template-declaration*.
527
 
528
- In a given non-class scope, a `typedef` specifier can be used to
529
- redeclare the name of any type declared in that scope to refer to the
530
- type to which it already refers.
531
-
532
- [*Example 3*:
533
-
534
- ``` cpp
535
- typedef struct s { ... } s;
536
- typedef int I;
537
- typedef int I;
538
- typedef I I;
539
- ```
540
-
541
- — *end example*]
542
-
543
- In a given class scope, a `typedef` specifier can be used to redeclare
544
- any *class-name* declared in that scope that is not also a
545
- *typedef-name* to refer to the type to which it already refers.
546
-
547
- [*Example 4*:
548
-
549
- ``` cpp
550
- struct S {
551
- typedef struct A { } A; // OK
552
- typedef struct B B; // OK
553
- typedef A A; // error
554
- };
555
- ```
556
-
557
- — *end example*]
558
-
559
- If a `typedef` specifier is used to redeclare in a given scope an entity
560
- that can be referenced using an *elaborated-type-specifier*, the entity
561
- can continue to be referenced by an *elaborated-type-specifier* or as an
562
- enumeration or class name in an enumeration or class definition
563
- respectively.
564
-
565
- [*Example 5*:
566
-
567
- ``` cpp
568
- struct S;
569
- typedef struct S S;
570
- int main() {
571
- struct S* p; // OK
572
- }
573
- struct S { }; // OK
574
- ```
575
-
576
- — *end example*]
577
-
578
- In a given scope, a `typedef` specifier shall not be used to redeclare
579
- the name of any type declared in that scope to refer to a different
580
- type.
581
-
582
- [*Example 6*:
583
-
584
- ``` cpp
585
- class complex { ... };
586
- typedef int complex; // error: redefinition
587
- ```
588
-
589
- — *end example*]
590
-
591
- Similarly, in a given scope, a class or enumeration shall not be
592
- declared with the same name as a *typedef-name* that is declared in that
593
- scope and refers to a type other than the class or enumeration itself.
594
-
595
- [*Example 7*:
596
-
597
- ``` cpp
598
- typedef int complex;
599
- class complex { ... }; // error: redefinition
600
- ```
601
-
602
- — *end example*]
603
-
604
  A *simple-template-id* is only a *typedef-name* if its *template-name*
605
  names an alias template or a template *template-parameter*.
606
 
607
  [*Note 1*: A *simple-template-id* that names a class template
608
  specialization is a *class-name* [[class.name]]. If a *typedef-name* is
609
  used to identify the subject of an *elaborated-type-specifier*
610
  [[dcl.type.elab]], a class definition [[class]], a constructor
611
  declaration [[class.ctor]], or a destructor declaration [[class.dtor]],
612
  the program is ill-formed. — *end note*]
613
 
614
- [*Example 8*:
615
 
616
  ``` cpp
617
  struct S {
618
  S();
619
  ~S();
@@ -625,23 +616,23 @@ S a = T(); // OK
625
  struct T * p; // error
626
  ```
627
 
628
  — *end example*]
629
 
630
- If the typedef declaration defines an unnamed class or enumeration, the
631
- first *typedef-name* declared by the declaration to be that type is used
632
- to denote the type for linkage purposes only [[basic.link]].
633
 
634
  [*Note 2*: A typedef declaration involving a *lambda-expression* does
635
  not itself define the associated closure type, and so the closure type
636
- is not given a name for linkage purposes. — *end note*]
637
 
638
- [*Example 9*:
639
 
640
  ``` cpp
641
- typedef struct { } *ps, S; // S is the class name for linkage purposes
642
- typedef decltype([]{}) C; // the closure type has no name for linkage purposes
643
  ```
644
 
645
  — *end example*]
646
 
647
  An unnamed class with a typedef name for linkage purposes shall not
@@ -652,11 +643,11 @@ An unnamed class with a typedef name for linkage purposes shall not
652
  - contain a *lambda-expression*,
653
 
654
  and all member classes shall also satisfy these requirements
655
  (recursively).
656
 
657
- [*Example 10*:
658
 
659
  ``` cpp
660
  typedef struct {
661
  int f() {}
662
  } X; // error: struct with typedef name for linkage has member functions
@@ -689,58 +680,52 @@ specifier. — *end note*]
689
  `constexpr`. — *end note*]
690
 
691
  [*Example 1*:
692
 
693
  ``` cpp
694
- constexpr void square(int &x); // OK: declaration
695
- constexpr int bufsz = 1024; // OK: definition
696
  constexpr struct pixel { // error: pixel is a type
697
  int x;
698
  int y;
699
- constexpr pixel(int); // OK: declaration
700
  };
701
  constexpr pixel::pixel(int a)
702
- : x(a), y(x) // OK: definition
703
  { square(x); }
704
  constexpr pixel small(2); // error: square not defined, so small(2)
705
  // not constant[expr.const] so constexpr not satisfied
706
 
707
- constexpr void square(int &x) { // OK: definition
708
  x *= x;
709
  }
710
- constexpr pixel large(4); // OK: square defined
711
  int next(constexpr int x) { // error: not for parameters
712
  return x + 1;
713
  }
714
  extern constexpr int memsz; // error: not a definition
715
  ```
716
 
717
  — *end example*]
718
 
719
  A `constexpr` or `consteval` specifier used in the declaration of a
720
- function declares that function to be a *constexpr function*. A function
721
- or constructor declared with the `consteval` specifier is called an
722
- *immediate function*. A destructor, an allocation function, or a
723
- deallocation function shall not be declared with the `consteval`
724
- specifier.
725
 
726
- The definition of a constexpr function shall satisfy the following
727
- requirements:
728
 
729
- - its return type (if any) shall be a literal type;
730
- - each of its parameter types shall be a literal type;
731
- - it shall not be a coroutine [[dcl.fct.def.coroutine]];
732
- - if the function is a constructor or destructor, its class shall not
733
- have any virtual base classes;
734
- - its *function-body* shall not enclose [[stmt.pre]]
735
- - a `goto` statement,
736
- - an identifier label [[stmt.label]],
737
- - a definition of a variable of non-literal type or of static or
738
- thread storage duration.
739
 
740
- \[*Note 3*: A *function-body* that is `= delete` or `= default`
741
- encloses none of the above. — *end note*]
 
 
 
 
 
 
742
 
743
  [*Example 2*:
744
 
745
  ``` cpp
746
  constexpr int square(int x)
@@ -750,14 +735,17 @@ constexpr long long_max()
750
  constexpr int abs(int x) {
751
  if (x < 0)
752
  x = -x;
753
  return x; // OK
754
  }
755
- constexpr int first(int n) {
756
- static int value = n; // error: variable has static storage duration
 
757
  return value;
758
  }
 
 
759
  constexpr int uninit() {
760
  struct { int a; } s;
761
  return s.a; // error: uninitialized read of s.a
762
  }
763
  constexpr int prev(int x)
@@ -769,77 +757,10 @@ constexpr int g(int x, int n) { // OK
769
  }
770
  ```
771
 
772
  — *end example*]
773
 
774
- The definition of a constexpr constructor whose *function-body* is not
775
- `= delete` shall additionally satisfy the following requirements:
776
-
777
- - for a non-delegating constructor, every constructor selected to
778
- initialize non-static data members and base class subobjects shall be
779
- a constexpr constructor;
780
- - for a delegating constructor, the target constructor shall be a
781
- constexpr constructor.
782
-
783
- [*Example 3*:
784
-
785
- ``` cpp
786
- struct Length {
787
- constexpr explicit Length(int i = 0) : val(i) { }
788
- private:
789
- int val;
790
- };
791
- ```
792
-
793
- — *end example*]
794
-
795
- The definition of a constexpr destructor whose *function-body* is not
796
- `= delete` shall additionally satisfy the following requirement:
797
-
798
- - for every subobject of class type or (possibly multi-dimensional)
799
- array thereof, that class type shall have a constexpr destructor.
800
-
801
- For a constexpr function or constexpr constructor that is neither
802
- defaulted nor a template, if no argument values exist such that an
803
- invocation of the function or constructor could be an evaluated
804
- subexpression of a core constant expression [[expr.const]], or, for a
805
- constructor, an evaluated subexpression of the initialization
806
- full-expression of some constant-initialized object
807
- [[basic.start.static]], the program is ill-formed, no diagnostic
808
- required.
809
-
810
- [*Example 4*:
811
-
812
- ``` cpp
813
- constexpr int f(bool b)
814
- { return b ? throw 0 : 0; } // OK
815
- constexpr int f() { return f(true); } // ill-formed, no diagnostic required
816
-
817
- struct B {
818
- constexpr B(int x) : i(0) { } // x is unused
819
- int i;
820
- };
821
-
822
- int global;
823
-
824
- struct D : B {
825
- constexpr D() : B(global) { } // ill-formed, no diagnostic required
826
- // lvalue-to-rvalue conversion on non-constant global
827
- };
828
- ```
829
-
830
- — *end example*]
831
-
832
- If the instantiated template specialization of a constexpr function
833
- template or member function of a class template would fail to satisfy
834
- the requirements for a constexpr function, that specialization is still
835
- a constexpr function, even though a call to such a function cannot
836
- appear in a constant expression. If no specialization of the template
837
- would satisfy the requirements for a constexpr function when considered
838
- as a non-template function, the template is ill-formed, no diagnostic
839
- required.
840
-
841
  An invocation of a constexpr function in a given context produces the
842
  same result as an invocation of an equivalent non-constexpr function in
843
  the same context in all respects except that
844
 
845
  - an invocation of a constexpr function can appear in a constant
@@ -850,14 +771,18 @@ the same context in all respects except that
850
  [*Note 4*: Declaring a function constexpr can change whether an
851
  expression is a constant expression. This can indirectly cause calls to
852
  `std::is_constant_evaluated` within an invocation of the function to
853
  produce a different value. — *end note*]
854
 
 
 
 
 
855
  The `constexpr` and `consteval` specifiers have no effect on the type of
856
  a constexpr function.
857
 
858
- [*Example 5*:
859
 
860
  ``` cpp
861
  constexpr int bar(int x, int y) // OK
862
  { return x + y + x*y; }
863
  // ...
@@ -869,13 +794,15 @@ int bar(int x, int y) // error: redefinition of bar
869
 
870
  A `constexpr` specifier used in an object declaration declares the
871
  object as const. Such an object shall have literal type and shall be
872
  initialized. In any `constexpr` variable declaration, the
873
  full-expression of the initialization shall be a constant expression
874
- [[expr.const]]. A `constexpr` variable shall have constant destruction.
 
 
875
 
876
- [*Example 6*:
877
 
878
  ``` cpp
879
  struct pixel {
880
  int x, y;
881
  };
@@ -892,15 +819,16 @@ variable with static or thread storage duration. If the specifier is
892
  applied to any declaration of a variable, it shall be applied to the
893
  initializing declaration. No diagnostic is required if no `constinit`
894
  declaration is reachable at the point of the initializing declaration.
895
 
896
  If a variable declared with the `constinit` specifier has dynamic
897
- initialization [[basic.start.dynamic]], the program is ill-formed.
 
 
898
 
899
  [*Note 1*: The `constinit` specifier ensures that the variable is
900
- initialized during static initialization
901
- [[basic.start.static]]. — *end note*]
902
 
903
  [*Example 1*:
904
 
905
  ``` cpp
906
  const char * g() { return "dynamic initialization"; }
@@ -914,11 +842,11 @@ constinit const char * d = f(false); // error
914
  ### The `inline` specifier <a id="dcl.inline">[[dcl.inline]]</a>
915
 
916
  The `inline` specifier shall be applied only to the declaration of a
917
  variable or function.
918
 
919
- A function declaration ([[dcl.fct]], [[class.mfct]], [[class.friend]])
920
  with an `inline` specifier declares an *inline function*. The inline
921
  specifier indicates to the implementation that inline substitution of
922
  the function body at the point of call is to be preferred to the usual
923
  function call mechanism. An implementation is not required to perform
924
  this inline substitution at the point of call; however, even if this
@@ -943,29 +871,30 @@ function or variable with external or module linkage is declared inline
943
  in one definition domain, an inline declaration of it shall be reachable
944
  from the end of every definition domain in which it is declared; no
945
  diagnostic is required.
946
 
947
  [*Note 2*: A call to an inline function or a use of an inline variable
948
- may be encountered before its definition becomes reachable in a
949
  translation unit. — *end note*]
950
 
951
  [*Note 3*: An inline function or variable with external or module
952
- linkage has the same address in all translation units. A `static` local
953
- variable in an inline function with external or module linkage always
954
- refers to the same object. A type defined within the body of an inline
955
- function with external or module linkage is the same type in every
956
- translation unit. — *end note*]
957
 
958
  If an inline function or variable that is attached to a named module is
959
  declared in a definition domain, it shall be defined in that domain.
960
 
961
  [*Note 4*: A constexpr function [[dcl.constexpr]] is implicitly inline.
962
  In the global module, a function defined within a class definition is
963
- implicitly inline ([[class.mfct]], [[class.friend]]). — *end note*]
964
 
965
  ### Type specifiers <a id="dcl.type">[[dcl.type]]</a>
966
 
 
 
967
  The type-specifiers are
968
 
969
  ``` bnf
970
  type-specifier:
971
  simple-type-specifier
@@ -1020,11 +949,11 @@ function, at least one *defining-type-specifier* that is not a
1020
  complete *decl-specifier-seq*.[^1]
1021
 
1022
  [*Note 1*: *enum-specifier*s, *class-specifier*s, and
1023
  *typename-specifier*s are discussed in [[dcl.enum]], [[class]], and
1024
  [[temp.res]], respectively. The remaining *type-specifier*s are
1025
- discussed in the rest of this subclause. — *end note*]
1026
 
1027
  #### The *cv-qualifier*s <a id="dcl.type.cv">[[dcl.type.cv]]</a>
1028
 
1029
  There are two *cv-qualifier*s, `const` and `volatile`. Each
1030
  *cv-qualifier* shall appear at most once in a *cv-qualifier-seq*. If a
@@ -1053,23 +982,24 @@ the object referenced is a non-const object and can be modified through
1053
  some other access path.
1054
 
1055
  [*Note 4*: Cv-qualifiers are supported by the type system so that they
1056
  cannot be subverted without casting [[expr.const.cast]]. — *end note*]
1057
 
1058
- Any attempt to modify ([[expr.ass]], [[expr.post.incr]],
1059
- [[expr.pre.incr]]) a const object [[basic.type.qualifier]] during its
1060
- lifetime [[basic.life]] results in undefined behavior.
 
1061
 
1062
  [*Example 1*:
1063
 
1064
  ``` cpp
1065
  const int ci = 3; // cv-qualified (initialized as required)
1066
  ci = 4; // error: attempt to modify const
1067
 
1068
  int i = 2; // not cv-qualified
1069
  const int* cip; // pointer to const int
1070
- cip = &i; // OK: cv-qualified access path to unqualified
1071
  *cip = 4; // error: attempt to modify through ptr to const
1072
 
1073
  int* ip;
1074
  ip = const_cast<int*>(cip); // cast needed to convert const int* to int*
1075
  *ip = 4; // defined: *ip points to i, a non-const object
@@ -1147,10 +1077,16 @@ type-name:
1147
  class-name
1148
  enum-name
1149
  typedef-name
1150
  ```
1151
 
 
 
 
 
 
 
1152
  A *placeholder-type-specifier* is a placeholder for a type to be deduced
1153
  [[dcl.spec.auto]]. A *type-specifier* of the form `typename`ₒₚₜ
1154
  *nested-name-specifier*ₒₚₜ *template-name* is a placeholder for a
1155
  deduced class type [[dcl.type.class.deduct]]. The
1156
  *nested-name-specifier*, if any, shall be non-dependent and the
@@ -1233,49 +1169,72 @@ contexts. — *end note*]
1233
  ``` bnf
1234
  elaborated-type-specifier:
1235
  class-key attribute-specifier-seqₒₚₜ nested-name-specifierₒₚₜ identifier
1236
  class-key simple-template-id
1237
  class-key nested-name-specifier templateₒₚₜ simple-template-id
1238
- elaborated-enum-specifier
1239
- ```
1240
-
1241
- ``` bnf
1242
- elaborated-enum-specifier:
1243
  enum nested-name-specifierₒₚₜ identifier
1244
  ```
1245
 
1246
- An *attribute-specifier-seq* shall not appear in an
1247
- *elaborated-type-specifier* unless the latter is the sole constituent of
1248
- a declaration. If an *elaborated-type-specifier* is the sole constituent
1249
- of a declaration, the declaration is ill-formed unless it is an explicit
 
 
1250
  specialization [[temp.expl.spec]], an explicit instantiation
1251
  [[temp.explicit]] or it has one of the following forms:
1252
 
1253
  ``` bnf
1254
  class-key attribute-specifier-seqₒₚₜ identifier ';'
1255
- friend class-key '::ₒₚₜ ' identifier ';'
1256
- friend class-key '::ₒₚₜ ' simple-template-id ';'
1257
- friend class-key nested-name-specifier identifier ';'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1258
  friend class-key nested-name-specifier templateₒₚₜ simple-template-id ';'
1259
  ```
1260
 
1261
- In the first case, the *attribute-specifier-seq*, if any, appertains to
1262
- the class being declared; the attributes in the
1263
- *attribute-specifier-seq* are thereafter considered attributes of the
1264
- class whenever it is named.
1265
 
1266
- [*Note 1*: [[basic.lookup.elab]] describes how name lookup proceeds
1267
- for the *identifier* in an *elaborated-type-specifier*. *end note*]
 
 
 
 
 
 
1268
 
1269
  If the *identifier* or *simple-template-id* resolves to a *class-name*
1270
  or *enum-name*, the *elaborated-type-specifier* introduces it into the
1271
  declaration the same way a *simple-type-specifier* introduces its
1272
  *type-name* [[dcl.type.simple]]. If the *identifier* or
1273
- *simple-template-id* resolves to a *typedef-name* ([[dcl.typedef]],
1274
- [[temp.names]]), the *elaborated-type-specifier* is ill-formed.
 
1275
 
1276
- [*Note 2*:
1277
 
1278
  This implies that, within a class template with a template
1279
  *type-parameter* `T`, the declaration
1280
 
1281
  ``` cpp
@@ -1323,23 +1282,23 @@ follows:
1323
  [[dcl.struct.bind]], `decltype(E)` is the referenced type as given in
1324
  the specification of the structured binding declaration;
1325
  - otherwise, if E is an unparenthesized *id-expression* naming a
1326
  non-type *template-parameter* [[temp.param]], `decltype(E)` is the
1327
  type of the *template-parameter* after performing any necessary type
1328
- deduction ([[dcl.spec.auto]], [[dcl.type.class.deduct]]);
1329
  - otherwise, if E is an unparenthesized *id-expression* or an
1330
  unparenthesized class member access [[expr.ref]], `decltype(E)` is the
1331
- type of the entity named by E. If there is no such entity, or if E
1332
- names a set of overloaded functions, the program is ill-formed;
1333
  - otherwise, if E is an xvalue, `decltype(E)` is `T&&`, where `T` is the
1334
  type of E;
1335
  - otherwise, if E is an lvalue, `decltype(E)` is `T&`, where `T` is the
1336
  type of E;
1337
  - otherwise, `decltype(E)` is the type of E.
1338
 
1339
  The operand of the `decltype` specifier is an unevaluated operand
1340
- [[expr.prop]].
1341
 
1342
  [*Example 1*:
1343
 
1344
  ``` cpp
1345
  const int&& foo();
@@ -1389,11 +1348,11 @@ template<class T> auto f(T) // #1
1389
  // for the temporary introduced by the use of h().
1390
  // (A temporary is not introduced as a result of the use of i().)
1391
  template<class T> auto f(T) // #2
1392
  -> void;
1393
  auto g() -> void {
1394
- f(42); // OK: calls #2. (#1 is not a viable candidate: type deduction
1395
  // fails[temp.deduct] because A<int>::~A() is implicitly used in its
1396
  // decltype-specifier)
1397
  }
1398
  template<class T> auto q(T)
1399
  -> decltype((h<T>())); // does not force completion of A<T>; A<T>::~A() is not implicitly
@@ -1408,10 +1367,12 @@ void r() {
1408
 
1409
  — *end example*]
1410
 
1411
  #### Placeholder type specifiers <a id="dcl.spec.auto">[[dcl.spec.auto]]</a>
1412
 
 
 
1413
  ``` bnf
1414
  placeholder-type-specifier:
1415
  type-constraintₒₚₜ auto
1416
  type-constraintₒₚₜ decltype '(' auto ')'
1417
  ```
@@ -1428,11 +1389,11 @@ placeholder* of the function declaration or *lambda-expression*.
1428
 
1429
  [*Note 1*: Having a generic parameter type placeholder signifies that
1430
  the function is an abbreviated function template [[dcl.fct]] or the
1431
  lambda is a generic lambda [[expr.prim.lambda]]. — *end note*]
1432
 
1433
- The placeholder type can appear with a function declarator in the
1434
  *decl-specifier-seq*, *type-specifier-seq*, *conversion-function-id*, or
1435
  *trailing-return-type*, in any context where such a declarator is valid.
1436
  If the function declarator includes a *trailing-return-type*
1437
  [[dcl.fct]], that *trailing-return-type* specifies the declared return
1438
  type of the function. Otherwise, the function declarator shall declare a
@@ -1444,54 +1405,49 @@ non-discarded `return` statements, if any, in the body of the function
1444
  The type of a variable declared using a placeholder type is deduced from
1445
  its initializer. This use is allowed in an initializing declaration
1446
  [[dcl.init]] of a variable. The placeholder type shall appear as one of
1447
  the *decl-specifier*s in the *decl-specifier-seq* and the
1448
  *decl-specifier-seq* shall be followed by one or more *declarator*s,
1449
- each of which shall be followed by a non-empty *initializer*. In an
1450
- *initializer* of the form
1451
-
1452
- ``` cpp
1453
- ( expression-list )
1454
- ```
1455
-
1456
- the *expression-list* shall be a single *assignment-expression*.
1457
 
1458
  [*Example 1*:
1459
 
1460
  ``` cpp
1461
- auto x = 5; // OK: x has type int
1462
- const auto *v = &x, u = 6; // OK: v has type const int*, u has type const int
1463
- static auto y = 0.0; // OK: y has type double
1464
  auto int r; // error: auto is not a storage-class-specifier
1465
- auto f() -> int; // OK: f returns int
1466
- auto g() { return 0.0; } // OK: g returns double
1467
- auto h(); // OK: h's return type will be deduced when it is defined
1468
  ```
1469
 
1470
  — *end example*]
1471
 
1472
  The `auto` *type-specifier* can also be used to introduce a structured
1473
  binding declaration [[dcl.struct.bind]].
1474
 
1475
  A placeholder type can also be used in the *type-specifier-seq* in the
1476
  *new-type-id* or *type-id* of a *new-expression* [[expr.new]] and as a
1477
  *decl-specifier* of the *parameter-declaration*'s *decl-specifier-seq*
1478
- in a *template-parameter* [[temp.param]].
 
 
1479
 
1480
  A program that uses a placeholder type in a context not explicitly
1481
- allowed in this subclause is ill-formed.
1482
 
1483
  If the *init-declarator-list* contains more than one *init-declarator*,
1484
  they shall all form declarations of variables. The type of each declared
1485
  variable is determined by placeholder type deduction
1486
  [[dcl.type.auto.deduct]], and if the type that replaces the placeholder
1487
  type is not the same in each deduction, the program is ill-formed.
1488
 
1489
  [*Example 2*:
1490
 
1491
  ``` cpp
1492
- auto x = 5, *y = &x; // OK: auto is int
1493
  auto a = 5, b = { 1, 2 }; // error: different types for auto
1494
  ```
1495
 
1496
  — *end example*]
1497
 
@@ -1519,15 +1475,15 @@ type shall be defined in the translation unit containing its exported
1519
  declaration, outside the *private-module-fragment* (if any).
1520
 
1521
  [*Note 2*: The deduced return type cannot have a name with internal
1522
  linkage [[basic.link]]. — *end note*]
1523
 
1524
- If the name of an entity with an undeduced placeholder type appears in
1525
- an expression, the program is ill-formed. Once a non-discarded `return`
1526
- statement has been seen in a function, however, the return type deduced
1527
- from that statement can be used in the rest of the function, including
1528
- in other `return` statements.
1529
 
1530
  [*Example 4*:
1531
 
1532
  ``` cpp
1533
  auto n = n; // error: n's initializer refers to n
@@ -1541,14 +1497,14 @@ auto sum(int i) {
1541
  }
1542
  ```
1543
 
1544
  — *end example*]
1545
 
1546
- Return type deduction for a templated entity that is a function or
1547
- function template with a placeholder in its declared type occurs when
1548
- the definition is instantiated even if the function body contains a
1549
- `return` statement with a non-type-dependent operand.
1550
 
1551
  [*Note 3*: Therefore, any use of a specialization of the function
1552
  template will cause an implicit instantiation. Any errors that arise
1553
  from this instantiation are not in the immediate context of the function
1554
  type and can result in the program being ill-formed
@@ -1564,24 +1520,22 @@ void g() { int (*p)(int*) = &f; } // instantiates both fs to deter
1564
  // chooses second
1565
  ```
1566
 
1567
  — *end example*]
1568
 
1569
- Redeclarations or specializations of a function or function template
1570
- with a declared return type that uses a placeholder type shall also use
1571
- that placeholder, not a deduced type. Similarly, redeclarations or
1572
- specializations of a function or function template with a declared
1573
- return type that does not use a placeholder type shall not use a
1574
- placeholder.
1575
 
1576
  [*Example 6*:
1577
 
1578
  ``` cpp
1579
  auto f();
1580
  auto f() { return 42; } // return type is int
1581
  auto f(); // OK
1582
- int f(); // error: cannot be overloaded with auto f()
1583
  decltype(auto) f(); // error: auto and decltype(auto) don't match
1584
 
1585
  template <typename T> auto g(T t) { return t; } // #1
1586
  template auto g(int); // OK, return type is int
1587
  template char g(char); // error: no matching template
@@ -1633,44 +1587,63 @@ int (*p)(int) = f; // instantiates f<int> to determine its return t
1633
 
1634
  *Placeholder type deduction* is the process by which a type containing a
1635
  placeholder type is replaced by a deduced type.
1636
 
1637
  A type `T` containing a placeholder type, and a corresponding
1638
- initializer E, are determined as follows:
1639
 
1640
- - for a non-discarded `return` statement that occurs in a function
1641
  declared with a return type that contains a placeholder type, `T` is
1642
- the declared return type and E is the operand of the `return`
1643
- statement. If the `return` statement has no operand, then E is
1644
- `void()`;
1645
- - for a variable declared with a type that contains a placeholder type,
1646
- `T` is the declared type of the variable and E is the initializer. If
1647
- the initialization is direct-list-initialization, the initializer
1648
- shall be a *braced-init-list* containing only a single
1649
- *assignment-expression* and E is the *assignment-expression*;
1650
- - for a non-type template parameter declared with a type that contains a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1651
  placeholder type, `T` is the declared type of the non-type template
1652
  parameter and E is the corresponding template argument.
1653
 
1654
- In the case of a `return` statement with no operand or with an operand
1655
- of type `void`, `T` shall be either *type-constraint*ₒₚₜ
1656
- `decltype(auto)` or cv *type-constraint*ₒₚₜ `auto`.
1657
-
1658
- If the deduction is for a `return` statement and E is a
1659
- *braced-init-list* [[dcl.init.list]], the program is ill-formed.
1660
 
1661
  If the *placeholder-type-specifier* is of the form *type-constraint*ₒₚₜ
1662
  `auto`, the deduced type T' replacing `T` is determined using the rules
1663
- for template argument deduction. Obtain `P` from `T` by replacing the
1664
- occurrences of *type-constraint*ₒₚₜ `auto` either with a new invented
1665
- type template parameter `U` or, if the initialization is
1666
- copy-list-initialization, with `std::initializer_list<U>`. Deduce a
1667
- value for `U` using the rules of template argument deduction from a
1668
- function call [[temp.deduct.call]], where `P` is a function template
1669
- parameter type and the corresponding argument is E. If the deduction
1670
- fails, the declaration is ill-formed. Otherwise, T' is obtained by
1671
- substituting the deduced `U` into `P`.
 
 
 
1672
 
1673
  [*Example 8*:
1674
 
1675
  ``` cpp
1676
  auto x1 = { 1, 2 }; // decltype(x1) is std::initializer_list<int>
@@ -1697,12 +1670,12 @@ template <class U> void f(const U& u);
1697
 
1698
  — *end example*]
1699
 
1700
  If the *placeholder-type-specifier* is of the form *type-constraint*ₒₚₜ
1701
  `decltype(auto)`, `T` shall be the placeholder alone. The type deduced
1702
- for `T` is determined as described in  [[dcl.type.simple]], as though E
1703
- had been the operand of the `decltype`.
1704
 
1705
  [*Example 10*:
1706
 
1707
  ``` cpp
1708
  int i;
@@ -1717,10 +1690,12 @@ auto x5a = f(); // decltype(x5a) is int
1717
  decltype(auto) x5d = f(); // decltype(x5d) is int&&
1718
  auto x6a = { 1, 2 }; // decltype(x6a) is std::initializer_list<int>
1719
  decltype(auto) x6d = { 1, 2 }; // error: { 1, 2 } is not an expression
1720
  auto *x7a = &i; // decltype(x7a) is int*
1721
  decltype(auto)*x7d = &i; // error: declared type is not plain decltype(auto)
 
 
1722
  ```
1723
 
1724
  — *end example*]
1725
 
1726
  For a *placeholder-type-specifier* with a *type-constraint*, the
@@ -1779,14 +1754,16 @@ container e{5, 6}; // error: int is not an iterator
1779
 
1780
  — *end example*]
1781
 
1782
  ## Declarators <a id="dcl.decl">[[dcl.decl]]</a>
1783
 
 
 
1784
  A declarator declares a single variable, function, or type, within a
1785
- declaration. The *init-declarator-list* appearing in a declaration is a
1786
- comma-separated sequence of declarators, each of which can have an
1787
- initializer.
1788
 
1789
  ``` bnf
1790
  init-declarator-list:
1791
  init-declarator
1792
  init-declarator-list ',' init-declarator
@@ -1796,28 +1773,31 @@ init-declarator-list:
1796
  init-declarator:
1797
  declarator initializerₒₚₜ
1798
  declarator requires-clause
1799
  ```
1800
 
1801
- The three components of a *simple-declaration* are the attributes
1802
- [[dcl.attr]], the specifiers (*decl-specifier-seq*; [[dcl.spec]]) and
1803
- the declarators (*init-declarator-list*). The specifiers indicate the
1804
- type, storage class or other properties of the entities being declared.
1805
- The declarators specify the names of these entities and (optionally)
1806
- modify the type of the specifiers with operators such as `*` (pointer
1807
- to) and `()` (function returning). Initial values can also be specified
1808
- in a declarator; initializers are discussed in  [[dcl.init]] and 
1809
- [[class.init]].
1810
 
1811
- Each *init-declarator* in a declaration is analyzed separately as if it
1812
- was in a declaration by itself.
1813
 
1814
- [*Note 1*:
 
 
 
1815
 
1816
  A declaration with several declarators is usually equivalent to the
1817
  corresponding sequence of declarations each with a single declarator.
1818
- That is
1819
 
1820
  ``` cpp
1821
  T D1, D2, ... Dn;
1822
  ```
1823
 
@@ -1826,14 +1806,14 @@ is usually equivalent to
1826
  ``` cpp
1827
  T D1; T D2; ... T Dn;
1828
  ```
1829
 
1830
  where `T` is a *decl-specifier-seq* and each `Di` is an
1831
- *init-declarator*. One exception is when a name introduced by one of the
1832
- *declarator*s hides a type name used by the *decl-specifier*s, so that
1833
- when the same *decl-specifier*s are used in a subsequent declaration,
1834
- they do not have the same meaning, as in
1835
 
1836
  ``` cpp
1837
  struct S { ... };
1838
  S S, T; // declare two instances of struct S
1839
  ```
@@ -1853,19 +1833,19 @@ auto i = 1, j = 2.0; // error: deduced types for i and j do not match
1853
  ```
1854
 
1855
  as opposed to
1856
 
1857
  ``` cpp
1858
- auto i = 1; // OK: i deduced to have type int
1859
- auto j = 2.0; // OK: j deduced to have type double
1860
  ```
1861
 
1862
  — *end note*]
1863
 
1864
- The optional *requires-clause* [[temp.pre]] in an *init-declarator* or
1865
  *member-declarator* shall be present only if the declarator declares a
1866
- templated function [[dcl.fct]]. When present after a declarator, the
1867
  *requires-clause* is called the *trailing *requires-clause**. The
1868
  trailing *requires-clause* introduces the *constraint-expression* that
1869
  results from interpreting its *constraint-logical-or-expression* as a
1870
  *constraint-expression*.
1871
 
@@ -2027,16 +2007,17 @@ A type can also be named (often more easily) by using a `typedef`
2027
 
2028
  ### Ambiguity resolution <a id="dcl.ambig.res">[[dcl.ambig.res]]</a>
2029
 
2030
  The ambiguity arising from the similarity between a function-style cast
2031
  and a declaration mentioned in  [[stmt.ambig]] can also occur in the
2032
- context of a declaration. In that context, the choice is between a
2033
- function declaration with a redundant set of parentheses around a
2034
- parameter name and an object declaration with a function-style cast as
2035
- the initializer. Just as for the ambiguities mentioned in 
2036
- [[stmt.ambig]], the resolution is to consider any construct that could
2037
- possibly be a declaration a declaration.
 
2038
 
2039
  [*Note 1*: A declaration can be explicitly disambiguated by adding
2040
  parentheses around the argument. The ambiguity can be avoided by use of
2041
  copy-initialization or list-initialization syntax, or by use of a
2042
  non-function-style cast. — *end note*]
@@ -2119,41 +2100,137 @@ void h(int *(C[10])); // void h(int *(*_fp)(C _parm[10]));
2119
 
2120
  — *end example*]
2121
 
2122
  ### Meaning of declarators <a id="dcl.meaning">[[dcl.meaning]]</a>
2123
 
2124
- A declarator contains exactly one *declarator-id*; it names the
2125
- identifier that is declared. An *unqualified-id* occurring in a
2126
- *declarator-id* shall be a simple *identifier* except for the
2127
- declaration of some special functions ([[class.ctor]], [[class.conv]],
2128
- [[class.dtor]], [[over.oper]]) and for the declaration of template
2129
- specializations or partial specializations [[temp.spec]]. When the
2130
- *declarator-id* is qualified, the declaration shall refer to a
2131
- previously declared member of the class or namespace to which the
2132
- qualifier refers (or, in the case of a namespace, of an element of the
2133
- inline namespace set of that namespace [[namespace.def]]) or to a
2134
- specialization thereof; the member shall not merely have been introduced
2135
- by a *using-declaration* in the scope of the class or namespace
2136
- nominated by the *nested-name-specifier* of the *declarator-id*. The
2137
- *nested-name-specifier* of a qualified *declarator-id* shall not begin
2138
- with a *decltype-specifier*.
2139
 
2140
- [*Note 1*: If the qualifier is the global `::` scope resolution
2141
- operator, the *declarator-id* refers to a name declared in the global
2142
- namespace scope. *end note*]
 
 
 
 
 
 
2143
 
2144
  The optional *attribute-specifier-seq* following a *declarator-id*
2145
  appertains to the entity that is declared.
2146
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2147
  A `static`, `thread_local`, `extern`, `mutable`, `friend`, `inline`,
2148
- `virtual`, `constexpr`, or `typedef` specifier or an
2149
- *explicit-specifier* applies directly to each *declarator-id* in an
2150
- *init-declarator-list* or *member-declarator-list*; the type specified
2151
- for each *declarator-id* depends on both the *decl-specifier-seq* and
2152
- its *declarator*.
2153
 
2154
- Thus, a declaration of a particular identifier has the form
2155
 
2156
  ``` cpp
2157
  T D
2158
  ```
2159
 
@@ -2168,11 +2245,11 @@ First, the *decl-specifier-seq* determines a type. In a declaration
2168
  T D
2169
  ```
2170
 
2171
  the *decl-specifier-seq* `T` determines the type `T`.
2172
 
2173
- [*Example 1*:
2174
 
2175
  In the declaration
2176
 
2177
  ``` cpp
2178
  int unsigned i;
@@ -2182,11 +2259,11 @@ the type specifiers `int` `unsigned` determine the type “`unsigned int`”
2182
  [[dcl.type.simple]].
2183
 
2184
  — *end example*]
2185
 
2186
  In a declaration *attribute-specifier-seq*ₒₚₜ `T` `D` where `D` is an
2187
- unadorned identifier the type of this identifier is “`T`”.
2188
 
2189
  In a declaration `T` `D` where `D` has the form
2190
 
2191
  ``` bnf
2192
  '(' 'D1' ')'
@@ -2208,17 +2285,17 @@ In a declaration `T` `D` where `D` has the form
2208
 
2209
  ``` bnf
2210
  '*' attribute-specifier-seqₒₚₜ cv-qualifier-seqₒₚₜ 'D1'
2211
  ```
2212
 
2213
- and the type of the identifier in the declaration `T` `D1` is
2214
- “*derived-declarator-type-list* `T`”, then the type of the identifier of
2215
- `D` is “*derived-declarator-type-list* *cv-qualifier-seq* pointer to
2216
- `T`”. The *cv-qualifier*s apply to the pointer and not to the object
2217
- pointed to. Similarly, the optional *attribute-specifier-seq*
2218
- [[dcl.attr.grammar]] appertains to the pointer and not to the object
2219
- pointed to.
2220
 
2221
  [*Example 1*:
2222
 
2223
  The declarations
2224
 
@@ -2282,18 +2359,18 @@ In a declaration `T` `D` where `D` has either of the forms
2282
  ``` bnf
2283
  '&' attribute-specifier-seqₒₚₜ 'D1'
2284
  '&&' attribute-specifier-seqₒₚₜ 'D1'
2285
  ```
2286
 
2287
- and the type of the identifier in the declaration `T` `D1` is
2288
- “*derived-declarator-type-list* `T`”, then the type of the identifier of
2289
- `D` is “*derived-declarator-type-list* reference to `T`”. The optional
2290
- *attribute-specifier-seq* appertains to the reference type. Cv-qualified
2291
- references are ill-formed except when the cv-qualifiers are introduced
2292
- through the use of a *typedef-name* ([[dcl.typedef]], [[temp.param]])
2293
- or *decltype-specifier* [[dcl.type.simple]], in which case the
2294
- cv-qualifiers are ignored.
2295
 
2296
  [*Example 1*:
2297
 
2298
  ``` cpp
2299
  typedef int& A;
@@ -2382,12 +2459,12 @@ well-defined program, because the only way to create such a reference
2382
  would be to bind it to the “object” obtained by indirection through a
2383
  null pointer, which causes undefined behavior. As described in 
2384
  [[class.bit]], a reference cannot be bound directly to a
2385
  bit-field. — *end note*]
2386
 
2387
- If a *typedef-name* ([[dcl.typedef]], [[temp.param]]) or a
2388
- *decltype-specifier* [[dcl.type.simple]] denotes a type `TR` that is a
2389
  reference to a type `T`, an attempt to create the type “lvalue reference
2390
  to cv `TR`” creates the type “lvalue reference to `T`”, while an attempt
2391
  to create the type “rvalue reference to cv `TR`” creates the type `TR`.
2392
 
2393
  [*Note 3*: This rule is known as reference collapsing. — *end note*]
@@ -2416,19 +2493,22 @@ decltype(r2)&& r7 = i; // r7 has the type int&
2416
  function type has *cv-qualifier*s or a *ref-qualifier*; see 
2417
  [[dcl.fct]]. — *end note*]
2418
 
2419
  #### Pointers to members <a id="dcl.mptr">[[dcl.mptr]]</a>
2420
 
 
 
 
2421
  In a declaration `T` `D` where `D` has the form
2422
 
2423
  ``` bnf
2424
  nested-name-specifier '*' attribute-specifier-seqₒₚₜ cv-qualifier-seqₒₚₜ 'D1'
2425
  ```
2426
 
2427
  and the *nested-name-specifier* denotes a class, and the type of the
2428
- identifier in the declaration `T` `D1` is
2429
- “*derived-declarator-type-list* `T`”, then the type of the identifier of
2430
  `D` is “*derived-declarator-type-list* *cv-qualifier-seq* pointer to
2431
  member of class *nested-name-specifier* of type `T`”. The optional
2432
  *attribute-specifier-seq* [[dcl.attr.grammar]] appertains to the
2433
  pointer-to-member.
2434
 
@@ -2503,12 +2583,12 @@ unknown bound of `T`”, except as specified below.
2503
  A type of the form “array of `N` `U`” or “array of unknown bound of `U`”
2504
  is an *array type*. The optional *attribute-specifier-seq* appertains to
2505
  the array type.
2506
 
2507
  `U` is called the array *element type*; this type shall not be a
2508
- placeholder type [[dcl.spec.auto]], a reference type, a function type,
2509
- an array of unknown bound, or cv `void`.
2510
 
2511
  [*Note 1*: An array can be constructed from one of the fundamental
2512
  types (except `void`), from a pointer, from a pointer to member, from a
2513
  class, from an enumeration type, or from an array of known
2514
  bound. — *end note*]
@@ -2539,39 +2619,39 @@ typedef const AA CAA; // type is ``array of 2 array of 3 const int''
2539
  — *end example*]
2540
 
2541
  [*Note 2*: An “array of `N` *cv-qualifier-seq* `U`” has cv-qualified
2542
  type; see  [[basic.type.qualifier]]. — *end note*]
2543
 
2544
- An object of type “array of `N` `U`” contains a contiguously allocated
2545
- non-empty set of `N` subobjects of type `U`, known as the *elements* of
2546
- the array, and numbered `0` to `N-1`.
2547
 
2548
  In addition to declarations in which an incomplete object type is
2549
  allowed, an array bound may be omitted in some cases in the declaration
2550
  of a function parameter [[dcl.fct]]. An array bound may also be omitted
2551
  when an object (but not a non-static data member) of array type is
2552
- initialized and the declarator is followed by an initializer (
2553
- [[dcl.init]], [[class.mem]], [[expr.type.conv]], [[expr.new]]). In these
2554
  cases, the array bound is calculated from the number of initial elements
2555
  (say, `N`) supplied [[dcl.init.aggr]], and the type of the array is
2556
  “array of `N` `U`”.
2557
 
2558
- Furthermore, if there is a preceding declaration of the entity in the
2559
- same scope in which the bound was specified, an omitted array bound is
2560
- taken to be the same as in that earlier declaration, and similarly for
2561
- the definition of a static data member of a class.
2562
 
2563
  [*Example 3*:
2564
 
2565
  ``` cpp
2566
  extern int x[10];
2567
  struct S {
2568
  static int y[10];
2569
  };
2570
 
2571
- int x[]; // OK: bound is 10
2572
- int S::y[]; // OK: bound is 10
2573
 
2574
  void f() {
2575
  extern int x[];
2576
  int i = sizeof(x); // error: incomplete object type
2577
  }
@@ -2581,11 +2661,11 @@ void f() {
2581
 
2582
  [*Note 3*:
2583
 
2584
  When several “array of” specifications are adjacent, a multidimensional
2585
  array type is created; only the first of the constant expressions that
2586
- specify the bounds of the arrays may be omitted.
2587
 
2588
  [*Example 4*:
2589
 
2590
  ``` cpp
2591
  int x3d[3][5][7];
@@ -2683,13 +2763,13 @@ parameter-declaration-list:
2683
  parameter-declaration-list ',' parameter-declaration
2684
  ```
2685
 
2686
  ``` bnf
2687
  parameter-declaration:
2688
- attribute-specifier-seqₒₚₜ decl-specifier-seq declarator
2689
  attribute-specifier-seqₒₚₜ decl-specifier-seq declarator '=' initializer-clause
2690
- attribute-specifier-seqₒₚₜ decl-specifier-seq abstract-declaratorₒₚₜ
2691
  attribute-specifier-seqₒₚₜ decl-specifier-seq abstract-declaratorₒₚₜ '=' initializer-clause
2692
  ```
2693
 
2694
  The optional *attribute-specifier-seq* in a *parameter-declaration*
2695
  appertains to the parameter.
@@ -2738,12 +2818,12 @@ However, the first argument must be of a type that can be converted to a
2738
  accessing arguments passed using the ellipsis (see  [[expr.call]] and 
2739
  [[support.runtime]]). — *end note*]
2740
 
2741
  The type of a function is determined using the following rules. The type
2742
  of each parameter (including function parameter packs) is determined
2743
- from its own *decl-specifier-seq* and *declarator*. After determining
2744
- the type of each parameter, any parameter of type “array of `T`” or of
2745
  function type `T` is adjusted to be “pointer to `T`”. After producing
2746
  the list of parameter types, any top-level *cv-qualifier*s modifying a
2747
  parameter type are deleted when forming the function type. The resulting
2748
  list of transformed parameter types and the presence or absence of the
2749
  ellipsis or a function parameter pack is the function’s
@@ -2751,24 +2831,94 @@ ellipsis or a function parameter pack is the function’s
2751
 
2752
  [*Note 3*: This transformation does not affect the types of the
2753
  parameters. For example, `int(*)(const int p, decltype(p)*)` and
2754
  `int(*)(int, const int*)` are identical types. — *end note*]
2755
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2756
  A function type with a *cv-qualifier-seq* or a *ref-qualifier*
2757
- (including a type named by *typedef-name* ([[dcl.typedef]],
2758
- [[temp.param]])) shall appear only as:
2759
 
2760
  - the function type for a non-static member function,
2761
  - the function type to which a pointer to member refers,
2762
  - the top-level function type of a function typedef declaration or
2763
  *alias-declaration*,
2764
  - the *type-id* in the default argument of a *type-parameter*
2765
  [[temp.param]], or
2766
  - the *type-id* of a *template-argument* for a *type-parameter*
2767
  [[temp.arg.type]].
2768
 
2769
- [*Example 2*:
2770
 
2771
  ``` cpp
2772
  typedef int FIC(int) const;
2773
  FIC f; // error: does not declare a member function
2774
  struct S {
@@ -2781,35 +2931,35 @@ FIC S::*pm = &S::f; // OK
2781
 
2782
  The effect of a *cv-qualifier-seq* in a function declarator is not the
2783
  same as adding cv-qualification on top of the function type. In the
2784
  latter case, the cv-qualifiers are ignored.
2785
 
2786
- [*Note 4*: A function type that has a *cv-qualifier-seq* is not a
2787
  cv-qualified type; there are no cv-qualified function
2788
  types. — *end note*]
2789
 
2790
- [*Example 3*:
2791
 
2792
  ``` cpp
2793
  typedef void F();
2794
  struct S {
2795
- const F f; // OK: equivalent to: void f();
2796
  };
2797
  ```
2798
 
2799
  — *end example*]
2800
 
2801
  The return type, the parameter-type-list, the *ref-qualifier*, the
2802
  *cv-qualifier-seq*, and the exception specification, but not the default
2803
  arguments [[dcl.fct.default]] or the trailing *requires-clause*
2804
  [[dcl.decl]], are part of the function type.
2805
 
2806
- [*Note 5*: Function types are checked during the assignments and
2807
  initializations of pointers to functions, references to functions, and
2808
  pointers to member functions. — *end note*]
2809
 
2810
- [*Example 4*:
2811
 
2812
  The declaration
2813
 
2814
  ``` cpp
2815
  int fseek(FILE*, long, int);
@@ -2818,50 +2968,46 @@ int fseek(FILE*, long, int);
2818
  declares a function taking three arguments of the specified types, and
2819
  returning `int` [[dcl.type]].
2820
 
2821
  — *end example*]
2822
 
2823
- A single name can be used for several different functions in a single
2824
- scope; this is function overloading [[over]]. All declarations for a
2825
- function shall have equivalent return types, parameter-type-lists, and
2826
- *requires-clause*s [[temp.over.link]].
2827
 
2828
- Functions shall not have a return type of type array or function,
2829
- although they may have a return type of type pointer or reference to
2830
- such things. There shall be no arrays of functions, although there can
2831
- be arrays of pointers to functions.
 
2832
 
2833
  A volatile-qualified return type is deprecated; see 
2834
  [[depr.volatile.type]].
2835
 
2836
  Types shall not be defined in return or parameter types.
2837
 
2838
  A typedef of function type may be used to declare a function but shall
2839
  not be used to define a function [[dcl.fct.def]].
2840
 
2841
- [*Example 5*:
2842
 
2843
  ``` cpp
2844
  typedef void F();
2845
- F fv; // OK: equivalent to void fv();
2846
  F fv { } // error
2847
- void fv() { } // OK: definition of fv
2848
  ```
2849
 
2850
  — *end example*]
2851
 
2852
  An identifier can optionally be provided as a parameter name; if present
2853
  in a function definition [[dcl.fct.def]], it names a parameter.
2854
 
2855
- [*Note 6*: In particular, parameter names are also optional in function
2856
  definitions and names used for a parameter in different declarations and
2857
- the definition of a function need not be the same. If a parameter name
2858
- is present in a function declaration that is not a definition, it cannot
2859
- be used outside of its function declarator because that is the extent of
2860
- its potential scope [[basic.scope.param]]. — *end note*]
2861
 
2862
- [*Example 6*:
2863
 
2864
  The declaration
2865
 
2866
  ``` cpp
2867
  int i,
@@ -2887,15 +3033,15 @@ calling of a function `fpi`, and then using indirection through the
2887
  to indicate that indirection through a pointer to a function yields a
2888
  function, which is then called.
2889
 
2890
  — *end example*]
2891
 
2892
- [*Note 7*:
2893
 
2894
  Typedefs and *trailing-return-type*s are sometimes convenient when the
2895
  return type of a function is complex. For example, the function `fpif`
2896
- above could have been declared
2897
 
2898
  ``` cpp
2899
  typedef int IFUNC(int);
2900
  IFUNC* fpif(int);
2901
  ```
@@ -2922,11 +3068,11 @@ template <class T, class U> decltype((*(T*)0) + (*(U*)0)) add(T t, U u);
2922
  — *end note*]
2923
 
2924
  A *non-template function* is a function that is not a function template
2925
  specialization.
2926
 
2927
- [*Note 8*: A function template is not a function. — *end note*]
2928
 
2929
  An *abbreviated function template* is a function declaration that has
2930
  one or more generic parameter type placeholders [[dcl.spec.auto]]. An
2931
  abbreviated function template is equivalent to a function template
2932
  [[temp.fct]] whose *template-parameter-list* includes one invented type
@@ -2935,18 +3081,18 @@ function declaration, in order of appearance. For a
2935
  *placeholder-type-specifier* of the form `auto`, the invented parameter
2936
  is an unconstrained *type-parameter*. For a *placeholder-type-specifier*
2937
  of the form *type-constraint* `auto`, the invented parameter is a
2938
  *type-parameter* with that *type-constraint*. The invented type
2939
  *template-parameter* is a template parameter pack if the corresponding
2940
- *parameter-declaration* declares a function parameter pack [[dcl.fct]].
2941
- If the placeholder contains `decltype(auto)`, the program is ill-formed.
2942
- The adjusted function parameters of an abbreviated function template are
2943
  derived from the *parameter-declaration-clause* by replacing each
2944
  occurrence of a placeholder with the name of the corresponding invented
2945
  *template-parameter*.
2946
 
2947
- [*Example 7*:
2948
 
2949
  ``` cpp
2950
  template<typename T> concept C1 = /* ... */;
2951
  template<typename T> concept C2 = /* ... */;
2952
  template<typename... Ts> concept C3 = /* ... */;
@@ -2955,12 +3101,12 @@ void g1(const C1 auto*, C2 auto&);
2955
  void g2(C1 auto&...);
2956
  void g3(C3 auto...);
2957
  void g4(C3 auto);
2958
  ```
2959
 
2960
- These declarations are functionally equivalent (but not equivalent) to
2961
- the following declarations.
2962
 
2963
  ``` cpp
2964
  template<C1 T, C2 U> void g1(const T*, U&);
2965
  template<C1... Ts> void g2(Ts&...);
2966
  template<C3... Ts> void g3(Ts...);
@@ -2975,15 +3121,15 @@ template<> void g1<int>(const int*, const double&); // OK, specialization of g1<
2975
  ```
2976
 
2977
  — *end example*]
2978
 
2979
  An abbreviated function template can have a *template-head*. The
2980
- invented *template-parameters* are appended to the
2981
  *template-parameter-list* after the explicitly declared
2982
- *template-parameters*.
2983
 
2984
- [*Example 8*:
2985
 
2986
  ``` cpp
2987
  template<typename> concept C = /* ... */;
2988
 
2989
  template <typename T, C U>
@@ -3013,11 +3159,11 @@ only be used in a *parameter-declaration*. When it is part of a
3013
  function parameter pack [[temp.variadic]]. Otherwise, the
3014
  *parameter-declaration* is part of a *template-parameter-list* and
3015
  declares a template parameter pack; see  [[temp.param]]. A function
3016
  parameter pack is a pack expansion [[temp.variadic]].
3017
 
3018
- [*Example 9*:
3019
 
3020
  ``` cpp
3021
  template<typename... T> void f(T (* ...t)(int, int));
3022
 
3023
  int add(int, int);
@@ -3073,18 +3219,18 @@ latter case, the *initializer-clause* shall be an
3073
  template parameter pack or a function parameter pack. If it is specified
3074
  in a *parameter-declaration-clause*, it shall not occur within a
3075
  *declarator* or *abstract-declarator* of a *parameter-declaration*.[^4]
3076
 
3077
  For non-template functions, default arguments can be added in later
3078
- declarations of a function in the same scope. Declarations in different
3079
- scopes have completely distinct sets of default arguments. That is,
3080
- declarations in inner scopes do not acquire default arguments from
3081
- declarations in outer scopes, and vice versa. In a given function
3082
- declaration, each parameter subsequent to a parameter with a default
3083
- argument shall have a default argument supplied in this or a previous
3084
- declaration, unless the parameter was expanded from a parameter pack, or
3085
- shall be a function parameter pack.
3086
 
3087
  [*Note 2*: A default argument cannot be redefined by a later
3088
  declaration (not even to the same value)
3089
  [[basic.def.odr]]. — *end note*]
3090
 
@@ -3118,22 +3264,26 @@ C<int> c; // OK, instantiates declaration void C::f(int n
3118
  — *end example*]
3119
 
3120
  For a given inline function defined in different translation units, the
3121
  accumulated sets of default arguments at the end of the translation
3122
  units shall be the same; no diagnostic is required. If a friend
3123
- declaration specifies a default argument expression, that declaration
3124
- shall be a definition and shall be the only declaration of the function
3125
- or function template in the translation unit.
 
3126
 
3127
  The default argument has the same semantic constraints as the
3128
  initializer in a declaration of a variable of the parameter type, using
3129
  the copy-initialization semantics [[dcl.init]]. The names in the default
3130
- argument are bound, and the semantic constraints are checked, at the
3131
- point where the default argument appears. Name lookup and checking of
3132
- semantic constraints for default arguments in function templates and in
3133
- member functions of class templates are performed as described in 
3134
- [[temp.inst]].
 
 
 
3135
 
3136
  [*Example 3*:
3137
 
3138
  In the following code, `g` will be called with the value `f(2)`:
3139
 
@@ -3151,14 +3301,13 @@ void h() {
3151
  }
3152
  ```
3153
 
3154
  — *end example*]
3155
 
3156
- [*Note 3*: In member function declarations, names in default arguments
3157
- are looked up as described in  [[basic.lookup.unqual]]. Access checking
3158
- applies to names in default arguments as described in
3159
- [[class.access]]. — *end note*]
3160
 
3161
  Except for member functions of class templates, the default arguments in
3162
  a member function definition that appears outside of the class
3163
  definition are added to the set of default arguments provided by the
3164
  member function declaration in the class definition; the program is
@@ -3175,16 +3324,16 @@ class C {
3175
  void f(int i = 3);
3176
  void g(int i, int j = 99);
3177
  };
3178
 
3179
  void C::f(int i = 3) {} // error: default argument already specified in class scope
3180
- void C::g(int i = 88, int j) {} // in this translation unit, C::g can be called with no argument
3181
  ```
3182
 
3183
  — *end example*]
3184
 
3185
- [*Note 4*: A local variable cannot be odr-used [[basic.def.odr]] in a
3186
  default argument. — *end note*]
3187
 
3188
  [*Example 5*:
3189
 
3190
  ``` cpp
@@ -3198,11 +3347,11 @@ void f() {
3198
 
3199
  — *end example*]
3200
 
3201
  [*Note 5*:
3202
 
3203
- The keyword `this` may not appear in a default argument of a member
3204
  function; see  [[expr.prim.this]].
3205
 
3206
  [*Example 6*:
3207
 
3208
  ``` cpp
@@ -3215,22 +3364,24 @@ class A {
3215
 
3216
  — *end note*]
3217
 
3218
  A default argument is evaluated each time the function is called with no
3219
  argument for the corresponding parameter. A parameter shall not appear
3220
- as a potentially-evaluated expression in a default argument. Parameters
3221
- of a function declared before a default argument are in scope and can
3222
- hide namespace and class member names.
 
 
3223
 
3224
  [*Example 7*:
3225
 
3226
  ``` cpp
3227
  int a;
3228
  int f(int a, int b = a); // error: parameter a used as default argument
3229
  typedef int I;
3230
  int g(float I, int b = I(2)); // error: parameter I found
3231
- int h(int a, int b = sizeof(a)); // OK, unevaluated operand
3232
  ```
3233
 
3234
  — *end example*]
3235
 
3236
  A non-static member shall not appear in a default argument unless it
@@ -3276,16 +3427,17 @@ int (*p1)(int) = &f;
3276
  int (*p2)() = &f; // error: type mismatch
3277
  ```
3278
 
3279
  — *end example*]
3280
 
3281
- When a declaration of a function is introduced by way of a
3282
- *using-declaration* [[namespace.udecl]], any default argument
3283
- information associated with the declaration is made known as well. If
3284
- the function is redeclared thereafter in the namespace with additional
3285
- default arguments, the additional arguments are also known at any point
3286
- following the redeclaration where the *using-declaration* is in scope.
 
3287
 
3288
  A virtual function call [[class.virtual]] uses the default arguments in
3289
  the declaration of the virtual function determined by the static type of
3290
  the pointer or reference denoting the object. An overriding function in
3291
  a derived class does not acquire default arguments from the function it
@@ -3310,11 +3462,13 @@ void m() {
3310
 
3311
  — *end example*]
3312
 
3313
  ## Initializers <a id="dcl.init">[[dcl.init]]</a>
3314
 
3315
- The process of initialization described in this subclause applies to all
 
 
3316
  initializations regardless of syntactic context, including the
3317
  initialization of a function parameter [[expr.call]], the initialization
3318
  of a return value [[stmt.return]], or when an initializer follows a
3319
  declarator.
3320
 
@@ -3369,13 +3523,13 @@ designator:
3369
  expr-or-braced-init-list:
3370
  expression
3371
  braced-init-list
3372
  ```
3373
 
3374
- [*Note 1*: The rules in this subclause apply even if the grammar
3375
- permits only the *brace-or-equal-initializer* form of *initializer* in a
3376
- given context. — *end note*]
3377
 
3378
  Except for objects declared with the `constexpr` specifier, for which
3379
  see  [[dcl.constexpr]], an *initializer* in the definition of a variable
3380
  can consist of arbitrary expressions involving literals and previously
3381
  declared variables and functions, regardless of the variable’s storage
@@ -3397,26 +3551,26 @@ int c(b);
3397
 
3398
  [*Note 3*: The order of initialization of variables with static storage
3399
  duration is described in  [[basic.start]] and 
3400
  [[stmt.dcl]]. — *end note*]
3401
 
3402
- A declaration of a block-scope variable with external or internal
3403
- linkage that has an *initializer* is ill-formed.
3404
 
3405
  To *zero-initialize* an object or reference of type `T` means:
3406
 
3407
- - if `T` is a scalar type [[basic.types]], the object is initialized to
3408
- the value obtained by converting the integer literal `0` (zero) to
3409
- `T`;[^5]
3410
  - if `T` is a (possibly cv-qualified) non-union class type, its padding
3411
- bits [[basic.types]] are initialized to zero bits and each non-static
3412
- data member, each non-virtual base class subobject, and, if the object
3413
- is not a base class subobject, each virtual base class subobject is
3414
- zero-initialized;
3415
  - if `T` is a (possibly cv-qualified) union type, its padding bits
3416
- [[basic.types]] are initialized to zero bits and the object’s first
3417
- non-static named data member is zero-initialized;
3418
  - if `T` is an array type, each element is zero-initialized;
3419
  - if `T` is a reference type, no initialization is performed.
3420
 
3421
  To *default-initialize* an object of type `T` means:
3422
 
@@ -3466,62 +3620,25 @@ of an entity of reference type is ill-formed.
3466
  [*Note 4*: For every object of static storage duration, static
3467
  initialization [[basic.start.static]] is performed at program startup
3468
  before any other initialization takes place. In some cases, additional
3469
  initialization is done later. — *end note*]
3470
 
3471
- An object whose initializer is an empty set of parentheses, i.e., `()`,
3472
- shall be value-initialized.
3473
-
3474
- [*Note 5*:
3475
-
3476
- Since `()` is not permitted by the syntax for *initializer*,
3477
-
3478
- ``` cpp
3479
- X a();
3480
- ```
3481
-
3482
- is not the declaration of an object of class `X`, but the declaration of
3483
- a function taking no argument and returning an `X`. The form `()` is
3484
- permitted in certain other initialization contexts ([[expr.new]],
3485
- [[expr.type.conv]], [[class.base.init]]).
3486
-
3487
- — *end note*]
3488
-
3489
  If no initializer is specified for an object, the object is
3490
  default-initialized.
3491
 
3492
- An initializer for a static member is in the scope of the member’s
3493
- class.
3494
-
3495
- [*Example 2*:
3496
-
3497
- ``` cpp
3498
- int a;
3499
-
3500
- struct X {
3501
- static int a;
3502
- static int b;
3503
- };
3504
-
3505
- int X::a = 1;
3506
- int X::b = a; // X::b = X::a
3507
- ```
3508
-
3509
- — *end example*]
3510
-
3511
  If the entity being initialized does not have class type, the
3512
  *expression-list* in a parenthesized initializer shall be a single
3513
  expression.
3514
 
3515
  The initialization that occurs in the `=` form of a
3516
  *brace-or-equal-initializer* or *condition* [[stmt.select]], as well as
3517
  in argument passing, function return, throwing an exception
3518
  [[except.throw]], handling an exception [[except.handle]], and aggregate
3519
- member initialization [[dcl.init.aggr]], is called
3520
- *copy-initialization*.
3521
 
3522
- [*Note 6*: Copy-initialization may invoke a move
3523
  [[class.copy.ctor]]. — *end note*]
3524
 
3525
  The initialization that occurs
3526
 
3527
  - for an *initializer* that is a parenthesized *expression-list* or a
@@ -3546,10 +3663,21 @@ defined.
3546
  - If the destination type is an array of characters, an array of
3547
  `char8_t`, an array of `char16_t`, an array of `char32_t`, or an array
3548
  of `wchar_t`, and the initializer is a *string-literal*, see 
3549
  [[dcl.init.string]].
3550
  - If the initializer is `()`, the object is value-initialized.
 
 
 
 
 
 
 
 
 
 
 
3551
  - Otherwise, if the destination type is an array, the object is
3552
  initialized as follows. Let x₁, …, xₖ be the elements of the
3553
  *expression-list*. If the destination type is an array of unknown
3554
  bound, it is defined as having k elements. Let n denote the array size
3555
  after this potential adjustment. If k is greater than n, the program
@@ -3562,12 +3690,12 @@ defined.
3562
  - Otherwise, if the destination type is a (possibly cv-qualified) class
3563
  type:
3564
  - If the initializer expression is a prvalue and the cv-unqualified
3565
  version of the source type is the same class as the class of the
3566
  destination, the initializer expression is used to initialize the
3567
- destination object. \[*Example 3*: `T x = T(T(T()));` calls the `T`
3568
- default constructor to initialize `x`. — *end example*]
3569
  - Otherwise, if the initialization is direct-initialization, or if it
3570
  is copy-initialization where the cv-unqualified version of the
3571
  source type is the same class as, or a derived class of, the class
3572
  of the destination, constructors are considered. The applicable
3573
  constructors are enumerated [[over.match.ctor]], and the best one is
@@ -3590,11 +3718,11 @@ defined.
3590
  \[*Note 7*:
3591
  By contrast with direct-list-initialization, narrowing conversions
3592
  [[dcl.init.list]] are permitted, designators are not permitted, a
3593
  temporary object bound to a reference does not have its lifetime
3594
  extended [[class.temporary]], and there is no brace elision.
3595
- \[*Example 4*:
3596
  ``` cpp
3597
  struct A {
3598
  int a;
3599
  int&& r;
3600
  };
@@ -3652,13 +3780,24 @@ defined.
3652
  int c = b;
3653
  ```
3654
 
3655
  — *end note*]
3656
 
 
 
 
 
 
 
3657
  An *initializer-clause* followed by an ellipsis is a pack expansion
3658
  [[temp.variadic]].
3659
 
 
 
 
 
 
3660
  If the initializer is a parenthesized *expression-list*, the expressions
3661
  are evaluated in the order specified for function calls [[expr.call]].
3662
 
3663
  The same *identifier* shall not appear in multiple *designator*s of a
3664
  *designated-initializer-list*.
@@ -3680,23 +3819,24 @@ A declaration that specifies the initialization of a variable, whether
3680
  from an explicit initializer or by default-initialization, is called the
3681
  *initializing declaration* of that variable.
3682
 
3683
  [*Note 10*: In most cases this is the defining declaration
3684
  [[basic.def]] of the variable, but the initializing declaration of a
3685
- non-inline static data member [[class.static.data]] might be the
3686
- declaration within the class definition and not the definition at
3687
- namespace scope. — *end note*]
3688
 
3689
  ### Aggregates <a id="dcl.init.aggr">[[dcl.init.aggr]]</a>
3690
 
3691
  An *aggregate* is an array or a class [[class]] with
3692
 
3693
  - no user-declared or inherited constructors [[class.ctor]],
3694
  - no private or protected direct non-static data members
3695
  [[class.access]],
3696
- - no virtual functions [[class.virtual]], and
3697
- - no virtual, private, or protected base classes [[class.mi]].
 
3698
 
3699
  [*Note 1*: Aggregate initialization does not allow accessing protected
3700
  and private base class’ members or constructors. — *end note*]
3701
 
3702
  The *elements* of an aggregate are:
@@ -3709,29 +3849,29 @@ The *elements* of an aggregate are:
3709
  When an aggregate is initialized by an initializer list as specified in 
3710
  [[dcl.init.list]], the elements of the initializer list are taken as
3711
  initializers for the elements of the aggregate. The *explicitly
3712
  initialized elements* of the aggregate are determined as follows:
3713
 
3714
- - If the initializer list is a *designated-initializer-list*, the
3715
- aggregate shall be of class type, the *identifier* in each
3716
- *designator* shall name a direct non-static data member of the class,
3717
- and the explicitly initialized elements of the aggregate are the
3718
- elements that are, or contain, those members.
3719
- - If the initializer list is an *initializer-list*, the explicitly
3720
- initialized elements of the aggregate are the first n elements of the
3721
- aggregate, where n is the number of elements in the initializer list.
 
3722
  - Otherwise, the initializer list must be `{}`, and there are no
3723
  explicitly initialized elements.
3724
 
3725
  For each explicitly initialized element:
3726
 
3727
- - If the element is an anonymous union object and the initializer list
3728
- is a *designated-initializer-list*, the anonymous union object is
3729
- initialized by the *designated-initializer-list* `{ `*D*` }`, where
3730
- *D* is the *designated-initializer-clause* naming a member of the
3731
- anonymous union object. There shall be only one such
3732
- *designated-initializer-clause*.
3733
  \[*Example 1*:
3734
  ``` cpp
3735
  struct C {
3736
  union {
3737
  int a;
@@ -3748,11 +3888,15 @@ For each explicitly initialized element:
3748
  *brace-or-equal-initializer* of the corresponding
3749
  *designated-initializer-clause*. If that initializer is of the form
3750
  *assignment-expression* or `= `*assignment-expression* and a narrowing
3751
  conversion [[dcl.init.list]] is required to convert the expression,
3752
  the program is ill-formed.
3753
- \[*Note 2*: If an initializer is itself an initializer list, the
 
 
 
 
3754
  element is list-initialized, which will result in a recursive
3755
  application of the rules in this subclause if the element is an
3756
  aggregate. — *end note*]
3757
  \[*Example 2*:
3758
  ``` cpp
@@ -3848,11 +3992,11 @@ expression not enclosed in braces, as described in  [[dcl.init]].
3848
 
3849
  The destructor for each element of class type is potentially invoked
3850
  [[class.dtor]] from the context where the aggregate initialization
3851
  occurs.
3852
 
3853
- [*Note 3*: This provision ensures that destructors can be called for
3854
  fully-constructed subobjects in case an exception is thrown
3855
  [[except.ctor]]. — *end note*]
3856
 
3857
  An array of unknown bound initialized with a brace-enclosed
3858
  *initializer-list* containing `n` *initializer-clause*s is defined as
@@ -3870,11 +4014,11 @@ elements since no size was specified and there are three initializers.
3870
  — *end example*]
3871
 
3872
  An array of unknown bound shall not be initialized with an empty
3873
  *braced-init-list* `{}`.[^6]
3874
 
3875
- [*Note 4*:
3876
 
3877
  A default member initializer does not determine the bound for a member
3878
  array of unknown bound. Since the default member initializer is ignored
3879
  if a suitable *mem-initializer* is present [[class.base.init]], the
3880
  default member initializer is not considered to initialize the array of
@@ -3890,11 +4034,11 @@ struct S {
3890
 
3891
  — *end example*]
3892
 
3893
  — *end note*]
3894
 
3895
- [*Note 5*:
3896
 
3897
  Static data members, non-static data members of anonymous union members,
3898
  and unnamed bit-fields are not considered elements of the aggregate.
3899
 
3900
  [*Example 6*:
@@ -3977,11 +4121,11 @@ struct A {
3977
  }; // Initialization not required for A::s3 because A::i3 is also not initialized
3978
  ```
3979
 
3980
  — *end example*]
3981
 
3982
- When initializing a multi-dimensional array, the *initializer-clause*s
3983
  initialize the elements with the last (rightmost) index of the array
3984
  varying the fastest [[dcl.array]].
3985
 
3986
  [*Example 10*:
3987
 
@@ -4051,11 +4195,11 @@ the element with an *assignment-expression*. If the
4051
  *assignment-expression* can initialize an element, the element is
4052
  initialized. Otherwise, if the element is itself a subaggregate, brace
4053
  elision is assumed and the *assignment-expression* is considered for the
4054
  initialization of the first element of the subaggregate.
4055
 
4056
- [*Note 6*: As specified above, brace elision cannot apply to
4057
  subaggregates with no elements; an *initializer-clause* for the entire
4058
  subobject is required. — *end note*]
4059
 
4060
  [*Example 12*:
4061
 
@@ -4076,16 +4220,16 @@ Braces are elided around the *initializer-clause* for `b.a1.i`. `b.a1.i`
4076
  is initialized with 4, `b.a2` is initialized with `a`, `b.z` is
4077
  initialized with whatever `a.operator int()` returns.
4078
 
4079
  — *end example*]
4080
 
4081
- [*Note 7*: An aggregate array or an aggregate class may contain
4082
  elements of a class type with a user-declared constructor
4083
  [[class.ctor]]. Initialization of these aggregate objects is described
4084
  in  [[class.expl.init]]. — *end note*]
4085
 
4086
- [*Note 8*: Whether the initialization of aggregates with static storage
4087
  duration is static or dynamic is specified in  [[basic.start.static]],
4088
  [[basic.start.dynamic]], and  [[stmt.dcl]]. — *end note*]
4089
 
4090
  When a union is initialized with an initializer list, there shall not be
4091
  more than one explicitly initialized element.
@@ -4103,23 +4247,27 @@ u f = { .b = "asdf" };
4103
  u g = { .a = 1, .b = "asdf" }; // error
4104
  ```
4105
 
4106
  — *end example*]
4107
 
4108
- [*Note 9*: As described above, the braces around the
4109
  *initializer-clause* for a union member can be omitted if the union is a
4110
  member of another aggregate. — *end note*]
4111
 
4112
  ### Character arrays <a id="dcl.init.string">[[dcl.init.string]]</a>
4113
 
4114
  An array of ordinary character type [[basic.fundamental]], `char8_t`
4115
- array, `char16_t` array, `char32_t` array, or `wchar_t` array can be
4116
  initialized by an ordinary string literal, UTF-8 string literal, UTF-16
4117
  string literal, UTF-32 string literal, or wide string literal,
4118
  respectively, or by an appropriately-typed *string-literal* enclosed in
4119
- braces [[lex.string]]. Successive characters of the value of the
4120
- *string-literal* initialize the elements of the array.
 
 
 
 
4121
 
4122
  [*Example 1*:
4123
 
4124
  ``` cpp
4125
  char msg[] = "Syntax error on line %s\n";
@@ -4147,12 +4295,12 @@ If there are fewer initializers than there are array elements, each
4147
  element not explicitly initialized shall be zero-initialized
4148
  [[dcl.init]].
4149
 
4150
  ### References <a id="dcl.init.ref">[[dcl.init.ref]]</a>
4151
 
4152
- A variable whose declared type is “reference to type `T`” [[dcl.ref]]
4153
- shall be initialized.
4154
 
4155
  [*Example 1*:
4156
 
4157
  ``` cpp
4158
  int g(int) noexcept;
@@ -4217,14 +4365,14 @@ A reference to type “*cv1* `T1`” is initialized by an expression of type
4217
  “*cv3* `T3`”, where “*cv1* `T1`” is reference-compatible with “*cv3*
4218
  `T3`”[^7] (this conversion is selected by enumerating the applicable
4219
  conversion functions [[over.match.ref]] and choosing the best one
4220
  through overload resolution [[over.match]]),
4221
 
4222
- then the reference is bound to the initializer expression lvalue in
4223
- the first case and to the lvalue result of the conversion in the
4224
- second case (or, in either case, to the appropriate base class
4225
- subobject of the object).
4226
  \[*Note 2*: The usual lvalue-to-rvalue [[conv.lval]], array-to-pointer
4227
  [[conv.array]], and function-to-pointer [[conv.func]] standard
4228
  conversions are not needed, and therefore are suppressed, when such
4229
  direct bindings to lvalues are done. — *end note*]
4230
  \[*Example 3*:
@@ -4258,55 +4406,57 @@ A reference to type “*cv1* `T1`” is initialized by an expression of type
4258
  - has a class type (i.e., `T2` is a class type), where `T1` is not
4259
  reference-related to `T2`, and can be converted to an rvalue or
4260
  function lvalue of type “*cv3* `T3`”, where “*cv1* `T1`” is
4261
  reference-compatible with “*cv3* `T3`” (see  [[over.match.ref]]),
4262
 
4263
- then the value of the initializer expression in the first case and the
4264
- result of the conversion in the second case is called the converted
4265
- initializer. If the converted initializer is a prvalue, its type `T4`
4266
- is adjusted to type “*cv1* `T4`” [[conv.qual]] and the temporary
4267
- materialization conversion [[conv.rval]] is applied. In any case, the
4268
- reference is bound to the resulting glvalue (or to an appropriate base
4269
- class subobject).
4270
  \[*Example 5*:
4271
  ``` cpp
4272
  struct A { };
4273
  struct B : A { } b;
4274
  extern B f();
4275
- const A& rca2 = f(); // bound to the A subobject of the B rvalue.
4276
  A&& rra = f(); // same as above
4277
  struct X {
4278
  operator B();
4279
  operator int&();
4280
  } x;
4281
- const A& r = x; // bound to the A subobject of the result of the conversion
4282
  int i2 = 42;
4283
- int&& rri = static_cast<int&&>(i2); // bound directly to i2
4284
- B&& rrb = x; // bound directly to the result of operator B
4285
  ```
4286
 
4287
  — *end example*]
4288
  - Otherwise:
4289
  - If `T1` or `T2` is a class type and `T1` is not reference-related to
4290
  `T2`, user-defined conversions are considered using the rules for
4291
  copy-initialization of an object of type “*cv1* `T1`” by
4292
- user-defined conversion ([[dcl.init]], [[over.match.copy]],
4293
- [[over.match.conv]]); the program is ill-formed if the corresponding
4294
- non-reference copy-initialization would be ill-formed. The result of
4295
- the call to the conversion function, as described for the
4296
- non-reference copy-initialization, is then used to direct-initialize
4297
- the reference. For this direct-initialization, user-defined
4298
- conversions are not considered.
4299
  - Otherwise, the initializer expression is implicitly converted to a
4300
- prvalue of type “*cv1* `T1`”. The temporary materialization
4301
- conversion is applied and the reference is bound to the result.
 
4302
 
4303
  If `T1` is reference-related to `T2`:
4304
  - *cv1* shall be the same cv-qualification as, or greater
4305
  cv-qualification than, *cv2*; and
4306
  - if the reference is an rvalue reference, the initializer expression
4307
- shall not be an lvalue.
 
 
4308
 
4309
  \[*Example 6*:
4310
  ``` cpp
4311
  struct Banana { };
4312
  struct Enigma { operator const Banana(); };
@@ -4337,11 +4487,11 @@ A reference to type “*cv1* `T1`” is initialized by an expression of type
4337
 
4338
  In all cases except the last (i.e., implicitly converting the
4339
  initializer expression to the referenced type), the reference is said to
4340
  *bind directly* to the initializer expression.
4341
 
4342
- [*Note 3*: [[class.temporary]] describes the lifetime of temporaries
4343
  bound to references. — *end note*]
4344
 
4345
  ### List-initialization <a id="dcl.init.list">[[dcl.init.list]]</a>
4346
 
4347
  *List-initialization* is initialization of an object or reference from a
@@ -4363,12 +4513,12 @@ List-initialization can be used
4363
  - as the initializer in a *new-expression* [[expr.new]]
4364
  - in a `return` statement [[stmt.return]]
4365
  - as a *for-range-initializer* [[stmt.iter]]
4366
  - as a function argument [[expr.call]]
4367
  - as a subscript [[expr.sub]]
4368
- - as an argument to a constructor invocation ([[dcl.init]],
4369
- [[expr.type.conv]])
4370
  - as an initializer for a non-static data member [[class.mem]]
4371
  - in a *mem-initializer* [[class.base.init]]
4372
  - on the right-hand side of an assignment [[expr.ass]]
4373
 
4374
  [*Example 1*:
@@ -4400,12 +4550,13 @@ initializer list as the argument to the constructor template
4400
  `template<class T> C(T)` of a class `C` does not create an
4401
  initializer-list constructor, because an initializer list argument
4402
  causes the corresponding parameter to be a non-deduced context
4403
  [[temp.deduct.call]]. — *end note*]
4404
 
4405
- The template `std::initializer_list` is not predefined; if the header
4406
- `<initializer_list>` is not imported or included prior to a use of
 
4407
  `std::initializer_list` — even an implicit use in which the type is not
4408
  named [[dcl.spec.auto]] — the program is ill-formed.
4409
 
4410
  List-initialization of an object or reference of type `T` is defined as
4411
  follows:
@@ -4444,22 +4595,22 @@ follows:
4444
  int m1;
4445
  double m2, m3;
4446
  };
4447
  S2 s21 = { 1, 2, 3.0 }; // OK
4448
  S2 s22 { 1.0, 2, 3 }; // error: narrowing
4449
- S2 s23 { }; // OK: default to 0,0,0
4450
  ```
4451
 
4452
  — *end example*]
4453
  - Otherwise, if the initializer list has no elements and `T` is a class
4454
  type with a default constructor, the object is value-initialized.
4455
  - Otherwise, if `T` is a specialization of `std::initializer_list<E>`,
4456
  the object is constructed as described below.
4457
  - Otherwise, if `T` is a class type, constructors are considered. The
4458
  applicable constructors are enumerated and the best one is chosen
4459
- through overload resolution ([[over.match]], [[over.match.list]]). If
4460
- a narrowing conversion (see below) is required to convert any of the
4461
  arguments, the program is ill-formed.
4462
  \[*Example 4*:
4463
  ``` cpp
4464
  struct S {
4465
  S(std::initializer_list<double>); // #1
@@ -4488,13 +4639,13 @@ follows:
4488
  // no initializer-list constructors
4489
  S(int, double, double); // #1
4490
  S(); // #2
4491
  // ...
4492
  };
4493
- S s1 = { 1, 2, 3.0 }; // OK: invoke #1
4494
  S s2 { 1.0, 2, 3 }; // error: narrowing
4495
- S s3 { }; // OK: invoke #2
4496
  ```
4497
 
4498
  — *end example*]
4499
  - Otherwise, if `T` is an enumeration with a fixed underlying type
4500
  [[dcl.enum]] `U`, the *initializer-list* has a single element `v`, `v`
@@ -4535,32 +4686,32 @@ follows:
4535
  int x2 {2.0}; // error: narrowing
4536
  ```
4537
 
4538
  — *end example*]
4539
  - Otherwise, if `T` is a reference type, a prvalue is generated. The
4540
- prvalue initializes its result object by copy-list-initialization. The
4541
- prvalue is then used to direct-initialize the reference. The type of
4542
- the temporary is the type referenced by `T`, unless `T` is “reference
4543
- to array of unknown bound of `U`”, in which case the type of the
4544
- temporary is the type of `x` in the declaration `U x[] H`, where H is
4545
- the initializer list.
4546
  \[*Note 3*: As usual, the binding will fail and the program is
4547
  ill-formed if the reference type is an lvalue reference to a non-const
4548
  type. — *end note*]
4549
  \[*Example 9*:
4550
  ``` cpp
4551
  struct S {
4552
  S(std::initializer_list<double>); // #1
4553
  S(const std::string&); // #2
4554
  // ...
4555
  };
4556
- const S& r1 = { 1, 2, 3.0 }; // OK: invoke #1
4557
- const S& r2 { "Spinach" }; // OK: invoke #2
4558
  S& r3 = { 1, 2, 3 }; // error: initializer is not an lvalue
4559
  const int& i1 = { 1 }; // OK
4560
  const int& i2 = { 1.1 }; // error: narrowing
4561
- const int (&iar)[2] = { 1, 2 }; // OK: iar is bound to temporary array
4562
 
4563
  struct A { } a;
4564
  struct B { explicit B(const A&); };
4565
  const B& b2{a}; // error: cannot copy-list-initialize B temporary from A
4566
  ```
@@ -4679,27 +4830,34 @@ variable, so the array persists for the lifetime of the variable. For
4679
  member, so the program is ill-formed [[class.base.init]].
4680
 
4681
  — *end example*]
4682
 
4683
  [*Note 6*: The implementation is free to allocate the array in
4684
- read-only memory if an explicit array with the same initializer could be
4685
  so allocated. — *end note*]
4686
 
4687
  A *narrowing conversion* is an implicit conversion
4688
 
4689
  - from a floating-point type to an integer type, or
4690
- - from `long double` to `double` or `float`, or from `double` to
4691
- `float`, except where the source is a constant expression and the
 
4692
  actual value after conversion is within the range of values that can
4693
  be represented (even if it cannot be represented exactly), or
4694
  - from an integer type or unscoped enumeration type to a floating-point
4695
  type, except where the source is a constant expression and the actual
4696
  value after conversion will fit into the target type and will produce
4697
  the original value when converted back to the original type, or
4698
  - from an integer type or unscoped enumeration type to an integer type
4699
  that cannot represent all the values of the original type, except
4700
- where the source is a constant expression whose value after integral
 
 
 
 
 
 
4701
  promotions will fit into the target type, or
4702
  - from a pointer type or a pointer-to-member type to `bool`.
4703
 
4704
  [*Note 7*: As indicated above, such conversions are not allowed at the
4705
  top level in list-initializations. — *end note*]
@@ -4708,25 +4866,25 @@ top level in list-initializations. — *end note*]
4708
 
4709
  ``` cpp
4710
  int x = 999; // x is not a constant expression
4711
  const int y = 999;
4712
  const int z = 99;
4713
- char c1 = x; // OK, though it might narrow (in this case, it does narrow)
4714
- char c2{x}; // error: might narrow
4715
  char c3{y}; // error: narrows (assuming char is 8 bits)
4716
- char c4{z}; // OK: no narrowing needed
4717
- unsigned char uc1 = {5}; // OK: no narrowing needed
4718
  unsigned char uc2 = {-1}; // error: narrows
4719
  unsigned int ui1 = {-1}; // error: narrows
4720
  signed int si1 =
4721
  { (unsigned int)-1 }; // error: narrows
4722
  int ii = {2.0}; // error: narrows
4723
- float f1 { x }; // error: might narrow
4724
- float f2 { 7 }; // OK: 7 can be exactly represented as a float
4725
  bool b = {"meow"}; // error: narrows
4726
  int f(int);
4727
- int a[] = { 2, f(2), f(2.0) }; // OK: the double-to-int conversion is not at the top level
4728
  ```
4729
 
4730
  — *end example*]
4731
 
4732
  ## Function definitions <a id="dcl.fct.def">[[dcl.fct.def]]</a>
@@ -4781,11 +4939,11 @@ Here `int` is the *decl-specifier-seq*; `max(int` `a,` `int` `b,` `int`
4781
 
4782
  A *ctor-initializer* is used only in a constructor; see  [[class.ctor]]
4783
  and  [[class.init]].
4784
 
4785
  [*Note 1*: A *cv-qualifier-seq* affects the type of `this` in the body
4786
- of a member function; see  [[dcl.ref]]. — *end note*]
4787
 
4788
  [*Note 2*:
4789
 
4790
  Unused parameters need not be named. For example,
4791
 
@@ -4795,13 +4953,12 @@ void print(int a, int) {
4795
  }
4796
  ```
4797
 
4798
  — *end note*]
4799
 
4800
- In the *function-body*, a *function-local predefined variable* denotes a
4801
- block-scope object of static storage duration that is implicitly defined
4802
- (see  [[basic.scope.block]]).
4803
 
4804
  The function-local predefined variable `__func__` is defined as if a
4805
  definition of the form
4806
 
4807
  ``` cpp
@@ -4832,47 +4989,50 @@ explicitly defaulted shall
4832
 
4833
  - be a special member function or a comparison operator function
4834
  [[over.binary]], and
4835
  - not have default arguments.
4836
 
4837
- The type `T`₁ of an explicitly defaulted special member function `F` is
4838
- allowed to differ from the type `T`₂ it would have had if it were
4839
- implicitly declared, as follows:
4840
 
4841
- - `T`₁ and `T`₂ may have differing *ref-qualifier*s;
4842
- - `T` and `T`₂ may have differing exception specifications; and
4843
- - if `T` has a parameter of type `const C&`, the corresponding
4844
- parameter of `T` may be of type `C&`.
 
 
 
 
 
4845
 
4846
- If `T`₁ differs from `T`₂ in any other way, then:
 
4847
 
4848
- - if `F` is an assignment operator, and the return type of `T`₁ differs
4849
- from the return type of `T`₂ or `T`₁’s parameter type is not a
4850
- reference, the program is ill-formed;
4851
- - otherwise, if `F` is explicitly defaulted on its first declaration, it
4852
- is defined as deleted;
4853
  - otherwise, the program is ill-formed.
4854
 
4855
- An explicitly-defaulted function that is not defined as deleted may be
4856
- declared `constexpr` or `consteval` only if it is constexpr-compatible (
4857
- [[special]], [[class.compare.default]]). A function explicitly defaulted
4858
- on its first declaration is implicitly inline [[dcl.inline]], and is
4859
- implicitly constexpr [[dcl.constexpr]] if it is constexpr-compatible.
4860
 
4861
  [*Example 1*:
4862
 
4863
  ``` cpp
4864
  struct S {
4865
- constexpr S() = default; // error: implicit S() is not constexpr
4866
  S(int a = 0) = default; // error: default argument
4867
  void operator=(const S&) = default; // error: non-matching return type
4868
  ~S() noexcept(false) = default; // OK, despite mismatched exception specification
4869
  private:
4870
  int i;
4871
- S(S&); // OK: private copy constructor
4872
  };
4873
- S::S(S&) = default; // OK: defines copy constructor
4874
 
4875
  struct T {
4876
  T();
4877
  T(T &&) noexcept(false);
4878
  };
@@ -4887,21 +5047,26 @@ U u2 = static_cast<U&&>(u1); // OK, calls std::terminate if T::T(T&&)
4887
 
4888
  — *end example*]
4889
 
4890
  Explicitly-defaulted functions and implicitly-declared functions are
4891
  collectively called *defaulted* functions, and the implementation shall
4892
- provide implicit definitions for them ([[class.ctor]], [[class.dtor]],
4893
- [[class.copy.ctor]], [[class.copy.assign]]), which might mean defining
4894
- them as deleted. A defaulted prospective destructor [[class.dtor]] that
4895
- is not a destructor is defined as deleted. A defaulted special member
4896
- function that is neither a prospective destructor nor an eligible
4897
- special member function [[special]] is defined as deleted. A function is
4898
- *user-provided* if it is user-declared and not explicitly defaulted or
4899
- deleted on its first declaration. A user-provided explicitly-defaulted
4900
- function (i.e., explicitly defaulted after its first declaration) is
4901
- defined at the point where it is explicitly defaulted; if such a
4902
- function is implicitly defined as deleted, the program is ill-formed.
 
 
 
 
 
4903
 
4904
  [*Note 1*: Declaring a function as defaulted after its first
4905
  declaration can provide efficient execution and concise definition while
4906
  enabling a stable binary interface to an evolving code
4907
  base. — *end note*]
@@ -4926,24 +5091,25 @@ nontrivial1::nontrivial1() = default; // not first declaration
4926
 
4927
  — *end example*]
4928
 
4929
  ### Deleted definitions <a id="dcl.fct.def.delete">[[dcl.fct.def.delete]]</a>
4930
 
4931
- A function definition whose *function-body* is of the form `= delete ;`
4932
- is called a *deleted definition*. A function with a deleted definition
4933
- is also called a *deleted function*.
 
 
4934
 
4935
  A program that refers to a deleted function implicitly or explicitly,
4936
  other than to declare it, is ill-formed.
4937
 
4938
  [*Note 1*: This includes calling the function implicitly or explicitly
4939
  and forming a pointer or pointer-to-member to the function. It applies
4940
  even for references in expressions that are not potentially-evaluated.
4941
- If a function is overloaded, it is referenced only if the function is
4942
- selected by overload resolution. The implicit odr-use [[basic.def.odr]]
4943
- of a virtual function does not, by itself, constitute a
4944
- reference. — *end note*]
4945
 
4946
  [*Example 1*:
4947
 
4948
  One can prevent default initialization and initialization by
4949
  non-`double`s with
@@ -5052,19 +5218,21 @@ task<void> g3(int a, ...) { // error: variable parameter list not allowed
5052
 
5053
  — *end example*]
5054
 
5055
  The *promise type* of a coroutine is
5056
  `std::coroutine_traits<R, P₁, …, Pₙ>::promise_type`, where `R` is the
5057
- return type of the function, and `P₁` … `Pₙ` are the sequence of types
5058
- of the function parameters, preceded by the type of the implicit object
5059
- parameter [[over.match.funcs]] if the coroutine is a non-static member
5060
- function. The promise type shall be a class type.
5061
 
5062
- In the following, `pᵢ` is an lvalue of type `Pᵢ`, where `p₁` denotes
5063
- `*this` and `p_i+1` denotes the $i^\textrm{th}$ function parameter for a
5064
- non-static member function, and `pᵢ` denotes the $i^\textrm{th}$
5065
- function parameter otherwise.
 
 
5066
 
5067
  A coroutine behaves as if its *function-body* were replaced by:
5068
 
5069
  ``` bnf
5070
  '{'
@@ -5085,75 +5253,81 @@ final-suspend ':'
5085
  ```
5086
 
5087
  where
5088
 
5089
  - the *await-expression* containing the call to `initial_suspend` is the
5090
- *initial suspend point*, and
5091
  - the *await-expression* containing the call to `final_suspend` is the
5092
- *final suspend point*, and
5093
  - *initial-await-resume-called* is initially `false` and is set to
5094
  `true` immediately before the evaluation of the *await-resume*
5095
- expression [[expr.await]] of the initial suspend point, and
5096
  - *promise-type* denotes the promise type, and
5097
  - the object denoted by the exposition-only name *`promise`* is the
5098
  *promise object* of the coroutine, and
5099
  - the label denoted by the name *`final-suspend`* is defined for
5100
  exposition only [[stmt.return.coroutine]], and
5101
  - *promise-constructor-arguments* is determined as follows: overload
5102
  resolution is performed on a promise constructor call created by
5103
- assembling an argument list with lvalues `p₁` … `pₙ`. If a viable
5104
- constructor is found [[over.match.viable]], then
5105
- *promise-constructor-arguments* is `(p₁, …, pₙ)`, otherwise
5106
- *promise-constructor-arguments* is empty.
 
 
 
 
5107
 
5108
- The *unqualified-id*s `return_void` and `return_value` are looked up in
5109
- the scope of the promise type. If both are found, the program is
5110
  ill-formed.
5111
 
5112
- [*Note 1*: If the *unqualified-id* `return_void` is found, flowing off
5113
- the end of a coroutine is equivalent to a `co_return` with no operand.
5114
- Otherwise, flowing off the end of a coroutine results in undefined
5115
- behavior [[stmt.return.coroutine]]. — *end note*]
5116
 
5117
  The expression `promise.get_return_object()` is used to initialize the
5118
- glvalue result or prvalue result object of a call to a coroutine. The
5119
- call to `get_return_object` is sequenced before the call to
5120
  `initial_suspend` and is invoked at most once.
5121
 
5122
  A suspended coroutine can be resumed to continue execution by invoking a
5123
  resumption member function [[coroutine.handle.resumption]] of a
5124
  coroutine handle [[coroutine.handle]] that refers to the coroutine. The
5125
- function that invoked a resumption member function is called the
5126
  *resumer*. Invoking a resumption member function for a coroutine that is
5127
  not suspended results in undefined behavior.
5128
 
5129
  An implementation may need to allocate additional storage for a
5130
  coroutine. This storage is known as the *coroutine state* and is
5131
  obtained by calling a non-array allocation function
5132
  [[basic.stc.dynamic.allocation]]. The allocation function’s name is
5133
- looked up in the scope of the promise type. If this lookup fails, the
5134
- allocation function’s name is looked up in the global scope. If the
5135
- lookup finds an allocation function in the scope of the promise type,
5136
- overload resolution is performed on a function call created by
5137
- assembling an argument list. The first argument is the amount of space
5138
- requested, and has type `std::size_t`. The lvalues `p₁` … `pₙ` are the
5139
- succeeding arguments. If no viable function is found
5140
- [[over.match.viable]], overload resolution is performed again on a
5141
- function call created by passing just the amount of space required as an
5142
- argument of type `std::size_t`.
5143
 
5144
- The *unqualified-id* `get_return_object_on_allocation_failure` is looked
5145
- up in the scope of the promise type by class member access lookup
5146
- [[basic.lookup.classref]]. If any declarations are found, then the
5147
- result of a call to an allocation function used to obtain storage for
5148
- the coroutine state is assumed to return `nullptr` if it fails to obtain
5149
- storage, and if a global allocation function is selected, the
5150
- `::operator new(size_t, nothrow_t)` form is used. The allocation
5151
- function used in this case shall have a non-throwing
5152
- *noexcept-specification*. If the allocation function returns `nullptr`,
5153
- the coroutine returns control to the caller of the coroutine and the
5154
- return value is obtained by a call to
 
 
 
 
 
 
 
 
 
 
 
5155
  `T::get_return_object_on_allocation_failure()`, where `T` is the promise
5156
  type.
5157
 
5158
  [*Example 2*:
5159
 
@@ -5168,11 +5342,11 @@ struct generator {
5168
  struct promise_type {
5169
  int current_value;
5170
  static auto get_return_object_on_allocation_failure() { return generator{nullptr}; }
5171
  auto get_return_object() { return generator{handle::from_promise(*this)}; }
5172
  auto initial_suspend() { return std::suspend_always{}; }
5173
- auto final_suspend() { return std::suspend_always{}; }
5174
  void unhandled_exception() { std::terminate(); }
5175
  void return_void() {}
5176
  auto yield_value(int value) {
5177
  current_value = value;
5178
  return std::suspend_always{};
@@ -5198,30 +5372,28 @@ int main() {
5198
 
5199
  The coroutine state is destroyed when control flows off the end of the
5200
  coroutine or the `destroy` member function
5201
  [[coroutine.handle.resumption]] of a coroutine handle
5202
  [[coroutine.handle]] that refers to the coroutine is invoked. In the
5203
- latter case objects with automatic storage duration that are in scope at
5204
- the suspend point are destroyed in the reverse order of the
5205
- construction. The storage for the coroutine state is released by calling
5206
- a non-array deallocation function [[basic.stc.dynamic.deallocation]]. If
5207
- `destroy` is called for a coroutine that is not suspended, the program
5208
- has undefined behavior.
5209
 
5210
- The deallocation function’s name is looked up in the scope of the
5211
- promise type. If this lookup fails, the deallocation function’s name is
5212
- looked up in the global scope. If deallocation function lookup finds
5213
- both a usual deallocation function with only a pointer parameter and a
5214
- usual deallocation function with both a pointer parameter and a size
5215
- parameter, then the selected deallocation function shall be the one with
5216
- two parameters. Otherwise, the selected deallocation function shall be
5217
- the function with one parameter. If no usual deallocation function is
5218
- found, the program is ill-formed. The selected deallocation function
5219
- shall be called with the address of the block of storage to be reclaimed
5220
- as its first argument. If a deallocation function with a parameter of
5221
- type `std::size_t` is used, the size of the block is passed as the
5222
- corresponding argument.
5223
 
5224
  When a coroutine is invoked, after initializing its parameters
5225
  [[expr.call]], a copy is created for each coroutine parameter. For a
5226
  parameter of type cv `T`, the copy is a variable of type cv `T` with
5227
  automatic storage duration that is direct-initialized from an xvalue of
@@ -5242,26 +5414,27 @@ the coroutine after the lifetime of the entity referred to by that
5242
  parameter has ended is likely to result in undefined
5243
  behavior. — *end note*]
5244
 
5245
  If the evaluation of the expression `promise.unhandled_exception()`
5246
  exits via an exception, the coroutine is considered suspended at the
5247
- final suspend point.
 
5248
 
5249
  The expression `co_await` `promise.final_suspend()` shall not be
5250
  potentially-throwing [[except.spec]].
5251
 
5252
  ## Structured binding declarations <a id="dcl.struct.bind">[[dcl.struct.bind]]</a>
5253
 
5254
  A structured binding declaration introduces the *identifier*s `v₀`,
5255
- `v₁`, `v₂`, … of the *identifier-list* as names
5256
- [[basic.scope.declarative]] of *structured binding*s. Let cv denote the
5257
- *cv-qualifier*s in the *decl-specifier-seq* and *S* consist of the
5258
- *storage-class-specifier*s of the *decl-specifier-seq* (if any). A cv
5259
- that includes `volatile` is deprecated; see  [[depr.volatile.type]].
5260
- First, a variable with a unique name *`e`* is introduced. If the
5261
- *assignment-expression* in the *initializer* has array type `A` and no
5262
- *ref-qualifier* is present, *`e`* is defined by
5263
 
5264
  ``` bnf
5265
  attribute-specifier-seqₒₚₜ *S* cv 'A' e ';'
5266
  ```
5267
 
@@ -5283,11 +5456,11 @@ from the corresponding structured binding declaration. The type of the
5283
  If the *initializer* refers to one of the names introduced by the
5284
  structured binding declaration, the program is ill-formed.
5285
 
5286
  If `E` is an array type with element type `T`, the number of elements in
5287
  the *identifier-list* shall be equal to the number of elements of `E`.
5288
- Each `v`ᵢ is the name of an lvalue that refers to the element i of the
5289
  array and whose type is `T`; the referenced type is `T`.
5290
 
5291
  [*Note 2*: The top-level cv-qualifiers of `T` are cv. — *end note*]
5292
 
5293
  [*Example 1*:
@@ -5303,18 +5476,17 @@ auto& [ xr, yr ] = f(); // xr and yr refer to elements in the array refe
5303
  Otherwise, if the *qualified-id* `std::tuple_size<E>` names a complete
5304
  class type with a member named `value`, the expression
5305
  `std::tuple_size<E>::value` shall be a well-formed integral constant
5306
  expression and the number of elements in the *identifier-list* shall be
5307
  equal to the value of that expression. Let `i` be an index prvalue of
5308
- type `std::size_t` corresponding to `v`_`i`. The *unqualified-id* `get`
5309
- is looked up in the scope of `E` by class member access lookup
5310
- [[basic.lookup.classref]], and if that finds at least one declaration
5311
- that is a function template whose first template parameter is a non-type
5312
- parameter, the initializer is `e.get<i>()`. Otherwise, the initializer
5313
- is `get<i>(e)`, where `get` is looked up in the associated namespaces
5314
- [[basic.lookup.argdep]]. In either case, `get<i>` is interpreted as a
5315
- *template-id*.
5316
 
5317
  [*Note 3*: Ordinary unqualified lookup [[basic.lookup.unqual]] is not
5318
  performed. — *end note*]
5319
 
5320
  In either case, *`e`* is an lvalue if the type of the entity *`e`* is an
@@ -5335,24 +5507,25 @@ Otherwise, all of `E`’s non-static data members shall be direct members
5335
  of `E` or of the same base class of `E`, well-formed when named as
5336
  `e.name` in the context of the structured binding, `E` shall not have an
5337
  anonymous union member, and the number of elements in the
5338
  *identifier-list* shall be equal to the number of non-static data
5339
  members of `E`. Designating the non-static data members of `E` as `m₀`,
5340
- `m₁`, `m₂`, … (in declaration order), each `v`ᵢ is the name of an lvalue
5341
- that refers to the member `m`ᵢ of *`e`* and whose type is cv `Tᵢ`, where
5342
- `Tᵢ` is the declared type of that member; the referenced type is
5343
- cv `Tᵢ`. The lvalue is a bit-field if that member is a bit-field.
 
5344
 
5345
  [*Example 2*:
5346
 
5347
  ``` cpp
5348
- struct S { int x1 : 2; volatile double y1; };
5349
  S f();
5350
  const auto [ x, y ] = f();
5351
  ```
5352
 
5353
- The type of the *id-expression* `x` is “`const int`”, the type of the
5354
  *id-expression* `y` is “`const volatile double`”.
5355
 
5356
  — *end example*]
5357
 
5358
  ## Enumerations <a id="enum">[[enum]]</a>
@@ -5442,11 +5615,13 @@ struct S {
5442
 
5443
  — *end example*]
5444
 
5445
  — *end note*]
5446
 
5447
- If the *enum-head-name* of an *opaque-enum-declaration* contains a
 
 
5448
  *nested-name-specifier*, the declaration shall be an explicit
5449
  specialization [[temp.expl.spec]].
5450
 
5451
  The enumeration type declared with an *enum-key* of only `enum` is an
5452
  *unscoped enumeration*, and its *enumerator*s are *unscoped
@@ -5457,16 +5632,18 @@ enumerators*. The optional *enum-head-name* shall not be omitted in the
5457
  declaration of a scoped enumeration. The *type-specifier-seq* of an
5458
  *enum-base* shall name an integral type; any cv-qualification is
5459
  ignored. An *opaque-enum-declaration* declaring an unscoped enumeration
5460
  shall not omit the *enum-base*. The identifiers in an *enumerator-list*
5461
  are declared as constants, and can appear wherever constants are
5462
- required. An *enumerator-definition* with `=` gives the associated
5463
- *enumerator* the value indicated by the *constant-expression*. If the
5464
- first *enumerator* has no *initializer*, the value of the corresponding
5465
- constant is zero. An *enumerator-definition* without an *initializer*
5466
- gives the *enumerator* the value obtained by increasing the value of the
5467
- previous *enumerator* by one.
 
 
5468
 
5469
  [*Example 2*:
5470
 
5471
  ``` cpp
5472
  enum { a, b, c=0 };
@@ -5492,19 +5669,17 @@ can be provided in a later redeclaration with an
5492
  A scoped enumeration shall not be later redeclared as unscoped or with a
5493
  different underlying type. An unscoped enumeration shall not be later
5494
  redeclared as scoped and each redeclaration shall include an *enum-base*
5495
  specifying the same underlying type as in the original declaration.
5496
 
5497
- If an *enum-head-name* contains a *nested-name-specifier*, it shall not
5498
- begin with a *decltype-specifier* and the enclosing *enum-specifier* or
5499
- *opaque-enum-declaration* shall refer to an enumeration that was
5500
- previously declared directly in the class or namespace to which the
5501
- *nested-name-specifier* refers, or in an element of the inline namespace
5502
- set [[namespace.def]] of that namespace (i.e., neither inherited nor
5503
- introduced by a *using-declaration*), and the *enum-specifier* or
5504
- *opaque-enum-declaration* shall appear in a namespace enclosing the
5505
- previous declaration.
5506
 
5507
  Each enumeration defines a type that is different from all other types.
5508
  Each enumeration also has an *underlying type*. The underlying type can
5509
  be explicitly specified using an *enum-base*. For a scoped enumeration
5510
  type, the underlying type is `int` if it is not explicitly specified. In
@@ -5528,16 +5703,15 @@ the closing brace is determined as follows:
5528
  preceding enumerator unless the incremented value is not representable
5529
  in that type, in which case the type is an unspecified integral type
5530
  sufficient to contain the incremented value. If no such type exists,
5531
  the program is ill-formed.
5532
 
5533
- An enumeration whose underlying type is fixed is an incomplete type from
5534
- its point of declaration [[basic.scope.pdecl]] to immediately after its
5535
- *enum-base* (if any), at which point it becomes a complete type. An
5536
- enumeration whose underlying type is not fixed is an incomplete type
5537
- from its point of declaration to immediately after the closing `}` of
5538
- its *enum-specifier*, at which point it becomes a complete type.
5539
 
5540
  For an enumeration whose underlying type is not fixed, the underlying
5541
  type is an integral type that can represent all the enumerator values
5542
  defined in the enumeration. If no integral type can represent all the
5543
  enumerator values, the enumeration is ill-formed. It is
@@ -5555,10 +5729,15 @@ represented. The width of the smallest bit-field large enough to hold
5555
  all the values of the enumeration type is M. It is possible to define an
5556
  enumeration that has values not defined by any of its enumerators. If
5557
  the *enumerator-list* is empty, the values of the enumeration are as if
5558
  the enumeration had a single enumerator with value 0.[^9]
5559
 
 
 
 
 
 
5560
  Two enumeration types are *layout-compatible enumerations* if they have
5561
  the same underlying type.
5562
 
5563
  The value of an enumerator or an object of an unscoped enumeration type
5564
  is converted to an integer by integral promotion [[conv.prom]].
@@ -5579,11 +5758,11 @@ type. The possible values of an object of type `color` are `red`,
5579
  values `0`, `1`, `20`, and `21`. Since enumerations are distinct types,
5580
  objects of type `color` can be assigned only values of type `color`.
5581
 
5582
  ``` cpp
5583
  color c = 1; // error: type mismatch, no conversion from int to color
5584
- int i = yellow; // OK: yellow converted to integral value 1, integral promotion
5585
  ```
5586
 
5587
  Note that this implicit `enum` to `int` conversion is not provided for a
5588
  scoped enumeration:
5589
 
@@ -5594,19 +5773,17 @@ Col y = Col::red;
5594
  if (y) { } // error: no Col to bool conversion
5595
  ```
5596
 
5597
  — *end example*]
5598
 
5599
- Each *enum-name* and each unscoped *enumerator* is declared in the scope
5600
- that immediately contains the *enum-specifier*. Each scoped *enumerator*
5601
- is declared in the scope of the enumeration. An unnamed enumeration that
5602
  does not have a typedef name for linkage purposes [[dcl.typedef]] and
5603
  that has a first enumerator is denoted, for linkage purposes
5604
  [[basic.link]], by its underlying type and its first enumerator; such an
5605
  enumeration is said to have an enumerator as a name for linkage
5606
- purposes. These names obey the scope rules defined for all names in 
5607
- [[basic.scope]] and  [[basic.lookup]].
5608
 
5609
  [*Note 3*: Each unnamed enumeration with no enumerators is a distinct
5610
  type. — *end note*]
5611
 
5612
  [*Example 4*:
@@ -5629,52 +5806,35 @@ void h() {
5629
  }
5630
  ```
5631
 
5632
  — *end example*]
5633
 
5634
- An enumerator declared in class scope can be referred to using the class
5635
- member access operators (`::`, `.` (dot) and `->` (arrow)), see 
5636
- [[expr.ref]].
5637
-
5638
- [*Example 5*:
5639
-
5640
- ``` cpp
5641
- struct X {
5642
- enum direction { left='l', right='r' };
5643
- int f(int i) { return i==left ? 0 : i==right ? 1 : 2; }
5644
- };
5645
-
5646
- void g(X* p) {
5647
- direction d; // error: direction not in scope
5648
- int i;
5649
- i = p->f(left); // error: left not in scope
5650
- i = p->f(X::right); // OK
5651
- i = p->f(p->left); // OK
5652
- // ...
5653
- }
5654
- ```
5655
-
5656
- — *end example*]
5657
-
5658
  ### The `using enum` declaration <a id="enum.udecl">[[enum.udecl]]</a>
5659
 
5660
  ``` bnf
5661
  using-enum-declaration:
5662
- 'using' elaborated-enum-specifier ';'
5663
  ```
5664
 
5665
- The *elaborated-enum-specifier* shall not name a dependent type and the
5666
- type shall have a reachable *enum-specifier*.
 
 
 
 
 
 
 
 
5667
 
5668
- A *using-enum-declaration* introduces the enumerator names of the named
5669
- enumeration as if by a *using-declaration* for each enumerator.
5670
 
5671
  [*Note 1*:
5672
 
5673
- A *using-enum-declaration* in class scope adds the enumerators of the
5674
- named enumeration as members to the scope. This means they are
5675
- accessible for member lookup.
5676
 
5677
  [*Example 1*:
5678
 
5679
  ``` cpp
5680
  enum class fruit { orange, apple };
@@ -5712,21 +5872,23 @@ void f() {
5712
 
5713
  — *end note*]
5714
 
5715
  ## Namespaces <a id="basic.namespace">[[basic.namespace]]</a>
5716
 
5717
- A namespace is an optionally-named declarative region. The name of a
5718
- namespace can be used to access entities declared in that namespace;
5719
- that is, the members of the namespace. Unlike other declarative regions,
5720
- the definition of a namespace can be split over several parts of one or
5721
- more translation units.
5722
 
5723
- [*Note 1*: A namespace name with external linkage is exported if any of
5724
- its *namespace-definition*s is exported, or if it contains any
 
 
 
 
 
 
5725
  *export-declaration*s [[module.interface]]. A namespace is never
5726
- attached to a module, and never has module linkage even if it is not
5727
- exported. — *end note*]
5728
 
5729
  [*Example 1*:
5730
 
5731
  ``` cpp
5732
  export module M;
@@ -5735,15 +5897,21 @@ export namespace N2 {} // N2 is exported
5735
  namespace N3 { export int n; } // N3 is exported
5736
  ```
5737
 
5738
  — *end example*]
5739
 
5740
- The outermost declarative region of a translation unit is a namespace;
5741
- see  [[basic.scope.namespace]].
 
 
 
 
5742
 
5743
  ### Namespace definition <a id="namespace.def">[[namespace.def]]</a>
5744
 
 
 
5745
  ``` bnf
5746
  namespace-name:
5747
  identifier
5748
  namespace-alias
5749
  ```
@@ -5779,22 +5947,20 @@ enclosing-namespace-specifier:
5779
  ``` bnf
5780
  namespace-body:
5781
  declaration-seqₒₚₜ
5782
  ```
5783
 
5784
- Every *namespace-definition* shall appear at namespace scope
5785
  [[basic.scope.namespace]].
5786
 
5787
- In a *named-namespace-definition*, the *identifier* is the name of the
5788
- namespace. If the *identifier*, when looked up [[basic.lookup.unqual]],
5789
- refers to a *namespace-name* (but not a *namespace-alias*) that was
5790
- introduced in the namespace in which the *named-namespace-definition*
5791
- appears or that was introduced in a member of the inline namespace set
5792
- of that namespace, the *namespace-definition* *extends* the
5793
- previously-declared namespace. Otherwise, the *identifier* is introduced
5794
- as a *namespace-name* into the declarative region in which the
5795
- *named-namespace-definition* appears.
5796
 
5797
  Because a *namespace-definition* contains *declaration*s in its
5798
  *namespace-body* and a *namespace-definition* is itself a *declaration*,
5799
  it follows that *namespace-definition*s can be nested.
5800
 
@@ -5811,34 +5977,10 @@ namespace Outer {
5811
  }
5812
  ```
5813
 
5814
  — *end example*]
5815
 
5816
- The *enclosing namespaces* of a declaration are those namespaces in
5817
- which the declaration lexically appears, except for a redeclaration of a
5818
- namespace member outside its original namespace (e.g., a definition as
5819
- specified in  [[namespace.memdef]]). Such a redeclaration has the same
5820
- enclosing namespaces as the original declaration.
5821
-
5822
- [*Example 2*:
5823
-
5824
- ``` cpp
5825
- namespace Q {
5826
- namespace V {
5827
- void f(); // enclosing namespaces are the global namespace, Q, and Q::V
5828
- class C { void m(); };
5829
- }
5830
- void V::f() { // enclosing namespaces are the global namespace, Q, and Q::V
5831
- extern void h(); // ... so this declares Q::V::h
5832
- }
5833
- void V::C::m() { // enclosing namespaces are the global namespace, Q, and Q::V
5834
- }
5835
- }
5836
- ```
5837
-
5838
- — *end example*]
5839
-
5840
  If the optional initial `inline` keyword appears in a
5841
  *namespace-definition* for a particular namespace, that namespace is
5842
  declared to be an *inline namespace*. The `inline` keyword may be used
5843
  on a *namespace-definition* that extends a namespace only if it was
5844
  previously used on the *namespace-definition* that initially declared
@@ -5846,33 +5988,30 @@ the *namespace-name* for that namespace.
5846
 
5847
  The optional *attribute-specifier-seq* in a *named-namespace-definition*
5848
  appertains to the namespace being defined or extended.
5849
 
5850
  Members of an inline namespace can be used in most respects as though
5851
- they were members of the enclosing namespace. Specifically, the inline
5852
- namespace and its enclosing namespace are both added to the set of
5853
- associated namespaces used in argument-dependent lookup
5854
  [[basic.lookup.argdep]] whenever one of them is, and a *using-directive*
5855
  [[namespace.udir]] that names the inline namespace is implicitly
5856
  inserted into the enclosing namespace as for an unnamed namespace
5857
  [[namespace.unnamed]]. Furthermore, each member of the inline namespace
5858
- can subsequently be partially specialized [[temp.class.spec]],
5859
  explicitly instantiated [[temp.explicit]], or explicitly specialized
5860
  [[temp.expl.spec]] as though it were a member of the enclosing
5861
  namespace. Finally, looking up a name in the enclosing namespace via
5862
  explicit qualification [[namespace.qual]] will include members of the
5863
- inline namespace brought in by the *using-directive* even if there are
5864
- declarations of that name in the enclosing namespace.
5865
 
5866
  These properties are transitive: if a namespace `N` contains an inline
5867
  namespace `M`, which in turn contains an inline namespace `O`, then the
5868
  members of `O` can be used as though they were members of `M` or `N`.
5869
  The *inline namespace set* of `N` is the transitive closure of all
5870
- inline namespaces in `N`. The *enclosing namespace set* of `O` is the
5871
- set of namespaces consisting of the innermost non-inline namespace
5872
- enclosing an inline namespace `O`, together with any intervening inline
5873
- namespaces.
5874
 
5875
  A *nested-namespace-definition* with an *enclosing-namespace-specifier*
5876
  `E`, *identifier* `I` and *namespace-body* `B` is equivalent to
5877
 
5878
  ``` cpp
@@ -5880,11 +6019,11 @@ namespace E { \opt{inline} namespace I { B } }
5880
  ```
5881
 
5882
  where the optional `inline` is present if and only if the *identifier*
5883
  `I` is preceded by `inline`.
5884
 
5885
- [*Example 3*:
5886
 
5887
  ``` cpp
5888
  namespace A::inline B::C {
5889
  int i;
5890
  }
@@ -5943,128 +6082,10 @@ void h() {
5943
  }
5944
  ```
5945
 
5946
  — *end example*]
5947
 
5948
- #### Namespace member definitions <a id="namespace.memdef">[[namespace.memdef]]</a>
5949
-
5950
- A declaration in a namespace `N` (excluding declarations in nested
5951
- scopes) whose *declarator-id* is an *unqualified-id* [[dcl.meaning]],
5952
- whose *class-head-name* [[class.pre]] or *enum-head-name* [[dcl.enum]]
5953
- is an *identifier*, or whose *elaborated-type-specifier* is of the form
5954
- *class-key* *attribute-specifier-seq*ₒₚₜ *identifier*
5955
- [[dcl.type.elab]], or that is an *opaque-enum-declaration*, declares (or
5956
- redeclares) its *unqualified-id* or *identifier* as a member of `N`.
5957
-
5958
- [*Note 1*: An explicit instantiation [[temp.explicit]] or explicit
5959
- specialization [[temp.expl.spec]] of a template does not introduce a
5960
- name and thus may be declared using an *unqualified-id* in a member of
5961
- the enclosing namespace set, if the primary template is declared in an
5962
- inline namespace. — *end note*]
5963
-
5964
- [*Example 1*:
5965
-
5966
- ``` cpp
5967
- namespace X {
5968
- void f() { ... } // OK: introduces X::f()
5969
-
5970
- namespace M {
5971
- void g(); // OK: introduces X::M::g()
5972
- }
5973
- using M::g;
5974
- void g(); // error: conflicts with X::M::g()
5975
- }
5976
- ```
5977
-
5978
- — *end example*]
5979
-
5980
- Members of a named namespace can also be defined outside that namespace
5981
- by explicit qualification [[namespace.qual]] of the name being defined,
5982
- provided that the entity being defined was already declared in the
5983
- namespace and the definition appears after the point of declaration in a
5984
- namespace that encloses the declaration’s namespace.
5985
-
5986
- [*Example 2*:
5987
-
5988
- ``` cpp
5989
- namespace Q {
5990
- namespace V {
5991
- void f();
5992
- }
5993
- void V::f() { ... } // OK
5994
- void V::g() { ... } // error: g() is not yet a member of V
5995
- namespace V {
5996
- void g();
5997
- }
5998
- }
5999
-
6000
- namespace R {
6001
- void Q::V::g() { ... } // error: R doesn't enclose Q
6002
- }
6003
- ```
6004
-
6005
- — *end example*]
6006
-
6007
- If a friend declaration in a non-local class first declares a class,
6008
- function, class template or function template[^10] the friend is a
6009
- member of the innermost enclosing namespace. The friend declaration does
6010
- not by itself make the name visible to unqualified lookup
6011
- [[basic.lookup.unqual]] or qualified lookup [[basic.lookup.qual]].
6012
-
6013
- [*Note 2*: The name of the friend will be visible in its namespace if a
6014
- matching declaration is provided at namespace scope (either before or
6015
- after the class definition granting friendship). — *end note*]
6016
-
6017
- If a friend function or function template is called, its name may be
6018
- found by the name lookup that considers functions from namespaces and
6019
- classes associated with the types of the function arguments
6020
- [[basic.lookup.argdep]]. If the name in a friend declaration is neither
6021
- qualified nor a *template-id* and the declaration is a function or an
6022
- *elaborated-type-specifier*, the lookup to determine whether the entity
6023
- has been previously declared shall not consider any scopes outside the
6024
- innermost enclosing namespace.
6025
-
6026
- [*Note 3*: The other forms of friend declarations cannot declare a new
6027
- member of the innermost enclosing namespace and thus follow the usual
6028
- lookup rules. — *end note*]
6029
-
6030
- [*Example 3*:
6031
-
6032
- ``` cpp
6033
- // Assume f and g have not yet been declared.
6034
- void h(int);
6035
- template <class T> void f2(T);
6036
- namespace A {
6037
- class X {
6038
- friend void f(X); // A::f(X) is a friend
6039
- class Y {
6040
- friend void g(); // A::g is a friend
6041
- friend void h(int); // A::h is a friend
6042
- // ::h not considered
6043
- friend void f2<>(int); // ::f2<>(int) is a friend
6044
- };
6045
- };
6046
-
6047
- // A::f, A::g and A::h are not visible here
6048
- X x;
6049
- void g() { f(x); } // definition of A::g
6050
- void f(X) { ... } // definition of A::f
6051
- void h(int) { ... } // definition of A::h
6052
- // A::f, A::g and A::h are visible here and known to be friends
6053
- }
6054
-
6055
- using A::x;
6056
-
6057
- void h() {
6058
- A::f(x);
6059
- A::X::f(x); // error: f is not a member of A::X
6060
- A::X::Y::g(); // error: g is not a member of A::X::Y
6061
- }
6062
- ```
6063
-
6064
- — *end example*]
6065
-
6066
  ### Namespace alias <a id="namespace.alias">[[namespace.alias]]</a>
6067
 
6068
  A *namespace-alias-definition* declares an alternate name for a
6069
  namespace according to the following grammar:
6070
 
@@ -6081,35 +6102,18 @@ namespace-alias-definition:
6081
  ``` bnf
6082
  qualified-namespace-specifier:
6083
  nested-name-specifierₒₚₜ namespace-name
6084
  ```
6085
 
6086
- The *identifier* in a *namespace-alias-definition* is a synonym for the
6087
- name of the namespace denoted by the *qualified-namespace-specifier* and
6088
- becomes a *namespace-alias*.
6089
 
6090
  [*Note 1*: When looking up a *namespace-name* in a
6091
  *namespace-alias-definition*, only namespace names are considered, see 
6092
  [[basic.lookup.udir]]. — *end note*]
6093
 
6094
- In a declarative region, a *namespace-alias-definition* can be used to
6095
- redefine a *namespace-alias* declared in that declarative region to
6096
- refer only to the namespace to which it already refers.
6097
-
6098
- [*Example 1*:
6099
-
6100
- The following declarations are well-formed:
6101
-
6102
- ``` cpp
6103
- namespace Company_with_very_long_name { ... }
6104
- namespace CWVLN = Company_with_very_long_name;
6105
- namespace CWVLN = Company_with_very_long_name; // OK: duplicate
6106
- namespace CWVLN = CWVLN;
6107
- ```
6108
-
6109
- — *end example*]
6110
-
6111
  ### Using namespace directive <a id="namespace.udir">[[namespace.udir]]</a>
6112
 
6113
  ``` bnf
6114
  using-directive:
6115
  attribute-specifier-seqₒₚₜ using namespace nested-name-specifierₒₚₜ namespace-name ';'
@@ -6123,22 +6127,19 @@ only namespace names are considered, see 
6123
  [[basic.lookup.udir]]. — *end note*]
6124
 
6125
  The optional *attribute-specifier-seq* appertains to the
6126
  *using-directive*.
6127
 
6128
- A *using-directive* specifies that the names in the nominated namespace
6129
- can be used in the scope in which the *using-directive* appears after
6130
- the *using-directive*. During unqualified name lookup
6131
- [[basic.lookup.unqual]], the names appear as if they were declared in
6132
- the nearest enclosing namespace which contains both the
6133
- *using-directive* and the nominated namespace.
6134
 
6135
- [*Note 2*: In this context, “contains” means “contains directly or
6136
- indirectly”. — *end note*]
6137
-
6138
- A *using-directive* does not add any members to the declarative region
6139
- in which it appears.
6140
 
6141
  [*Example 1*:
6142
 
6143
  ``` cpp
6144
  namespace A {
@@ -6168,18 +6169,14 @@ void f4() {
6168
  }
6169
  ```
6170
 
6171
  — *end example*]
6172
 
6173
- For unqualified lookup [[basic.lookup.unqual]], the *using-directive* is
6174
- transitive: if a scope contains a *using-directive* that nominates a
6175
- second namespace that itself contains *using-directive*s, the effect is
6176
- as if the *using-directive*s from the second namespace also appeared in
6177
- the first.
6178
-
6179
- [*Note 3*: For qualified lookup, see 
6180
- [[namespace.qual]]. — *end note*]
6181
 
6182
  [*Example 2*:
6183
 
6184
  ``` cpp
6185
  namespace M {
@@ -6222,17 +6219,15 @@ namespace B {
6222
  }
6223
  ```
6224
 
6225
  — *end example*]
6226
 
6227
- If a namespace is extended [[namespace.def]] after a *using-directive*
6228
- for that namespace is given, the additional members of the extended
6229
- namespace and the members of namespaces nominated by *using-directive*s
6230
- in the extending *namespace-definition* can be used after the extending
6231
- *namespace-definition*.
6232
 
6233
- [*Note 4*:
6234
 
6235
  If name lookup finds a declaration for a name in two different
6236
  namespaces, and the declarations do not declare the same entity and do
6237
  not declare functions or function templates, the use of the name is
6238
  ill-formed [[basic.lookup]]. In particular, the name of a variable,
@@ -6253,40 +6248,37 @@ namespace B {
6253
  using namespace A;
6254
  using namespace B;
6255
 
6256
  void f() {
6257
  X(1); // error: name X found in two namespaces
6258
- g(); // OK: name g refers to the same entity
6259
- h(); // OK: overload resolution selects A::h
6260
  }
6261
  ```
6262
 
6263
  — *end note*]
6264
 
6265
- During overload resolution, all functions from the transitive search are
6266
- considered for argument matching. The set of declarations found by the
6267
- transitive search is unordered.
6268
 
6269
- [*Note 5*: In particular, the order in which namespaces were considered
6270
- and the relationships among the namespaces implied by the
6271
- *using-directive*s do not cause preference to be given to any of the
6272
- declarations found by the search. *end note*]
 
6273
 
6274
- An ambiguity exists if the best match finds two functions with the same
6275
- signature, even if one is in a namespace reachable through
6276
- *using-directive*s in the namespace of the other.[^11]
6277
 
6278
  [*Example 3*:
6279
 
6280
  ``` cpp
6281
  namespace D {
6282
  int d1;
6283
  void f(char);
6284
  }
6285
  using namespace D;
6286
 
6287
- int d1; // OK: no conflict with D::d1
6288
 
6289
  namespace E {
6290
  int e;
6291
  void f(int);
6292
  }
@@ -6299,14 +6291,14 @@ namespace D { // namespace extension
6299
 
6300
  void f() {
6301
  d1++; // error: ambiguous ::d1 or D::d1?
6302
  ::d1++; // OK
6303
  D::d1++; // OK
6304
- d2++; // OK: D::d2
6305
- e++; // OK: E::e
6306
  f(1); // error: ambiguous: D::f(int) or E::f(int)?
6307
- f('a'); // OK: D::f(char)
6308
  }
6309
  ```
6310
 
6311
  — *end example*]
6312
 
@@ -6326,57 +6318,43 @@ using-declarator-list:
6326
  ``` bnf
6327
  using-declarator:
6328
  typenameₒₚₜ nested-name-specifier unqualified-id
6329
  ```
6330
 
6331
- Each *using-declarator* in a *using-declaration* [^12] introduces a set
6332
- of declarations into the declarative region in which the
6333
- *using-declaration* appears. The set of declarations introduced by the
6334
- *using-declarator* is found by performing qualified name lookup (
6335
- [[basic.lookup.qual]], [[class.member.lookup]]) for the name in the
6336
- *using-declarator*, excluding functions that are hidden as described
6337
- below. If the *using-declarator* does not name a constructor, the
6338
- *unqualified-id* is declared in the declarative region in which the
6339
- *using-declaration* appears as a synonym for each declaration introduced
6340
- by the *using-declarator*.
6341
 
6342
- [*Note 1*: Only the specified name is so declared; specifying an
6343
- enumeration name in a *using-declaration* does not declare its
6344
- enumerators in the *using-declaration*'s declarative
6345
- region. *end note*]
 
 
 
 
 
 
 
 
6346
 
6347
  If the *using-declarator* names a constructor, it declares that the
6348
- class *inherits* the set of constructor declarations introduced by the
6349
- *using-declarator* from the nominated base class.
6350
-
6351
- Every *using-declaration* is a *declaration* and a *member-declaration*
6352
- and can therefore be used in a class definition.
6353
-
6354
- [*Example 1*:
6355
-
6356
- ``` cpp
6357
- struct B {
6358
- void f(char);
6359
- void g(char);
6360
- enum E { e };
6361
- union { int x; };
6362
- };
6363
-
6364
- struct D : B {
6365
- using B::f;
6366
- void f(int) { f('c'); } // calls B::f(char)
6367
- void g(int) { g('c'); } // recursively calls D::g(int)
6368
- };
6369
- ```
6370
-
6371
- — *end example*]
6372
 
6373
  In a *using-declaration* used as a *member-declaration*, each
6374
  *using-declarator* shall either name an enumerator or have a
6375
- *nested-name-specifier* naming a base class of the class being defined.
 
6376
 
6377
- [*Example 2*:
6378
 
6379
  ``` cpp
6380
  enum class button { up, down };
6381
  struct S {
6382
  using button::up;
@@ -6385,60 +6363,59 @@ struct S {
6385
  ```
6386
 
6387
  — *end example*]
6388
 
6389
  If a *using-declarator* names a constructor, its *nested-name-specifier*
6390
- shall name a direct base class of the class being defined.
 
 
6391
 
6392
- [*Example 3*:
6393
 
6394
  ``` cpp
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6395
  template <typename... bases>
6396
  struct X : bases... {
6397
- using bases::g...;
6398
- };
6399
-
6400
- X<B, D> x; // OK: B::g and D::g introduced
6401
- ```
6402
-
6403
- — *end example*]
6404
-
6405
- [*Example 4*:
6406
-
6407
- ``` cpp
6408
- class C {
6409
- int g();
6410
- };
6411
-
6412
- class D2 : public B {
6413
- using B::f; // OK: B is a base of D2
6414
- using B::e; // OK: e is an enumerator of base B
6415
- using B::x; // OK: x is a union member of base B
6416
- using C::g; // error: C isn't a base of D2
6417
  };
 
6418
  ```
6419
 
6420
  — *end example*]
6421
 
6422
  [*Note 2*: Since destructors do not have names, a *using-declaration*
6423
- cannot refer to a destructor for a base class. Since specializations of
6424
- member templates for conversion functions are not found by name lookup,
6425
- they are not considered when a *using-declaration* specifies a
6426
- conversion function [[temp.mem]]. — *end note*]
6427
 
6428
  If a constructor or assignment operator brought from a base class into a
6429
  derived class has the signature of a copy/move constructor or assignment
6430
- operator for the derived class ([[class.copy.ctor]],
6431
- [[class.copy.assign]]), the *using-declaration* does not by itself
6432
- suppress the implicit declaration of the derived class member; the
6433
- member from the base class is hidden or overridden by the
6434
  implicitly-declared copy/move constructor or assignment operator of the
6435
  derived class, as described below.
6436
 
6437
  A *using-declaration* shall not name a *template-id*.
6438
 
6439
- [*Example 5*:
6440
 
6441
  ``` cpp
6442
  struct A {
6443
  template <class T> void f(T);
6444
  template <class T> struct X { };
@@ -6454,11 +6431,11 @@ struct B : A {
6454
  A *using-declaration* shall not name a namespace.
6455
 
6456
  A *using-declaration* that names a class member other than an enumerator
6457
  shall be a *member-declaration*.
6458
 
6459
- [*Example 6*:
6460
 
6461
  ``` cpp
6462
  struct X {
6463
  int i;
6464
  static int s;
@@ -6470,71 +6447,21 @@ void f() {
6470
  }
6471
  ```
6472
 
6473
  — *end example*]
6474
 
6475
- Members declared by a *using-declaration* can be referred to by explicit
6476
- qualification just like other member names [[namespace.qual]].
6477
 
6478
- [*Example 7*:
 
 
 
 
 
6479
 
6480
- ``` cpp
6481
- void f();
6482
-
6483
- namespace A {
6484
- void g();
6485
- }
6486
-
6487
- namespace X {
6488
- using ::f; // global f
6489
- using A::g; // A's g
6490
- }
6491
-
6492
- void h()
6493
- {
6494
- X::f(); // calls ::f
6495
- X::g(); // calls A::g
6496
- }
6497
- ```
6498
-
6499
- — *end example*]
6500
-
6501
- A *using-declaration* is a *declaration* and can therefore be used
6502
- repeatedly where (and only where) multiple declarations are allowed.
6503
-
6504
- [*Example 8*:
6505
-
6506
- ``` cpp
6507
- namespace A {
6508
- int i;
6509
- }
6510
-
6511
- namespace A1 {
6512
- using A::i, A::i; // OK: double declaration
6513
- }
6514
-
6515
- struct B {
6516
- int i;
6517
- };
6518
-
6519
- struct X : B {
6520
- using B::i, B::i; // error: double member declaration
6521
- };
6522
- ```
6523
-
6524
- — *end example*]
6525
-
6526
- [*Note 3*: For a *using-declaration* whose *nested-name-specifier*
6527
- names a namespace, members added to the namespace after the
6528
- *using-declaration* are not in the set of introduced declarations, so
6529
- they are not considered when a use of the name is made. Thus, additional
6530
- overloads added after the *using-declaration* are ignored, but default
6531
- function arguments [[dcl.fct.default]], default template arguments
6532
- [[temp.param]], and template specializations ([[temp.class.spec]],
6533
- [[temp.expl.spec]]) are considered. — *end note*]
6534
-
6535
- [*Example 9*:
6536
 
6537
  ``` cpp
6538
  namespace A {
6539
  void f(int);
6540
  }
@@ -6554,107 +6481,70 @@ void bar() {
6554
  }
6555
  ```
6556
 
6557
  — *end example*]
6558
 
6559
- [*Note 4*: Partial specializations of class templates are found by
6560
- looking up the primary class template and then considering all partial
6561
- specializations of that template. If a *using-declaration* names a class
6562
- template, partial specializations introduced after the
6563
- *using-declaration* are effectively visible because the primary template
6564
- is visible [[temp.class.spec]]. *end note*]
 
6565
 
6566
- Since a *using-declaration* is a declaration, the restrictions on
6567
- declarations of the same name in the same declarative region
6568
- [[basic.scope]] also apply to *using-declaration*s.
6569
 
6570
- [*Example 10*:
6571
 
6572
  ``` cpp
6573
  namespace A {
6574
  int x;
 
 
 
6575
  }
6576
 
6577
  namespace B {
6578
  int i;
6579
  struct g { };
6580
  struct x { };
6581
  void f(int);
6582
  void f(double);
6583
- void g(char); // OK: hides struct g
6584
  }
6585
 
6586
  void func() {
6587
  int i;
6588
- using B::i; // error: i declared twice
6589
  void f(char);
6590
- using B::f; // OK: each f is a function
 
 
 
6591
  f(3.5); // calls B::f(double)
6592
  using B::g;
6593
  g('a'); // calls B::g(char)
6594
  struct g g1; // g1 has class type B::g
 
 
 
6595
  using B::x;
6596
- using A::x; // OK: hides struct B::x
6597
  x = 99; // assigns to A::x
6598
  struct x x1; // x1 has class type B::x
6599
  }
6600
  ```
6601
 
6602
  — *end example*]
6603
 
6604
- If a function declaration in namespace scope or block scope has the same
6605
- name and the same parameter-type-list [[dcl.fct]] as a function
6606
- introduced by a *using-declaration*, and the declarations do not declare
6607
- the same function, the program is ill-formed. If a function template
6608
- declaration in namespace scope has the same name, parameter-type-list,
6609
- trailing *requires-clause* (if any), return type, and *template-head*,
6610
- as a function template introduced by a *using-declaration*, the program
6611
- is ill-formed.
6612
 
6613
- [*Note 5*:
6614
-
6615
- Two *using-declaration*s may introduce functions with the same name and
6616
- the same parameter-type-list. If, for a call to an unqualified function
6617
- name, function overload resolution selects the functions introduced by
6618
- such *using-declaration*s, the function call is ill-formed.
6619
-
6620
- [*Example 11*:
6621
-
6622
- ``` cpp
6623
- namespace B {
6624
- void f(int);
6625
- void f(double);
6626
- }
6627
- namespace C {
6628
- void f(int);
6629
- void f(double);
6630
- void f(char);
6631
- }
6632
-
6633
- void h() {
6634
- using B::f; // B::f(int) and B::f(double)
6635
- using C::f; // C::f(int), C::f(double), and C::f(char)
6636
- f('h'); // calls C::f(char)
6637
- f(1); // error: ambiguous: B::f(int) or C::f(int)?
6638
- void f(int); // error: f(int) conflicts with C::f(int) and B::f(int)
6639
- }
6640
- ```
6641
-
6642
- — *end example*]
6643
-
6644
- — *end note*]
6645
-
6646
- When a *using-declarator* brings declarations from a base class into a
6647
- derived class, member functions and member function templates in the
6648
- derived class override and/or hide member functions and member function
6649
- templates with the same name, parameter-type-list [[dcl.fct]], trailing
6650
- *requires-clause* (if any), cv-qualification, and *ref-qualifier* (if
6651
- any), in a base class (rather than conflicting). Such hidden or
6652
- overridden declarations are excluded from the set of declarations
6653
- introduced by the *using-declarator*.
6654
-
6655
- [*Example 12*:
6656
 
6657
  ``` cpp
6658
  struct B {
6659
  virtual void f(int);
6660
  virtual void f(char);
@@ -6662,17 +6552,17 @@ struct B {
6662
  void h(int);
6663
  };
6664
 
6665
  struct D : B {
6666
  using B::f;
6667
- void f(int); // OK: D::f(int) overrides B::f(int);
6668
 
6669
  using B::g;
6670
  void g(char); // OK
6671
 
6672
  using B::h;
6673
- void h(int); // OK: D::h(int) hides B::h(int)
6674
  };
6675
 
6676
  void k(D* p)
6677
  {
6678
  p->f(1); // calls D::f(int)
@@ -6696,58 +6586,51 @@ struct D1 : B1, B2 {
6696
  D1 d1(0); // error: ambiguous
6697
 
6698
  struct D2 : B1, B2 {
6699
  using B1::B1;
6700
  using B2::B2;
6701
- D2(int); // OK: D2::D2(int) hides B1::B1(int) and B2::B2(int)
6702
  };
6703
  D2 d2(0); // calls D2::D2(int)
6704
  ```
6705
 
6706
  — *end example*]
6707
 
6708
- [*Note 6*: For the purpose of forming a set of candidates during
6709
- overload resolution, the functions that are introduced by a
6710
- *using-declaration* into a derived class are treated as though they were
6711
- members of the derived class [[class.member.lookup]]. In particular, the
6712
- implicit object parameter is treated as if it were a reference to the
6713
- derived class rather than to the base class [[over.match.funcs]]. This
6714
- has no effect on the type of the function, and in all other respects the
6715
- function remains a member of the base class. — *end note*]
6716
 
6717
- Constructors that are introduced by a *using-declaration* are treated as
6718
  though they were constructors of the derived class when looking up the
6719
  constructors of the derived class [[class.qual]] or forming a set of
6720
- overload candidates ([[over.match.ctor]], [[over.match.copy]],
6721
- [[over.match.list]]).
6722
 
6723
- [*Note 7*: If such a constructor is selected to perform the
6724
  initialization of an object of class type, all subobjects other than the
6725
  base class from which the constructor originated are implicitly
6726
  initialized [[class.inhctor.init]]. A constructor of a derived class is
6727
  sometimes preferred to a constructor of a base class if they would
6728
  otherwise be ambiguous [[over.match.best]]. — *end note*]
6729
 
6730
- In a *using-declarator* that does not name a constructor, all members of
6731
- the set of introduced declarations shall be accessible. In a
6732
- *using-declarator* that names a constructor, no access check is
6733
- performed. In particular, if a derived class uses a *using-declarator*
6734
- to access a member of a base class, the member name shall be accessible.
6735
- If the name is that of an overloaded member function, then all functions
6736
- named shall be accessible. The base class members mentioned by a
6737
- *using-declarator* shall be visible in the scope of at least one of the
6738
- direct base classes of the class where the *using-declarator* is
6739
- specified.
6740
 
6741
- [*Note 8*:
6742
 
6743
  Because a *using-declarator* designates a base class member (and not a
6744
  member subobject or a member function of a base class subobject), a
6745
  *using-declarator* cannot be used to resolve inherited member
6746
  ambiguities.
6747
 
6748
- [*Example 13*:
6749
 
6750
  ``` cpp
6751
  struct A { int x(); };
6752
  struct B : A { };
6753
  struct C : A {
@@ -6766,18 +6649,17 @@ int f(D* d) {
6766
 
6767
  — *end example*]
6768
 
6769
  — *end note*]
6770
 
6771
- A synonym created by a *using-declaration* has the usual accessibility
6772
- for a *member-declaration*. A *using-declarator* that names a
6773
- constructor does not create a synonym; instead, the additional
6774
- constructors are accessible if they would be accessible when used to
6775
- construct an object of the corresponding base class, and the
6776
- accessibility of the *using-declaration* is ignored.
6777
 
6778
- [*Example 14*:
6779
 
6780
  ``` cpp
6781
  class A {
6782
  private:
6783
  void f(char);
@@ -6794,14 +6676,10 @@ public:
6794
  };
6795
  ```
6796
 
6797
  — *end example*]
6798
 
6799
- If a *using-declarator* uses the keyword `typename` and specifies a
6800
- dependent name [[temp.dep]], the name introduced by the
6801
- *using-declaration* is treated as a *typedef-name* [[dcl.typedef]].
6802
-
6803
  ## The `asm` declaration <a id="dcl.asm">[[dcl.asm]]</a>
6804
 
6805
  An `asm` declaration has the form
6806
 
6807
  ``` bnf
@@ -6816,32 +6694,32 @@ The `asm` declaration is conditionally-supported; its meaning is
6816
  [*Note 1*: Typically it is used to pass information through the
6817
  implementation to an assembler. — *end note*]
6818
 
6819
  ## Linkage specifications <a id="dcl.link">[[dcl.link]]</a>
6820
 
6821
- All function types, function names with external linkage, and variable
6822
- names with external linkage have a *language linkage*.
6823
 
6824
  [*Note 1*: Some of the properties associated with an entity with
6825
  language linkage are specific to each implementation and are not
6826
- described here. For example, a particular language linkage may be
6827
  associated with a particular form of representing names of objects and
6828
  functions with external linkage, or with a particular calling
6829
  convention, etc. — *end note*]
6830
 
6831
- The default language linkage of all function types, function names, and
6832
- variable names is C++ language linkage. Two function types with
6833
- different language linkages are distinct types even if they are
6834
- otherwise identical.
6835
 
6836
  Linkage [[basic.link]] between C++ and non-C++ code fragments can be
6837
  achieved using a *linkage-specification*:
6838
 
6839
  ``` bnf
6840
  linkage-specification:
6841
  extern string-literal '{' declaration-seqₒₚₜ '}'
6842
- extern string-literal declaration
6843
  ```
6844
 
6845
  The *string-literal* indicates the required language linkage. This
6846
  document specifies the semantics for the *string-literal*s `"C"` and
6847
  `"C++"`. Use of a *string-literal* other than `"C"` or `"C++"` is
@@ -6849,143 +6727,119 @@ conditionally-supported, with *implementation-defined* semantics.
6849
 
6850
  [*Note 2*: Therefore, a linkage-specification with a *string-literal*
6851
  that is unknown to the implementation requires a
6852
  diagnostic. — *end note*]
6853
 
6854
- [*Note 3*: It is recommended that the spelling of the *string-literal*
6855
- be taken from the document defining that language. For example, `Ada`
6856
- (not `ADA`) and `Fortran` or `FORTRAN`, depending on the
6857
- vintage. — *end note*]
6858
 
6859
- Every implementation shall provide for linkage to functions written in
6860
- the C programming language, `"C"`, and linkage to C++ functions,
6861
- `"C++"`.
6862
 
6863
  [*Example 1*:
6864
 
6865
  ``` cpp
6866
- complex sqrt(complex); // C++{} linkage by default
6867
  extern "C" {
6868
- double sqrt(double); // C linkage
6869
  }
6870
  ```
6871
 
6872
  — *end example*]
6873
 
6874
- A *module-import-declaration* shall not be directly contained in a
6875
- *linkage-specification*. A *module-import-declaration* appearing in a
6876
- linkage specification with other than C++ language linkage is
6877
- conditionally-supported with *implementation-defined* semantics.
6878
 
6879
  Linkage specifications nest. When linkage specifications nest, the
6880
- innermost one determines the language linkage. A linkage specification
6881
- does not establish a scope. A *linkage-specification* shall occur only
6882
- in namespace scope [[basic.scope]]. In a *linkage-specification*, the
6883
- specified language linkage applies to the function types of all function
6884
- declarators, function names with external linkage, and variable names
6885
- with external linkage declared within the *linkage-specification*.
 
 
 
6886
 
6887
  [*Example 2*:
6888
 
6889
  ``` cpp
6890
- extern "C" // the name f1 and its function type have C language linkage;
6891
  void f1(void(*pf)(int)); // pf is a pointer to a C function
6892
 
6893
  extern "C" typedef void FUNC();
6894
- FUNC f2; // the name f2 has C++{} language linkage and the
6895
- // function's type has C language linkage
6896
 
6897
- extern "C" FUNC f3; // the name of function f3 and the function's type have C language linkage
6898
 
6899
- void (*pf2)(FUNC*); // the name of the variable pf2 has C++{} linkage and the type
6900
- // of pf2 is ``pointer to C++{} function that takes one parameter of type
6901
  // pointer to C function''
6902
  extern "C" {
6903
- static void f4(); // the name of the function f4 has internal linkage (not C language linkage)
6904
- // and the function's type has C language linkage.
6905
  }
6906
 
6907
  extern "C" void f5() {
6908
- extern void f4(); // OK: Name linkage (internal) and function type linkage (C language linkage)
6909
  // obtained from previous declaration.
6910
  }
6911
 
6912
- extern void f4(); // OK: Name linkage (internal) and function type linkage (C language linkage)
6913
  // obtained from previous declaration.
6914
 
6915
  void f6() {
6916
- extern void f4(); // OK: Name linkage (internal) and function type linkage (C language linkage)
6917
  // obtained from previous declaration.
6918
  }
6919
  ```
6920
 
6921
  — *end example*]
6922
 
6923
  A C language linkage is ignored in determining the language linkage of
6924
- the names of class members and the function type of class member
6925
- functions.
6926
 
6927
  [*Example 3*:
6928
 
6929
  ``` cpp
6930
  extern "C" typedef void FUNC_c();
6931
 
6932
  class C {
6933
- void mf1(FUNC_c*); // the name of the function mf1 and the member function's type have
6934
- // C++{} language linkage; the parameter has type ``pointer to C function''
6935
 
6936
- FUNC_c mf2; // the name of the function mf2 and the member function's type have
6937
- // C++{} language linkage
6938
 
6939
- static FUNC_c* q; // the name of the data member q has C++{} language linkage and
6940
- // the data member's type is ``pointer to C function''
6941
  };
6942
 
6943
  extern "C" {
6944
  class X {
6945
- void mf(); // the name of the function mf and the member function's type have
6946
- // C++{} language linkage
6947
- void mf2(void(*)()); // the name of the function mf2 has C++{} language linkage;
6948
  // the parameter has type ``pointer to C function''
6949
  };
6950
  }
6951
  ```
6952
 
6953
  — *end example*]
6954
 
6955
- If two declarations declare functions with the same name and
6956
- parameter-type-list [[dcl.fct]] to be members of the same namespace or
6957
- declare objects with the same name to be members of the same namespace
6958
- and the declarations give the names different language linkages, the
6959
- program is ill-formed; no diagnostic is required if the declarations
6960
- appear in different translation units. Except for functions with C++
6961
- linkage, a function declaration without a linkage specification shall
6962
- not precede the first linkage specification for that function. A
6963
- function can be declared without a linkage specification after an
6964
- explicit linkage specification has been seen; the linkage explicitly
6965
- specified in the earlier declaration is not affected by such a function
6966
- declaration.
6967
 
6968
- At most one function with a particular name can have C language linkage.
6969
- Two declarations for a function with C language linkage with the same
6970
- function name (ignoring the namespace names that qualify it) that appear
6971
- in different namespace scopes refer to the same function. Two
6972
- declarations for a variable with C language linkage with the same name
6973
- (ignoring the namespace names that qualify it) that appear in different
6974
- namespace scopes refer to the same variable. An entity with C language
6975
- linkage shall not be declared with the same name as a variable in global
6976
- scope, unless both declarations denote the same entity; no diagnostic is
6977
- required if the declarations appear in different translation units. A
6978
- variable with C language linkage shall not be declared with the same
6979
- name as a function with C language linkage (ignoring the namespace names
6980
- that qualify the respective names); no diagnostic is required if the
6981
- declarations appear in different translation units.
6982
-
6983
- [*Note 4*: Only one definition for an entity with a given name with C
6984
- language linkage may appear in the program (see  [[basic.def.odr]]);
6985
- this implies that such an entity must not be defined in more than one
6986
- namespace scope. — *end note*]
6987
 
6988
  [*Example 4*:
6989
 
6990
  ``` cpp
6991
  int x;
@@ -7025,11 +6879,11 @@ extern "C" {
7025
  extern "C" static void g(); // error
7026
  ```
7027
 
7028
  — *end example*]
7029
 
7030
- [*Note 5*: Because the language linkage is part of a function type,
7031
  when indirecting through a pointer to C function, the function to which
7032
  the resulting lvalue refers is considered a C function. — *end note*]
7033
 
7034
  Linkage from C++ to objects defined in other languages and to objects
7035
  defined in C++ from other languages is *implementation-defined* and
@@ -7152,39 +7006,53 @@ contained in an *attribute-token*, it is considered an identifier. No
7152
  name lookup [[basic.lookup]] is performed on any of the identifiers
7153
  contained in an *attribute-token*. The *attribute-token* determines
7154
  additional requirements on the *attribute-argument-clause* (if any).
7155
 
7156
  Each *attribute-specifier-seq* is said to *appertain* to some entity or
7157
- statement, identified by the syntactic context where it appears (
7158
- [[stmt.stmt]], [[dcl.dcl]], [[dcl.decl]]). If an
7159
  *attribute-specifier-seq* that appertains to some entity or statement
7160
  contains an *attribute* or *alignment-specifier* that is not allowed to
7161
  apply to that entity or statement, the program is ill-formed. If an
7162
  *attribute-specifier-seq* appertains to a friend declaration
7163
  [[class.friend]], that declaration shall be a definition.
7164
 
7165
  [*Note 3*: An *attribute-specifier-seq* cannot appeartain to an
7166
  explicit instantiation [[temp.explicit]]. — *end note*]
7167
 
7168
  For an *attribute-token* (including an *attribute-scoped-token*) not
7169
- specified in this document, the behavior is *implementation-defined*.
7170
- Any *attribute-token* that is not recognized by the implementation is
7171
- ignored. An *attribute-token* is reserved for future standardization if
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7172
 
7173
  - it is not an *attribute-scoped-token* and is not specified in this
7174
  document, or
7175
  - it is an *attribute-scoped-token* and its *attribute-namespace* is
7176
  `std` followed by zero or more digits.
7177
 
7178
- [*Note 4*: Each implementation should choose a distinctive name for the
7179
- *attribute-namespace* in an *attribute-scoped-token*. — *end note*]
7180
 
7181
  Two consecutive left square bracket tokens shall appear only when
7182
  introducing an *attribute-specifier* or within the *balanced-token-seq*
7183
  of an *attribute-argument-clause*.
7184
 
7185
- [*Note 5*: If two consecutive left square brackets appear where an
7186
  *attribute-specifier* is not allowed, the program is ill-formed even if
7187
  the brackets match an alternative grammar production. — *end note*]
7188
 
7189
  [*Example 2*:
7190
 
@@ -7289,23 +7157,58 @@ alignas(float)
7289
  extern unsigned char c[sizeof(double)]; // error: different alignment in declaration
7290
  ```
7291
 
7292
  — *end example*]
7293
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7294
  ### Carries dependency attribute <a id="dcl.attr.depend">[[dcl.attr.depend]]</a>
7295
 
7296
  The *attribute-token* `carries_dependency` specifies dependency
7297
- propagation into and out of functions. It shall appear at most once in
7298
- each *attribute-list* and no *attribute-argument-clause* shall be
7299
- present. The attribute may be applied to the *declarator-id* of a
7300
- *parameter-declaration* in a function declaration or lambda, in which
7301
- case it specifies that the initialization of the parameter carries a
7302
- dependency to [[intro.multithread]] each lvalue-to-rvalue conversion
7303
- [[conv.lval]] of that object. The attribute may also be applied to the
7304
- *declarator-id* of a function declaration, in which case it specifies
7305
- that the return value, if any, carries a dependency to the evaluation of
7306
- the function call expression.
7307
 
7308
  The first declaration of a function shall specify the
7309
  `carries_dependency` attribute for its *declarator-id* if any
7310
  declaration of the function specifies the `carries_dependency`
7311
  attribute. Furthermore, the first declaration of a function shall
@@ -7317,11 +7220,11 @@ declaration in one translation unit and the same function or one of its
7317
  parameters is declared without the `carries_dependency` attribute in its
7318
  first declaration in another translation unit, the program is
7319
  ill-formed, no diagnostic required.
7320
 
7321
  [*Note 1*: The `carries_dependency` attribute does not change the
7322
- meaning of the program, but may result in generation of more efficient
7323
  code. — *end note*]
7324
 
7325
  [*Example 1*:
7326
 
7327
  ``` cpp
@@ -7373,28 +7276,28 @@ The *attribute-token* `deprecated` can be used to mark names and
7373
  entities whose use is still allowed, but is discouraged for some reason.
7374
 
7375
  [*Note 1*: In particular, `deprecated` is appropriate for names and
7376
  entities that are deemed obsolescent or unsafe. — *end note*]
7377
 
7378
- It shall appear at most once in each *attribute-list*. An
7379
- *attribute-argument-clause* may be present and, if present, it shall
7380
  have the form:
7381
 
7382
  ``` bnf
7383
  '(' string-literal ')'
7384
  ```
7385
 
7386
- [*Note 2*: The *string-literal* in the *attribute-argument-clause*
7387
- could be used to explain the rationale for deprecation and/or to suggest
7388
- a replacing entity. — *end note*]
7389
 
7390
  The attribute may be applied to the declaration of a class, a
7391
  *typedef-name*, a variable, a non-static data member, a function, a
7392
- namespace, an enumeration, an enumerator, or a template specialization.
 
7393
 
7394
- A name or entity declared without the `deprecated` attribute can later
7395
- be redeclared with the attribute and vice-versa.
7396
 
7397
  [*Note 3*: Thus, an entity initially declared without the attribute can
7398
  be marked as deprecated by a subsequent redeclaration. However, after an
7399
  entity is marked as deprecated, later redeclarations do not un-deprecate
7400
  the entity. — *end note*]
@@ -7411,21 +7314,20 @@ provided within the *attribute-argument-clause* of any `deprecated`
7411
  attribute applied to the name or entity.
7412
 
7413
  ### Fallthrough attribute <a id="dcl.attr.fallthrough">[[dcl.attr.fallthrough]]</a>
7414
 
7415
  The *attribute-token* `fallthrough` may be applied to a null statement
7416
- [[stmt.expr]]; such a statement is a fallthrough statement. The
7417
- *attribute-token* `fallthrough` shall appear at most once in each
7418
- *attribute-list* and no *attribute-argument-clause* shall be present. A
7419
- fallthrough statement may only appear within an enclosing `switch`
7420
- statement [[stmt.switch]]. The next statement that would be executed
7421
- after a fallthrough statement shall be a labeled statement whose label
7422
- is a case label or default label for the same `switch` statement and, if
7423
- the fallthrough statement is contained in an iteration statement, the
7424
- next statement shall be part of the same execution of the substatement
7425
- of the innermost enclosing iteration statement. The program is
7426
- ill-formed if there is no such statement.
7427
 
7428
  *Recommended practice:* The use of a fallthrough statement should
7429
  suppress a warning that an implementation might otherwise issue for a
7430
  case or default label that is reachable from another case or default
7431
  label along some path of execution. Implementations should issue a
@@ -7465,15 +7367,14 @@ void f(int n) {
7465
  — *end example*]
7466
 
7467
  ### Likelihood attributes <a id="dcl.attr.likelihood">[[dcl.attr.likelihood]]</a>
7468
 
7469
  The *attribute-token*s `likely` and `unlikely` may be applied to labels
7470
- or statements. The *attribute-token*s `likely` and `unlikely` shall
7471
- appear at most once in each *attribute-list* and no
7472
- *attribute-argument-clause* shall be present. The *attribute-token*
7473
- `likely` shall not appear in an *attribute-specifier-seq* that contains
7474
- the *attribute-token* `unlikely`.
7475
 
7476
  *Recommended practice:* The use of the `likely` attribute is intended to
7477
  allow implementations to optimize for the case where paths of execution
7478
  including it are arbitrarily more likely than any alternative path of
7479
  execution that does not include such an attribute on a statement or
@@ -7513,12 +7414,12 @@ int f(int n) {
7513
  — *end example*]
7514
 
7515
  ### Maybe unused attribute <a id="dcl.attr.unused">[[dcl.attr.unused]]</a>
7516
 
7517
  The *attribute-token* `maybe_unused` indicates that a name or entity is
7518
- possibly intentionally unused. It shall appear at most once in each
7519
- *attribute-list* and no *attribute-argument-clause* shall be present.
7520
 
7521
  The attribute may be applied to the declaration of a class, a
7522
  *typedef-name*, a variable (including a structured binding declaration),
7523
  a non-static data member, a function, an enumeration, or an enumerator.
7524
 
@@ -7548,13 +7449,12 @@ Implementations should not warn that `b` is unused, whether or not
7548
 
7549
  — *end example*]
7550
 
7551
  ### Nodiscard attribute <a id="dcl.attr.nodiscard">[[dcl.attr.nodiscard]]</a>
7552
 
7553
- The *attribute-token* `nodiscard` may be applied to the *declarator-id*
7554
- in a function declaration or to the declaration of a class or
7555
- enumeration. It shall appear at most once in each *attribute-list*. An
7556
  *attribute-argument-clause* may be present and, if present, shall have
7557
  the form:
7558
 
7559
  ``` bnf
7560
  '(' string-literal ')'
@@ -7577,14 +7477,15 @@ type marked `nodiscard` in a reachable declaration. A *nodiscard call*
7577
  is either
7578
 
7579
  - a function call expression [[expr.call]] that calls a function
7580
  declared `nodiscard` in a reachable declaration or whose return type
7581
  is a nodiscard type, or
7582
- - an explicit type conversion ([[expr.type.conv]],
7583
- [[expr.static.cast]], [[expr.cast]]) that constructs an object through
7584
- a constructor declared `nodiscard` in a reachable declaration, or that
7585
- initializes an object of a nodiscard type.
 
7586
 
7587
  *Recommended practice:* Appearance of a nodiscard call as a
7588
  potentially-evaluated discarded-value expression [[expr.prop]] is
7589
  discouraged unless explicitly cast to `void`. Implementations should
7590
  issue a warning in such cases.
@@ -7626,13 +7527,12 @@ void f() { foo(); } // warning not encouraged: not a nodiscard call,
7626
  — *end example*]
7627
 
7628
  ### Noreturn attribute <a id="dcl.attr.noreturn">[[dcl.attr.noreturn]]</a>
7629
 
7630
  The *attribute-token* `noreturn` specifies that a function does not
7631
- return. It shall appear at most once in each *attribute-list* and no
7632
- *attribute-argument-clause* shall be present. The attribute may be
7633
- applied to the *declarator-id* in a function declaration. The first
7634
  declaration of a function shall specify the `noreturn` attribute if any
7635
  declaration of that function specifies the `noreturn` attribute. If a
7636
  function is declared with the `noreturn` attribute in one translation
7637
  unit and the same function is declared without the `noreturn` attribute
7638
  in another translation unit, the program is ill-formed, no diagnostic
@@ -7664,12 +7564,11 @@ function marked `[[noreturn]]` might return.
7664
  — *end example*]
7665
 
7666
  ### No unique address attribute <a id="dcl.attr.nouniqueaddr">[[dcl.attr.nouniqueaddr]]</a>
7667
 
7668
  The *attribute-token* `no_unique_address` specifies that a non-static
7669
- data member is a potentially-overlapping subobject [[intro.object]]. It
7670
- shall appear at most once in each *attribute-list* and no
7671
  *attribute-argument-clause* shall be present. The attribute may
7672
  appertain to a non-static data member other than a bit-field.
7673
 
7674
  [*Note 1*: The non-static data member can share the address of another
7675
  non-static data member or that of a base class, and any padding that
@@ -7705,22 +7604,19 @@ Here, `hasher`, `pred`, and `alloc` could have the same address as
7705
  [basic.fundamental]: basic.md#basic.fundamental
7706
  [basic.life]: basic.md#basic.life
7707
  [basic.link]: basic.md#basic.link
7708
  [basic.lookup]: basic.md#basic.lookup
7709
  [basic.lookup.argdep]: basic.md#basic.lookup.argdep
7710
- [basic.lookup.classref]: basic.md#basic.lookup.classref
7711
  [basic.lookup.elab]: basic.md#basic.lookup.elab
 
7712
  [basic.lookup.qual]: basic.md#basic.lookup.qual
7713
  [basic.lookup.udir]: basic.md#basic.lookup.udir
7714
  [basic.lookup.unqual]: basic.md#basic.lookup.unqual
7715
  [basic.namespace]: #basic.namespace
7716
- [basic.scope]: basic.md#basic.scope
7717
- [basic.scope.block]: basic.md#basic.scope.block
7718
- [basic.scope.declarative]: basic.md#basic.scope.declarative
7719
  [basic.scope.namespace]: basic.md#basic.scope.namespace
7720
- [basic.scope.param]: basic.md#basic.scope.param
7721
- [basic.scope.pdecl]: basic.md#basic.scope.pdecl
7722
  [basic.start]: basic.md#basic.start
7723
  [basic.start.dynamic]: basic.md#basic.start.dynamic
7724
  [basic.start.static]: basic.md#basic.start.static
7725
  [basic.stc]: basic.md#basic.stc
7726
  [basic.stc.auto]: basic.md#basic.stc.auto
@@ -7728,17 +7624,15 @@ Here, `hasher`, `pred`, and `alloc` could have the same address as
7728
  [basic.stc.dynamic.allocation]: basic.md#basic.stc.dynamic.allocation
7729
  [basic.stc.dynamic.deallocation]: basic.md#basic.stc.dynamic.deallocation
7730
  [basic.stc.static]: basic.md#basic.stc.static
7731
  [basic.stc.thread]: basic.md#basic.stc.thread
7732
  [basic.type.qualifier]: basic.md#basic.type.qualifier
7733
- [basic.types]: basic.md#basic.types
7734
  [class]: class.md#class
7735
  [class.access]: class.md#class.access
 
7736
  [class.base.init]: class.md#class.base.init
7737
  [class.bit]: class.md#class.bit
7738
- [class.compare.default]: class.md#class.compare.default
7739
- [class.conv]: class.md#class.conv
7740
  [class.conv.ctor]: class.md#class.conv.ctor
7741
  [class.conv.fct]: class.md#class.conv.fct
7742
  [class.copy.assign]: class.md#class.copy.assign
7743
  [class.copy.ctor]: class.md#class.copy.ctor
7744
  [class.copy.elision]: class.md#class.copy.elision
@@ -7748,11 +7642,12 @@ Here, `hasher`, `pred`, and `alloc` could have the same address as
7748
  [class.expl.init]: class.md#class.expl.init
7749
  [class.friend]: class.md#class.friend
7750
  [class.inhctor.init]: class.md#class.inhctor.init
7751
  [class.init]: class.md#class.init
7752
  [class.mem]: class.md#class.mem
7753
- [class.member.lookup]: class.md#class.member.lookup
 
7754
  [class.mfct]: class.md#class.mfct
7755
  [class.mi]: class.md#class.mi
7756
  [class.name]: class.md#class.name
7757
  [class.pre]: class.md#class.pre
7758
  [class.qual]: basic.md#class.qual
@@ -7763,10 +7658,12 @@ Here, `hasher`, `pred`, and `alloc` could have the same address as
7763
  [class.union.anon]: class.md#class.union.anon
7764
  [class.virtual]: class.md#class.virtual
7765
  [conv]: expr.md#conv
7766
  [conv.array]: expr.md#conv.array
7767
  [conv.func]: expr.md#conv.func
 
 
7768
  [conv.lval]: expr.md#conv.lval
7769
  [conv.prom]: expr.md#conv.prom
7770
  [conv.ptr]: expr.md#conv.ptr
7771
  [conv.qual]: expr.md#conv.qual
7772
  [conv.rval]: expr.md#conv.rval
@@ -7775,10 +7672,11 @@ Here, `hasher`, `pred`, and `alloc` could have the same address as
7775
  [dcl.align]: #dcl.align
7776
  [dcl.ambig.res]: #dcl.ambig.res
7777
  [dcl.array]: #dcl.array
7778
  [dcl.asm]: #dcl.asm
7779
  [dcl.attr]: #dcl.attr
 
7780
  [dcl.attr.depend]: #dcl.attr.depend
7781
  [dcl.attr.deprecated]: #dcl.attr.deprecated
7782
  [dcl.attr.fallthrough]: #dcl.attr.fallthrough
7783
  [dcl.attr.grammar]: #dcl.attr.grammar
7784
  [dcl.attr.likelihood]: #dcl.attr.likelihood
@@ -7788,10 +7686,11 @@ Here, `hasher`, `pred`, and `alloc` could have the same address as
7788
  [dcl.attr.unused]: #dcl.attr.unused
7789
  [dcl.constexpr]: #dcl.constexpr
7790
  [dcl.constinit]: #dcl.constinit
7791
  [dcl.dcl]: #dcl.dcl
7792
  [dcl.decl]: #dcl.decl
 
7793
  [dcl.enum]: #dcl.enum
7794
  [dcl.fct]: #dcl.fct
7795
  [dcl.fct.def]: #dcl.fct.def
7796
  [dcl.fct.def.coroutine]: #dcl.fct.def.coroutine
7797
  [dcl.fct.def.default]: #dcl.fct.def.default
@@ -7800,80 +7699,92 @@ Here, `hasher`, `pred`, and `alloc` could have the same address as
7800
  [dcl.fct.default]: #dcl.fct.default
7801
  [dcl.fct.spec]: #dcl.fct.spec
7802
  [dcl.friend]: #dcl.friend
7803
  [dcl.init]: #dcl.init
7804
  [dcl.init.aggr]: #dcl.init.aggr
 
7805
  [dcl.init.list]: #dcl.init.list
7806
  [dcl.init.ref]: #dcl.init.ref
7807
  [dcl.init.string]: #dcl.init.string
7808
  [dcl.inline]: #dcl.inline
7809
  [dcl.link]: #dcl.link
7810
  [dcl.meaning]: #dcl.meaning
 
7811
  [dcl.mptr]: #dcl.mptr
7812
  [dcl.name]: #dcl.name
7813
  [dcl.pre]: #dcl.pre
7814
  [dcl.ptr]: #dcl.ptr
7815
  [dcl.ref]: #dcl.ref
7816
  [dcl.spec]: #dcl.spec
7817
  [dcl.spec.auto]: #dcl.spec.auto
 
 
7818
  [dcl.stc]: #dcl.stc
7819
  [dcl.struct.bind]: #dcl.struct.bind
7820
  [dcl.type]: #dcl.type
7821
  [dcl.type.auto.deduct]: #dcl.type.auto.deduct
7822
  [dcl.type.class.deduct]: #dcl.type.class.deduct
7823
  [dcl.type.cv]: #dcl.type.cv
7824
  [dcl.type.decltype]: #dcl.type.decltype
7825
  [dcl.type.elab]: #dcl.type.elab
 
7826
  [dcl.type.simple]: #dcl.type.simple
7827
  [dcl.typedef]: #dcl.typedef
7828
  [depr.volatile.type]: future.md#depr.volatile.type
7829
  [enum]: #enum
7830
  [enum.udecl]: #enum.udecl
7831
  [except.ctor]: except.md#except.ctor
7832
  [except.handle]: except.md#except.handle
 
7833
  [except.spec]: except.md#except.spec
7834
  [except.throw]: except.md#except.throw
7835
  [expr.alignof]: expr.md#expr.alignof
7836
  [expr.ass]: expr.md#expr.ass
7837
  [expr.await]: expr.md#expr.await
7838
  [expr.call]: expr.md#expr.call
7839
  [expr.cast]: expr.md#expr.cast
 
7840
  [expr.const]: expr.md#expr.const
7841
  [expr.const.cast]: expr.md#expr.const.cast
7842
  [expr.mptr.oper]: expr.md#expr.mptr.oper
7843
  [expr.new]: expr.md#expr.new
7844
  [expr.post.incr]: expr.md#expr.post.incr
7845
  [expr.pre.incr]: expr.md#expr.pre.incr
 
7846
  [expr.prim.lambda]: expr.md#expr.prim.lambda
7847
  [expr.prim.this]: expr.md#expr.prim.this
7848
  [expr.prop]: expr.md#expr.prop
7849
  [expr.ref]: expr.md#expr.ref
7850
  [expr.static.cast]: expr.md#expr.static.cast
7851
  [expr.sub]: expr.md#expr.sub
7852
  [expr.type.conv]: expr.md#expr.type.conv
7853
  [expr.unary]: expr.md#expr.unary
7854
  [expr.unary.op]: expr.md#expr.unary.op
7855
  [expr.yield]: expr.md#expr.yield
 
 
7856
  [intro.compliance]: intro.md#intro.compliance
7857
  [intro.execution]: basic.md#intro.execution
7858
  [intro.multithread]: basic.md#intro.multithread
7859
  [intro.object]: basic.md#intro.object
7860
- [lex.charset]: lex.md#lex.charset
7861
  [lex.digraph]: lex.md#lex.digraph
7862
  [lex.key]: lex.md#lex.key
7863
  [lex.name]: lex.md#lex.name
7864
  [lex.string]: lex.md#lex.string
7865
  [module.interface]: module.md#module.interface
 
 
7866
  [namespace.alias]: #namespace.alias
7867
  [namespace.def]: #namespace.def
7868
- [namespace.memdef]: #namespace.memdef
7869
  [namespace.qual]: basic.md#namespace.qual
7870
  [namespace.udecl]: #namespace.udecl
7871
  [namespace.udir]: #namespace.udir
7872
  [namespace.unnamed]: #namespace.unnamed
7873
  [over]: over.md#over
7874
  [over.binary]: over.md#over.binary
 
7875
  [over.match]: over.md#over.match
7876
  [over.match.best]: over.md#over.match.best
7877
  [over.match.class.deduct]: over.md#over.match.class.deduct
7878
  [over.match.conv]: over.md#over.match.conv
7879
  [over.match.copy]: over.md#over.match.copy
@@ -7883,42 +7794,44 @@ Here, `hasher`, `pred`, and `alloc` could have the same address as
7883
  [over.match.ref]: over.md#over.match.ref
7884
  [over.match.viable]: over.md#over.match.viable
7885
  [over.oper]: over.md#over.oper
7886
  [over.sub]: over.md#over.sub
7887
  [special]: class.md#special
 
7888
  [stmt.ambig]: stmt.md#stmt.ambig
7889
  [stmt.dcl]: stmt.md#stmt.dcl
7890
  [stmt.expr]: stmt.md#stmt.expr
7891
  [stmt.if]: stmt.md#stmt.if
7892
  [stmt.iter]: stmt.md#stmt.iter
7893
- [stmt.label]: stmt.md#stmt.label
7894
- [stmt.pre]: stmt.md#stmt.pre
7895
  [stmt.return]: stmt.md#stmt.return
7896
  [stmt.return.coroutine]: stmt.md#stmt.return.coroutine
7897
  [stmt.select]: stmt.md#stmt.select
7898
  [stmt.stmt]: stmt.md#stmt.stmt
7899
  [stmt.switch]: stmt.md#stmt.switch
7900
  [support.runtime]: support.md#support.runtime
7901
  [temp.arg.type]: temp.md#temp.arg.type
7902
- [temp.class.spec]: temp.md#temp.class.spec
7903
  [temp.deduct]: temp.md#temp.deduct
7904
  [temp.deduct.call]: temp.md#temp.deduct.call
 
7905
  [temp.deduct.guide]: temp.md#temp.deduct.guide
7906
- [temp.dep]: temp.md#temp.dep
7907
  [temp.expl.spec]: temp.md#temp.expl.spec
7908
  [temp.explicit]: temp.md#temp.explicit
7909
  [temp.fct]: temp.md#temp.fct
7910
  [temp.inst]: temp.md#temp.inst
7911
  [temp.local]: temp.md#temp.local
7912
- [temp.mem]: temp.md#temp.mem
7913
  [temp.names]: temp.md#temp.names
7914
- [temp.over.link]: temp.md#temp.over.link
7915
  [temp.param]: temp.md#temp.param
7916
  [temp.pre]: temp.md#temp.pre
7917
  [temp.res]: temp.md#temp.res
7918
- [temp.spec]: temp.md#temp.spec
7919
  [temp.variadic]: temp.md#temp.variadic
 
 
 
 
7920
 
7921
  [^1]: There is no special provision for a *decl-specifier-seq* that
7922
  lacks a *type-specifier* or that has a *type-specifier* that only
7923
  specifies *cv-qualifier*s. The “implicit int” rule of C is no longer
7924
  supported.
@@ -7946,25 +7859,22 @@ Here, `hasher`, `pred`, and `alloc` could have the same address as
7946
  reference type.
7947
 
7948
  [^8]: Implementations are permitted to provide additional predefined
7949
  variables with names that are reserved to the implementation
7950
  [[lex.name]]. If a predefined variable is not odr-used
7951
- [[basic.def.odr]], its string value need not be present in the
7952
  program image.
7953
 
7954
  [^9]: This set of values is used to define promotion and conversion
7955
  semantics for the enumeration type. It does not preclude an
7956
  expression of enumeration type from having a value that falls
7957
  outside this range.
7958
 
7959
- [^10]: this implies that the name of the class or function is
7960
- unqualified.
7961
-
7962
- [^11]: During name lookup in a class hierarchy, some ambiguities may be
7963
  resolved by considering whether one member hides the other along
7964
- some paths [[class.member.lookup]]. There is no such disambiguation
7965
- when considering the set of names found as a result of following
7966
- *using-directive*s.
7967
 
7968
- [^12]: A *using-declaration* with more than one *using-declarator* is
7969
  equivalent to a corresponding sequence of *using-declaration*s with
7970
  one *using-declarator* each.
 
11
  declaration-seq declaration
12
  ```
13
 
14
  ``` bnf
15
  declaration:
16
+ name-declaration
17
+ special-declaration
18
+ ```
19
+
20
+ ``` bnf
21
+ name-declaration:
22
  block-declaration
23
  nodeclspec-function-declaration
24
  function-definition
25
  template-declaration
26
  deduction-guide
 
 
 
27
  linkage-specification
28
  namespace-definition
29
  empty-declaration
30
  attribute-declaration
31
  module-import-declaration
32
  ```
33
 
34
+ ``` bnf
35
+ special-declaration:
36
+ explicit-instantiation
37
+ explicit-specialization
38
+ export-declaration
39
+ ```
40
+
41
  ``` bnf
42
  block-declaration:
43
  simple-declaration
44
  asm-declaration
45
  namespace-alias-definition
 
91
  [[temp.deduct.guide]]; *namespace-definition*s are described in 
92
  [[namespace.def]], *using-declaration*s are described in 
93
  [[namespace.udecl]] and *using-directive*s are described in 
94
  [[namespace.udir]]. — *end note*]
95
 
96
+ Certain declarations contain one or more scopes [[basic.scope.scope]].
97
+ Unless otherwise stated, utterances in [[dcl.dcl]] about components in,
98
+ of, or contained by a declaration or subcomponent thereof refer only to
99
+ those components of the declaration that are *not* nested within scopes
100
+ nested within the declaration.
101
+
102
  A *simple-declaration* or *nodeclspec-function-declaration* of the form
103
 
104
  ``` bnf
105
  attribute-specifier-seqₒₚₜ decl-specifier-seqₒₚₜ init-declarator-listₒₚₜ ';'
106
  ```
 
111
  *init-declarator-list*, are described in [[dcl.decl]]. The
112
  *attribute-specifier-seq* appertains to each of the entities declared by
113
  the *declarator*s of the *init-declarator-list*.
114
 
115
  [*Note 2*: In the declaration for an entity, attributes appertaining to
116
+ that entity can appear at the start of the declaration and after the
117
  *declarator-id* for that declaration. — *end note*]
118
 
119
  [*Example 1*:
120
 
121
  ``` cpp
122
  [[noreturn]] void f [[noreturn]] (); // OK
123
  ```
124
 
125
  — *end example*]
126
 
127
+ If a *declarator-id* is a name, the *init-declarator* and (hence) the
128
+ declaration introduce that name.
129
 
130
+ [*Note 3*: Otherwise, the *declarator-id* is a *qualified-id* or names
131
+ a destructor or its *unqualified-id* is a *template-id* and no name is
132
+ introduced. *end note*]
133
+
134
+ The *defining-type-specifier*s [[dcl.type]] in the *decl-specifier-seq*
135
+ and the recursive *declarator* structure describe a type
136
+ [[dcl.meaning]], which is then associated with the *declarator-id*.
 
137
 
138
  In a *simple-declaration*, the optional *init-declarator-list* can be
139
+ omitted only when declaring a class [[class.pre]] or enumeration
140
  [[dcl.enum]], that is, when the *decl-specifier-seq* contains either a
141
  *class-specifier*, an *elaborated-type-specifier* with a *class-key*
142
  [[class.name]], or an *enum-specifier*. In these cases and whenever a
143
  *class-specifier* or *enum-specifier* is present in the
144
+ *decl-specifier-seq*, the identifiers in these specifiers are also
145
+ declared (as *class-name*s, *enum-name*s, or *enumerator*s, depending on
146
+ the syntax). In such cases, the *decl-specifier-seq* shall (re)introduce
147
+ one or more names into the program.
 
148
 
149
  [*Example 2*:
150
 
151
  ``` cpp
152
  enum { }; // error
153
  typedef class { }; // error
154
  ```
155
 
156
  — *end example*]
157
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  A *simple-declaration* with an *identifier-list* is called a *structured
159
+ binding declaration* [[dcl.struct.bind]]. Each *decl-specifier* in the
160
+ *decl-specifier-seq* shall be `static`, `thread_local`, `auto`
161
+ [[dcl.spec.auto]], or a *cv-qualifier*.
162
+
163
+ [*Example 3*:
164
+
165
+ ``` cpp
166
+ template<class T> concept C = true;
167
+ C auto [x, y] = std::pair{1, 2}; // error: constrained placeholder-type-specifier
168
+ // not permitted for structured bindings
169
+ ```
170
+
171
+ — *end example*]
172
+
173
  The *initializer* shall be of the form “`=` *assignment-expression*”, of
174
  the form “`{` *assignment-expression* `}`”, or of the form “`(`
175
  *assignment-expression* `)`”, where the *assignment-expression* is of
176
  array or non-union class type.
177
 
 
 
 
 
 
 
 
 
178
  If the *decl-specifier-seq* contains the `typedef` specifier, the
179
+ declaration is a *typedef declaration* and each *declarator-id* is
180
+ declared to be a *typedef-name*, synonymous with its associated type
181
+ [[dcl.typedef]].
182
+
183
+ [*Note 4*: Such a *declarator-id* is an *identifier*
184
+ [[class.conv.fct]]. *end note*]
185
+
186
+ Otherwise, if the type associated with a *declarator-id* is a function
187
+ type [[dcl.fct]], the declaration is a *function declaration*.
188
+ Otherwise, if the type associated with a *declarator-id* is an object or
189
+ reference type, the declaration is an *object declaration*. Otherwise,
190
+ the program is ill-formed.
191
+
192
+ [*Example 4*:
193
+
194
+ ``` cpp
195
+ int f(), x; // OK, function declaration for f and object declaration for x
196
+ extern void g(), // OK, function declaration for g
197
+ y; // error: void is not an object type
198
+ ```
199
+
200
+ — *end example*]
201
 
202
  Syntactic components beyond those found in the general form of
203
+ *simple-declaration* are added to a function declaration to make a
204
  *function-definition*. An object declaration, however, is also a
205
  definition unless it contains the `extern` specifier and has no
206
  initializer [[basic.def]]. An object definition causes storage of
207
  appropriate size and alignment to be reserved and any appropriate
208
  initialization [[dcl.init]] to be done.
209
 
210
  A *nodeclspec-function-declaration* shall declare a constructor,
211
  destructor, or conversion function.
212
 
213
+ [*Note 5*: Because a member function cannot be subject to a
214
+ non-defining declaration outside of a class definition [[class.mfct]], a
215
+ *nodeclspec-function-declaration* can only be used in a
216
  *template-declaration* [[temp.pre]], *explicit-instantiation*
217
  [[temp.explicit]], or *explicit-specialization*
218
  [[temp.expl.spec]]. — *end note*]
219
 
220
+ In a *static_assert-declaration*, the *constant-expression* is
221
+ contextually converted to `bool` and the converted expression shall be a
222
+ constant expression [[expr.const]]. If the value of the expression when
223
+ so converted is `true` or the expression is evaluated in the context of
224
+ a template definition, the declaration has no effect. Otherwise, the
225
+ *static_assert-declaration* *fails*, the program is ill-formed, and the
226
+ resulting diagnostic message [[intro.compliance]] should include the
227
+ text of the *string-literal*, if one is supplied.
228
+
229
+ [*Example 5*:
230
+
231
+ ``` cpp
232
+ static_assert(sizeof(int) == sizeof(void*), "wrong pointer size");
233
+ static_assert(sizeof(int[2])); // OK, narrowing allowed
234
+
235
+ template <class T>
236
+ void f(T t) {
237
+ if constexpr (sizeof(T) == sizeof(int)) {
238
+ use(t);
239
+ } else {
240
+ static_assert(false, "must be int-sized");
241
+ }
242
+ }
243
+
244
+ void g(char c) {
245
+ f(0); // OK
246
+ f(c); // error on implementations where sizeof(int) > 1: must be int-sized
247
+ }
248
+ ```
249
+
250
+ — *end example*]
251
+
252
+ An *empty-declaration* has no effect.
253
+
254
+ Except where otherwise specified, the meaning of an
255
+ *attribute-declaration* is *implementation-defined*.
256
+
257
  ## Specifiers <a id="dcl.spec">[[dcl.spec]]</a>
258
 
259
+ ### General <a id="dcl.spec.general">[[dcl.spec.general]]</a>
260
+
261
  The specifiers that can be used in a declaration are
262
 
263
  ``` bnf
264
  decl-specifier:
265
  storage-class-specifier
 
351
  `static` or `extern`. If `thread_local` appears in any declaration of a
352
  variable it shall be present in all declarations of that entity. If a
353
  *storage-class-specifier* appears in a *decl-specifier-seq*, there can
354
  be no `typedef` specifier in the same *decl-specifier-seq* and the
355
  *init-declarator-list* or *member-declarator-list* of the declaration
356
+ shall not be empty (except for an anonymous union declared in a
357
+ namespace scope [[class.union.anon]]). The *storage-class-specifier*
358
+ applies to the name declared by each *init-declarator* in the list and
359
+ not to any names declared by other specifiers.
 
360
 
361
  [*Note 1*: See [[temp.expl.spec]] and [[temp.explicit]] for
362
  restrictions in explicit specializations and explicit instantiations,
363
  respectively. — *end note*]
364
 
 
394
 
395
  [*Note 3*: The `extern` keyword can also be used in
396
  *explicit-instantiation*s and *linkage-specification*s, but it is not a
397
  *storage-class-specifier* in such contexts. — *end note*]
398
 
399
+ All declarations for a given entity shall give its name the same
400
+ linkage.
401
+
402
+ [*Note 4*: The linkage given by some declarations is affected by
403
+ previous declarations. Overloads are distinct entities. — *end note*]
404
 
405
  [*Example 1*:
406
 
407
  ``` cpp
408
  static char* f(); // f() has internal linkage
 
473
  };
474
  ```
475
 
476
  — *end example*]
477
 
478
+ [*Note 5*: The `mutable` specifier on a class data member nullifies a
479
  `const` specifier applied to the containing class object and permits
480
  modification of the mutable class member even though the rest of the
481
+ object is const
482
+ [[basic.type.qualifier]], [[dcl.type.cv]]. — *end note*]
483
 
484
  ### Function specifiers <a id="dcl.fct.spec">[[dcl.fct.spec]]</a>
485
 
486
  A *function-specifier* can be used only in a function declaration.
487
 
 
496
  explicit '(' constant-expression ')'
497
  explicit
498
  ```
499
 
500
  The `virtual` specifier shall be used only in the initial declaration of
501
+ a non-static member function; see  [[class.virtual]].
502
 
503
  An *explicit-specifier* shall be used only in the declaration of a
504
  constructor or conversion function within its class definition; see 
505
  [[class.conv.ctor]] and  [[class.conv.fct]].
506
 
 
511
  `explicit(true)`. If the constant expression evaluates to `true`, the
512
  function is explicit. Otherwise, the function is not explicit. A `(`
513
  token that follows `explicit` is parsed as part of the
514
  *explicit-specifier*.
515
 
516
+ [*Example 1*:
517
+
518
+ ``` cpp
519
+ struct S {
520
+ explicit(sizeof(char[2])) S(char); // error: narrowing conversion of value 2 to type bool
521
+ explicit(sizeof(char)) S(bool); // OK, conversion of value 1 to type bool is non-narrowing
522
+ };
523
+ ```
524
+
525
+ — *end example*]
526
+
527
  ### The `typedef` specifier <a id="dcl.typedef">[[dcl.typedef]]</a>
528
 
529
  Declarations containing the *decl-specifier* `typedef` declare
530
  identifiers that can be used later for naming fundamental
531
  [[basic.fundamental]] or compound [[basic.compound]] types. The
 
568
  of `metricp` is “pointer to `int`”.
569
 
570
  — *end example*]
571
 
572
  A *typedef-name* can also be introduced by an *alias-declaration*. The
573
+ *identifier* following the `using` keyword is not looked up; it becomes
574
+ a *typedef-name* and the optional *attribute-specifier-seq* following
575
+ the *identifier* appertains to that *typedef-name*. Such a
576
+ *typedef-name* has the same semantics as if it were introduced by the
577
+ `typedef` specifier. In particular, it does not define a new type.
578
 
579
  [*Example 2*:
580
 
581
  ``` cpp
582
  using handler_t = void (*)(int);
583
  extern handler_t ignore;
584
  extern void (*ignore)(int); // redeclare ignore
585
+ template<class T> struct P { };
586
+ using cell = P<cell*>; // error: cell not found[basic.scope.pdecl]
587
  ```
588
 
589
  — *end example*]
590
 
591
  The *defining-type-specifier-seq* of the *defining-type-id* shall not
592
  define a class or enumeration if the *alias-declaration* is the
593
  *declaration* of a *template-declaration*.
594
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
595
  A *simple-template-id* is only a *typedef-name* if its *template-name*
596
  names an alias template or a template *template-parameter*.
597
 
598
  [*Note 1*: A *simple-template-id* that names a class template
599
  specialization is a *class-name* [[class.name]]. If a *typedef-name* is
600
  used to identify the subject of an *elaborated-type-specifier*
601
  [[dcl.type.elab]], a class definition [[class]], a constructor
602
  declaration [[class.ctor]], or a destructor declaration [[class.dtor]],
603
  the program is ill-formed. — *end note*]
604
 
605
+ [*Example 3*:
606
 
607
  ``` cpp
608
  struct S {
609
  S();
610
  ~S();
 
616
  struct T * p; // error
617
  ```
618
 
619
  — *end example*]
620
 
621
+ An unnamed class or enumeration C defined in a typedef declaration has
622
+ the first *typedef-name* declared by the declaration to be of type C as
623
+ its *typedef name for linkage purposes* [[basic.link]].
624
 
625
  [*Note 2*: A typedef declaration involving a *lambda-expression* does
626
  not itself define the associated closure type, and so the closure type
627
+ is not given a typedef name for linkage purposes. — *end note*]
628
 
629
+ [*Example 4*:
630
 
631
  ``` cpp
632
+ typedef struct { } *ps, S; // S is the typedef name for linkage purposes
633
+ typedef decltype([]{}) C; // the closure type has no typedef name for linkage purposes
634
  ```
635
 
636
  — *end example*]
637
 
638
  An unnamed class with a typedef name for linkage purposes shall not
 
643
  - contain a *lambda-expression*,
644
 
645
  and all member classes shall also satisfy these requirements
646
  (recursively).
647
 
648
+ [*Example 5*:
649
 
650
  ``` cpp
651
  typedef struct {
652
  int f() {}
653
  } X; // error: struct with typedef name for linkage has member functions
 
680
  `constexpr`. — *end note*]
681
 
682
  [*Example 1*:
683
 
684
  ``` cpp
685
+ constexpr void square(int &x); // OK, declaration
686
+ constexpr int bufsz = 1024; // OK, definition
687
  constexpr struct pixel { // error: pixel is a type
688
  int x;
689
  int y;
690
+ constexpr pixel(int); // OK, declaration
691
  };
692
  constexpr pixel::pixel(int a)
693
+ : x(a), y(x) // OK, definition
694
  { square(x); }
695
  constexpr pixel small(2); // error: square not defined, so small(2)
696
  // not constant[expr.const] so constexpr not satisfied
697
 
698
+ constexpr void square(int &x) { // OK, definition
699
  x *= x;
700
  }
701
+ constexpr pixel large(4); // OK, square defined
702
  int next(constexpr int x) { // error: not for parameters
703
  return x + 1;
704
  }
705
  extern constexpr int memsz; // error: not a definition
706
  ```
707
 
708
  — *end example*]
709
 
710
  A `constexpr` or `consteval` specifier used in the declaration of a
711
+ function declares that function to be a *constexpr function*.
 
 
 
 
712
 
713
+ [*Note 3*: A function or constructor declared with the `consteval`
714
+ specifier is an immediate function [[expr.const]]. — *end note*]
715
 
716
+ A destructor, an allocation function, or a deallocation function shall
717
+ not be declared with the `consteval` specifier.
 
 
 
 
 
 
 
 
718
 
719
+ A function is *constexpr-suitable* if:
720
+
721
+ - it is not a coroutine [[dcl.fct.def.coroutine]], and
722
+ - if the function is a constructor or destructor, its class does not
723
+ have any virtual base classes.
724
+
725
+ Except for instantiated constexpr functions, non-templated constexpr
726
+ functions shall be constexpr-suitable.
727
 
728
  [*Example 2*:
729
 
730
  ``` cpp
731
  constexpr int square(int x)
 
735
  constexpr int abs(int x) {
736
  if (x < 0)
737
  x = -x;
738
  return x; // OK
739
  }
740
+ constexpr int constant_non_42(int n) { // OK
741
+ if (n == 42) {
742
+ static int value = n;
743
  return value;
744
  }
745
+ return n;
746
+ }
747
  constexpr int uninit() {
748
  struct { int a; } s;
749
  return s.a; // error: uninitialized read of s.a
750
  }
751
  constexpr int prev(int x)
 
757
  }
758
  ```
759
 
760
  — *end example*]
761
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
762
  An invocation of a constexpr function in a given context produces the
763
  same result as an invocation of an equivalent non-constexpr function in
764
  the same context in all respects except that
765
 
766
  - an invocation of a constexpr function can appear in a constant
 
771
  [*Note 4*: Declaring a function constexpr can change whether an
772
  expression is a constant expression. This can indirectly cause calls to
773
  `std::is_constant_evaluated` within an invocation of the function to
774
  produce a different value. — *end note*]
775
 
776
+ [*Note 5*: It is possible to write a constexpr function for which no
777
+ invocation satisfies the requirements of a core constant
778
+ expression. — *end note*]
779
+
780
  The `constexpr` and `consteval` specifiers have no effect on the type of
781
  a constexpr function.
782
 
783
+ [*Example 3*:
784
 
785
  ``` cpp
786
  constexpr int bar(int x, int y) // OK
787
  { return x + y + x*y; }
788
  // ...
 
794
 
795
  A `constexpr` specifier used in an object declaration declares the
796
  object as const. Such an object shall have literal type and shall be
797
  initialized. In any `constexpr` variable declaration, the
798
  full-expression of the initialization shall be a constant expression
799
+ [[expr.const]]. A `constexpr` variable that is an object, as well as any
800
+ temporary to which a `constexpr` reference is bound, shall have constant
801
+ destruction.
802
 
803
+ [*Example 4*:
804
 
805
  ``` cpp
806
  struct pixel {
807
  int x, y;
808
  };
 
819
  applied to any declaration of a variable, it shall be applied to the
820
  initializing declaration. No diagnostic is required if no `constinit`
821
  declaration is reachable at the point of the initializing declaration.
822
 
823
  If a variable declared with the `constinit` specifier has dynamic
824
+ initialization [[basic.start.dynamic]], the program is ill-formed, even
825
+ if the implementation would perform that initialization as a static
826
+ initialization [[basic.start.static]].
827
 
828
  [*Note 1*: The `constinit` specifier ensures that the variable is
829
+ initialized during static initialization. — *end note*]
 
830
 
831
  [*Example 1*:
832
 
833
  ``` cpp
834
  const char * g() { return "dynamic initialization"; }
 
842
  ### The `inline` specifier <a id="dcl.inline">[[dcl.inline]]</a>
843
 
844
  The `inline` specifier shall be applied only to the declaration of a
845
  variable or function.
846
 
847
+ A function declaration [[dcl.fct]], [[class.mfct]], [[class.friend]]
848
  with an `inline` specifier declares an *inline function*. The inline
849
  specifier indicates to the implementation that inline substitution of
850
  the function body at the point of call is to be preferred to the usual
851
  function call mechanism. An implementation is not required to perform
852
  this inline substitution at the point of call; however, even if this
 
871
  in one definition domain, an inline declaration of it shall be reachable
872
  from the end of every definition domain in which it is declared; no
873
  diagnostic is required.
874
 
875
  [*Note 2*: A call to an inline function or a use of an inline variable
876
+ can be encountered before its definition becomes reachable in a
877
  translation unit. — *end note*]
878
 
879
  [*Note 3*: An inline function or variable with external or module
880
+ linkage can be defined in multiple translation units [[basic.def.odr]],
881
+ but is one entity with one address. A type or `static` variable defined
882
+ in the body of such a function is therefore a single
883
+ entity. *end note*]
 
884
 
885
  If an inline function or variable that is attached to a named module is
886
  declared in a definition domain, it shall be defined in that domain.
887
 
888
  [*Note 4*: A constexpr function [[dcl.constexpr]] is implicitly inline.
889
  In the global module, a function defined within a class definition is
890
+ implicitly inline [[class.mfct]], [[class.friend]]. — *end note*]
891
 
892
  ### Type specifiers <a id="dcl.type">[[dcl.type]]</a>
893
 
894
+ #### General <a id="dcl.type.general">[[dcl.type.general]]</a>
895
+
896
  The type-specifiers are
897
 
898
  ``` bnf
899
  type-specifier:
900
  simple-type-specifier
 
949
  complete *decl-specifier-seq*.[^1]
950
 
951
  [*Note 1*: *enum-specifier*s, *class-specifier*s, and
952
  *typename-specifier*s are discussed in [[dcl.enum]], [[class]], and
953
  [[temp.res]], respectively. The remaining *type-specifier*s are
954
+ discussed in the rest of [[dcl.type]]. — *end note*]
955
 
956
  #### The *cv-qualifier*s <a id="dcl.type.cv">[[dcl.type.cv]]</a>
957
 
958
  There are two *cv-qualifier*s, `const` and `volatile`. Each
959
  *cv-qualifier* shall appear at most once in a *cv-qualifier-seq*. If a
 
982
  some other access path.
983
 
984
  [*Note 4*: Cv-qualifiers are supported by the type system so that they
985
  cannot be subverted without casting [[expr.const.cast]]. — *end note*]
986
 
987
+ Any attempt to modify
988
+ [[expr.ass]], [[expr.post.incr]], [[expr.pre.incr]] a const object
989
+ [[basic.type.qualifier]] during its lifetime [[basic.life]] results in
990
+ undefined behavior.
991
 
992
  [*Example 1*:
993
 
994
  ``` cpp
995
  const int ci = 3; // cv-qualified (initialized as required)
996
  ci = 4; // error: attempt to modify const
997
 
998
  int i = 2; // not cv-qualified
999
  const int* cip; // pointer to const int
1000
+ cip = &i; // OK, cv-qualified access path to unqualified
1001
  *cip = 4; // error: attempt to modify through ptr to const
1002
 
1003
  int* ip;
1004
  ip = const_cast<int*>(cip); // cast needed to convert const int* to int*
1005
  *ip = 4; // defined: *ip points to i, a non-const object
 
1077
  class-name
1078
  enum-name
1079
  typedef-name
1080
  ```
1081
 
1082
+ The component names of a *simple-type-specifier* are those of its
1083
+ *nested-name-specifier*, *type-name*, *simple-template-id*,
1084
+ *template-name*, and/or *type-constraint* (if it is a
1085
+ *placeholder-type-specifier*). The component name of a *type-name* is
1086
+ the first name in it.
1087
+
1088
  A *placeholder-type-specifier* is a placeholder for a type to be deduced
1089
  [[dcl.spec.auto]]. A *type-specifier* of the form `typename`ₒₚₜ
1090
  *nested-name-specifier*ₒₚₜ *template-name* is a placeholder for a
1091
  deduced class type [[dcl.type.class.deduct]]. The
1092
  *nested-name-specifier*, if any, shall be non-dependent and the
 
1169
  ``` bnf
1170
  elaborated-type-specifier:
1171
  class-key attribute-specifier-seqₒₚₜ nested-name-specifierₒₚₜ identifier
1172
  class-key simple-template-id
1173
  class-key nested-name-specifier templateₒₚₜ simple-template-id
 
 
 
 
 
1174
  enum nested-name-specifierₒₚₜ identifier
1175
  ```
1176
 
1177
+ The component names of an *elaborated-type-specifier* are its
1178
+ *identifier* (if any) and those of its *nested-name-specifier* and
1179
+ *simple-template-id* (if any).
1180
+
1181
+ If an *elaborated-type-specifier* is the sole constituent of a
1182
+ declaration, the declaration is ill-formed unless it is an explicit
1183
  specialization [[temp.expl.spec]], an explicit instantiation
1184
  [[temp.explicit]] or it has one of the following forms:
1185
 
1186
  ``` bnf
1187
  class-key attribute-specifier-seqₒₚₜ identifier ';'
1188
+ class-key attribute-specifier-seqₒₚₜ simple-template-id ';'
1189
+ ```
1190
+
1191
+ In the first case, the *elaborated-type-specifier* declares the
1192
+ *identifier* as a *class-name*. The second case shall appear only in an
1193
+ *explicit-specialization* [[temp.expl.spec]] or in a
1194
+ *template-declaration* (where it declares a partial specialization
1195
+ [[temp.decls]]). The *attribute-specifier-seq*, if any, appertains to
1196
+ the class or template being declared.
1197
+
1198
+ Otherwise, an *elaborated-type-specifier* E shall not have an
1199
+ *attribute-specifier-seq*. If E contains an *identifier* but no
1200
+ *nested-name-specifier* and (unqualified) lookup for the *identifier*
1201
+ finds nothing, E shall not be introduced by the `enum` keyword and
1202
+ declares the *identifier* as a *class-name*. The target scope of E is
1203
+ the nearest enclosing namespace or block scope.
1204
+
1205
+ If an *elaborated-type-specifier* appears with the `friend` specifier as
1206
+ an entire *member-declaration*, the *member-declaration* shall have one
1207
+ of the following forms:
1208
+
1209
+ ``` bnf
1210
+ friend class-key nested-name-specifierₒₚₜ identifier ';'
1211
+ friend class-key simple-template-id ';'
1212
  friend class-key nested-name-specifier templateₒₚₜ simple-template-id ';'
1213
  ```
1214
 
1215
+ Any unqualified lookup for the *identifier* (in the first case) does not
1216
+ consider scopes that contain the target scope; no name is bound.
 
 
1217
 
1218
+ [*Note 1*: A *using-directive* in the target scope is ignored if it
1219
+ refers to a namespace not contained by that scope. [[basic.lookup.elab]]
1220
+ describes how name lookup proceeds in an
1221
+ *elaborated-type-specifier*. — *end note*]
1222
+
1223
+ [*Note 2*: An *elaborated-type-specifier* can be used to refer to a
1224
+ previously declared *class-name* or *enum-name* even if the name has
1225
+ been hidden by a non-type declaration. — *end note*]
1226
 
1227
  If the *identifier* or *simple-template-id* resolves to a *class-name*
1228
  or *enum-name*, the *elaborated-type-specifier* introduces it into the
1229
  declaration the same way a *simple-type-specifier* introduces its
1230
  *type-name* [[dcl.type.simple]]. If the *identifier* or
1231
+ *simple-template-id* resolves to a *typedef-name*
1232
+ [[dcl.typedef]], [[temp.names]], the *elaborated-type-specifier* is
1233
+ ill-formed.
1234
 
1235
+ [*Note 3*:
1236
 
1237
  This implies that, within a class template with a template
1238
  *type-parameter* `T`, the declaration
1239
 
1240
  ``` cpp
 
1282
  [[dcl.struct.bind]], `decltype(E)` is the referenced type as given in
1283
  the specification of the structured binding declaration;
1284
  - otherwise, if E is an unparenthesized *id-expression* naming a
1285
  non-type *template-parameter* [[temp.param]], `decltype(E)` is the
1286
  type of the *template-parameter* after performing any necessary type
1287
+ deduction [[dcl.spec.auto]], [[dcl.type.class.deduct]];
1288
  - otherwise, if E is an unparenthesized *id-expression* or an
1289
  unparenthesized class member access [[expr.ref]], `decltype(E)` is the
1290
+ type of the entity named by E. If there is no such entity, the program
1291
+ is ill-formed;
1292
  - otherwise, if E is an xvalue, `decltype(E)` is `T&&`, where `T` is the
1293
  type of E;
1294
  - otherwise, if E is an lvalue, `decltype(E)` is `T&`, where `T` is the
1295
  type of E;
1296
  - otherwise, `decltype(E)` is the type of E.
1297
 
1298
  The operand of the `decltype` specifier is an unevaluated operand
1299
+ [[term.unevaluated.operand]].
1300
 
1301
  [*Example 1*:
1302
 
1303
  ``` cpp
1304
  const int&& foo();
 
1348
  // for the temporary introduced by the use of h().
1349
  // (A temporary is not introduced as a result of the use of i().)
1350
  template<class T> auto f(T) // #2
1351
  -> void;
1352
  auto g() -> void {
1353
+ f(42); // OK, calls #2. (#1 is not a viable candidate: type deduction
1354
  // fails[temp.deduct] because A<int>::~A() is implicitly used in its
1355
  // decltype-specifier)
1356
  }
1357
  template<class T> auto q(T)
1358
  -> decltype((h<T>())); // does not force completion of A<T>; A<T>::~A() is not implicitly
 
1367
 
1368
  — *end example*]
1369
 
1370
  #### Placeholder type specifiers <a id="dcl.spec.auto">[[dcl.spec.auto]]</a>
1371
 
1372
+ ##### General <a id="dcl.spec.auto.general">[[dcl.spec.auto.general]]</a>
1373
+
1374
  ``` bnf
1375
  placeholder-type-specifier:
1376
  type-constraintₒₚₜ auto
1377
  type-constraintₒₚₜ decltype '(' auto ')'
1378
  ```
 
1389
 
1390
  [*Note 1*: Having a generic parameter type placeholder signifies that
1391
  the function is an abbreviated function template [[dcl.fct]] or the
1392
  lambda is a generic lambda [[expr.prim.lambda]]. — *end note*]
1393
 
1394
+ A placeholder type can appear with a function declarator in the
1395
  *decl-specifier-seq*, *type-specifier-seq*, *conversion-function-id*, or
1396
  *trailing-return-type*, in any context where such a declarator is valid.
1397
  If the function declarator includes a *trailing-return-type*
1398
  [[dcl.fct]], that *trailing-return-type* specifies the declared return
1399
  type of the function. Otherwise, the function declarator shall declare a
 
1405
  The type of a variable declared using a placeholder type is deduced from
1406
  its initializer. This use is allowed in an initializing declaration
1407
  [[dcl.init]] of a variable. The placeholder type shall appear as one of
1408
  the *decl-specifier*s in the *decl-specifier-seq* and the
1409
  *decl-specifier-seq* shall be followed by one or more *declarator*s,
1410
+ each of which shall be followed by a non-empty *initializer*.
 
 
 
 
 
 
 
1411
 
1412
  [*Example 1*:
1413
 
1414
  ``` cpp
1415
+ auto x = 5; // OK, x has type int
1416
+ const auto *v = &x, u = 6; // OK, v has type const int*, u has type const int
1417
+ static auto y = 0.0; // OK, y has type double
1418
  auto int r; // error: auto is not a storage-class-specifier
1419
+ auto f() -> int; // OK, f returns int
1420
+ auto g() { return 0.0; } // OK, g returns double
1421
+ auto h(); // OK, h's return type will be deduced when it is defined
1422
  ```
1423
 
1424
  — *end example*]
1425
 
1426
  The `auto` *type-specifier* can also be used to introduce a structured
1427
  binding declaration [[dcl.struct.bind]].
1428
 
1429
  A placeholder type can also be used in the *type-specifier-seq* in the
1430
  *new-type-id* or *type-id* of a *new-expression* [[expr.new]] and as a
1431
  *decl-specifier* of the *parameter-declaration*'s *decl-specifier-seq*
1432
+ in a *template-parameter* [[temp.param]]. The `auto` *type-specifier*
1433
+ can also be used as the *simple-type-specifier* in an explicit type
1434
+ conversion (functional notation) [[expr.type.conv]].
1435
 
1436
  A program that uses a placeholder type in a context not explicitly
1437
+ allowed in [[dcl.spec.auto]] is ill-formed.
1438
 
1439
  If the *init-declarator-list* contains more than one *init-declarator*,
1440
  they shall all form declarations of variables. The type of each declared
1441
  variable is determined by placeholder type deduction
1442
  [[dcl.type.auto.deduct]], and if the type that replaces the placeholder
1443
  type is not the same in each deduction, the program is ill-formed.
1444
 
1445
  [*Example 2*:
1446
 
1447
  ``` cpp
1448
+ auto x = 5, *y = &x; // OK, auto is int
1449
  auto a = 5, b = { 1, 2 }; // error: different types for auto
1450
  ```
1451
 
1452
  — *end example*]
1453
 
 
1475
  declaration, outside the *private-module-fragment* (if any).
1476
 
1477
  [*Note 2*: The deduced return type cannot have a name with internal
1478
  linkage [[basic.link]]. — *end note*]
1479
 
1480
+ If a variable or function with an undeduced placeholder type is named by
1481
+ an expression [[basic.def.odr]], the program is ill-formed. Once a
1482
+ non-discarded `return` statement has been seen in a function, however,
1483
+ the return type deduced from that statement can be used in the rest of
1484
+ the function, including in other `return` statements.
1485
 
1486
  [*Example 4*:
1487
 
1488
  ``` cpp
1489
  auto n = n; // error: n's initializer refers to n
 
1497
  }
1498
  ```
1499
 
1500
  — *end example*]
1501
 
1502
+ Return type deduction for a templated function with a placeholder in its
1503
+ declared type occurs when the definition is instantiated even if the
1504
+ function body contains a `return` statement with a non-type-dependent
1505
+ operand.
1506
 
1507
  [*Note 3*: Therefore, any use of a specialization of the function
1508
  template will cause an implicit instantiation. Any errors that arise
1509
  from this instantiation are not in the immediate context of the function
1510
  type and can result in the program being ill-formed
 
1520
  // chooses second
1521
  ```
1522
 
1523
  — *end example*]
1524
 
1525
+ If a function or function template F has a declared return type that
1526
+ uses a placeholder type, redeclarations or specializations of F shall
1527
+ use that placeholder type, not a deduced type; otherwise, they shall not
1528
+ use a placeholder type.
 
 
1529
 
1530
  [*Example 6*:
1531
 
1532
  ``` cpp
1533
  auto f();
1534
  auto f() { return 42; } // return type is int
1535
  auto f(); // OK
1536
+ int f(); // error: auto and int don't match
1537
  decltype(auto) f(); // error: auto and decltype(auto) don't match
1538
 
1539
  template <typename T> auto g(T t) { return t; } // #1
1540
  template auto g(int); // OK, return type is int
1541
  template char g(char); // error: no matching template
 
1587
 
1588
  *Placeholder type deduction* is the process by which a type containing a
1589
  placeholder type is replaced by a deduced type.
1590
 
1591
  A type `T` containing a placeholder type, and a corresponding
1592
+ *initializer-clause* E, are determined as follows:
1593
 
1594
+ - For a non-discarded `return` statement that occurs in a function
1595
  declared with a return type that contains a placeholder type, `T` is
1596
+ the declared return type.
1597
+ - If the `return` statement has no operand, then E is `void()`.
1598
+ - If the operand is a *braced-init-list* [[dcl.init.list]], the
1599
+ program is ill-formed.
1600
+ - If the operand is an *expression* X that is not an
1601
+ *assignment-expression*, E is `(X)`. \[*Note 4*: A comma expression
1602
+ [[expr.comma]] is not an *assignment-expression*. *end note*]
1603
+ - Otherwise, E is the operand of the `return` statement.
1604
+
1605
+ If E has type `void`, `T` shall be either *type-constraint*ₒₚₜ
1606
+ `decltype(auto)` or cv *type-constraint*ₒₚₜ `auto`.
1607
+ - For a variable declared with a type that contains a placeholder type,
1608
+ `T` is the declared type of the variable.
1609
+ - If the initializer of the variable is a *brace-or-equal-initializer*
1610
+ of the form `= initializer-clause`, E is the *initializer-clause*.
1611
+ - If the initializer is a *braced-init-list*, it shall consist of a
1612
+ single brace-enclosed *assignment-expression* and E is the
1613
+ *assignment-expression*.
1614
+ - If the initializer is a parenthesized *expression-list*, the
1615
+ *expression-list* shall be a single *assignment-expression* and E is
1616
+ the *assignment-expression*.
1617
+ - For an explicit type conversion [[expr.type.conv]], `T` is the
1618
+ specified type, which shall be `auto`.
1619
+ - If the initializer is a *braced-init-list*, it shall consist of a
1620
+ single brace-enclosed *assignment-expression* and E is the
1621
+ *assignment-expression*.
1622
+ - If the initializer is a parenthesized *expression-list*, the
1623
+ *expression-list* shall be a single *assignment-expression* and E is
1624
+ the *assignment-expression*.
1625
+ - For a non-type template parameter declared with a type that contains a
1626
  placeholder type, `T` is the declared type of the non-type template
1627
  parameter and E is the corresponding template argument.
1628
 
1629
+ `T` shall not be an array type.
 
 
 
 
 
1630
 
1631
  If the *placeholder-type-specifier* is of the form *type-constraint*ₒₚₜ
1632
  `auto`, the deduced type T' replacing `T` is determined using the rules
1633
+ for template argument deduction. If the initialization is
1634
+ copy-list-initialization, a declaration of `std::initializer_list` shall
1635
+ precede [[basic.lookup.general]] the *placeholder-type-specifier*.
1636
+ Obtain `P` from `T` by replacing the occurrences of
1637
+ *type-constraint*ₒₚₜ `auto` either with a new invented type template
1638
+ parameter `U` or, if the initialization is copy-list-initialization,
1639
+ with `std::initializer_list<U>`. Deduce a value for `U` using the rules
1640
+ of template argument deduction from a function call
1641
+ [[temp.deduct.call]], where `P` is a function template parameter type
1642
+ and the corresponding argument is E. If the deduction fails, the
1643
+ declaration is ill-formed. Otherwise, T' is obtained by substituting the
1644
+ deduced `U` into `P`.
1645
 
1646
  [*Example 8*:
1647
 
1648
  ``` cpp
1649
  auto x1 = { 1, 2 }; // decltype(x1) is std::initializer_list<int>
 
1670
 
1671
  — *end example*]
1672
 
1673
  If the *placeholder-type-specifier* is of the form *type-constraint*ₒₚₜ
1674
  `decltype(auto)`, `T` shall be the placeholder alone. The type deduced
1675
+ for `T` is determined as described in  [[dcl.type.decltype]], as though
1676
+ E had been the operand of the `decltype`.
1677
 
1678
  [*Example 10*:
1679
 
1680
  ``` cpp
1681
  int i;
 
1690
  decltype(auto) x5d = f(); // decltype(x5d) is int&&
1691
  auto x6a = { 1, 2 }; // decltype(x6a) is std::initializer_list<int>
1692
  decltype(auto) x6d = { 1, 2 }; // error: { 1, 2 } is not an expression
1693
  auto *x7a = &i; // decltype(x7a) is int*
1694
  decltype(auto)*x7d = &i; // error: declared type is not plain decltype(auto)
1695
+ auto f1(int x) -> decltype((x)) { return (x); } // return type is int&
1696
+ auto f2(int x) -> decltype(auto) { return (x); } // return type is int&&
1697
  ```
1698
 
1699
  — *end example*]
1700
 
1701
  For a *placeholder-type-specifier* with a *type-constraint*, the
 
1754
 
1755
  — *end example*]
1756
 
1757
  ## Declarators <a id="dcl.decl">[[dcl.decl]]</a>
1758
 
1759
+ ### General <a id="dcl.decl.general">[[dcl.decl.general]]</a>
1760
+
1761
  A declarator declares a single variable, function, or type, within a
1762
+ declaration. The *init-declarator-list* appearing in a
1763
+ *simple-declaration* is a comma-separated sequence of declarators, each
1764
+ of which can have an initializer.
1765
 
1766
  ``` bnf
1767
  init-declarator-list:
1768
  init-declarator
1769
  init-declarator-list ',' init-declarator
 
1773
  init-declarator:
1774
  declarator initializerₒₚₜ
1775
  declarator requires-clause
1776
  ```
1777
 
1778
+ In all contexts, a *declarator* is interpreted as given below. Where an
1779
+ *abstract-declarator* can be used (or omitted) in place of a
1780
+ *declarator* [[dcl.fct]], [[except.pre]], it is as if a unique
1781
+ identifier were included in the appropriate place [[dcl.name]]. The
1782
+ preceding specifiers indicate the type, storage class or other
1783
+ properties of the entity or entities being declared. Each declarator
1784
+ specifies one entity and (optionally) names it and/or modifies the type
1785
+ of the specifiers with operators such as `*` (pointer to) and `()`
1786
+ (function returning).
1787
 
1788
+ [*Note 1*: An *init-declarator* can also specify an initializer
1789
+ [[dcl.init]]. *end note*]
1790
 
1791
+ Each *init-declarator* or *member-declarator* in a declaration is
1792
+ analyzed separately as if it were in a declaration by itself.
1793
+
1794
+ [*Note 2*:
1795
 
1796
  A declaration with several declarators is usually equivalent to the
1797
  corresponding sequence of declarations each with a single declarator.
1798
+ That is,
1799
 
1800
  ``` cpp
1801
  T D1, D2, ... Dn;
1802
  ```
1803
 
 
1806
  ``` cpp
1807
  T D1; T D2; ... T Dn;
1808
  ```
1809
 
1810
  where `T` is a *decl-specifier-seq* and each `Di` is an
1811
+ *init-declarator* or *member-declarator*. One exception is when a name
1812
+ introduced by one of the *declarator*s hides a type name used by the
1813
+ *decl-specifier*s, so that when the same *decl-specifier*s are used in a
1814
+ subsequent declaration, they do not have the same meaning, as in
1815
 
1816
  ``` cpp
1817
  struct S { ... };
1818
  S S, T; // declare two instances of struct S
1819
  ```
 
1833
  ```
1834
 
1835
  as opposed to
1836
 
1837
  ``` cpp
1838
+ auto i = 1; // OK, i deduced to have type int
1839
+ auto j = 2.0; // OK, j deduced to have type double
1840
  ```
1841
 
1842
  — *end note*]
1843
 
1844
+ The optional *requires-clause* in an *init-declarator* or
1845
  *member-declarator* shall be present only if the declarator declares a
1846
+ templated function [[temp.pre]]. When present after a declarator, the
1847
  *requires-clause* is called the *trailing *requires-clause**. The
1848
  trailing *requires-clause* introduces the *constraint-expression* that
1849
  results from interpreting its *constraint-logical-or-expression* as a
1850
  *constraint-expression*.
1851
 
 
2007
 
2008
  ### Ambiguity resolution <a id="dcl.ambig.res">[[dcl.ambig.res]]</a>
2009
 
2010
  The ambiguity arising from the similarity between a function-style cast
2011
  and a declaration mentioned in  [[stmt.ambig]] can also occur in the
2012
+ context of a declaration. In that context, the choice is between an
2013
+ object declaration with a function-style cast as the initializer and a
2014
+ declaration involving a function declarator with a redundant set of
2015
+ parentheses around a parameter name. Just as for the ambiguities
2016
+ mentioned in  [[stmt.ambig]], the resolution is to consider any
2017
+ construct, such as the potential parameter declaration, that could
2018
+ possibly be a declaration to be a declaration.
2019
 
2020
  [*Note 1*: A declaration can be explicitly disambiguated by adding
2021
  parentheses around the argument. The ambiguity can be avoided by use of
2022
  copy-initialization or list-initialization syntax, or by use of a
2023
  non-function-style cast. — *end note*]
 
2100
 
2101
  — *end example*]
2102
 
2103
  ### Meaning of declarators <a id="dcl.meaning">[[dcl.meaning]]</a>
2104
 
2105
+ #### General <a id="dcl.meaning.general">[[dcl.meaning.general]]</a>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2106
 
2107
+ A declarator contains exactly one *declarator-id*; it names the entity
2108
+ that is declared. If the *unqualified-id* occurring in a *declarator-id*
2109
+ is a *template-id*, the declarator shall appear in the *declaration* of
2110
+ a *template-declaration* [[temp.decls]], *explicit-specialization*
2111
+ [[temp.expl.spec]], or *explicit-instantiation* [[temp.explicit]].
2112
+
2113
+ [*Note 1*: An *unqualified-id* that is not an *identifier* is used to
2114
+ declare certain functions
2115
+ [[class.conv.fct]], [[class.dtor]], [[over.oper]], [[over.literal]]. — *end note*]
2116
 
2117
  The optional *attribute-specifier-seq* following a *declarator-id*
2118
  appertains to the entity that is declared.
2119
 
2120
+ If the declaration is a friend declaration:
2121
+
2122
+ - The *declarator* does not bind a name.
2123
+ - If the *id-expression* E in the *declarator-id* of the *declarator* is
2124
+ a *qualified-id* or a *template-id*:
2125
+ - If the friend declaration is not a template declaration, then in the
2126
+ lookup for the terminal name of E:
2127
+ - if the *unqualified-id* in E is a *template-id*, all function
2128
+ declarations are discarded;
2129
+ - otherwise, if the *declarator* corresponds [[basic.scope.scope]]
2130
+ to any declaration found of a non-template function, all function
2131
+ template declarations are discarded;
2132
+ - each remaining function template is replaced with the
2133
+ specialization chosen by deduction from the friend declaration
2134
+ [[temp.deduct.decl]] or discarded if deduction fails.
2135
+ - The *declarator* shall correspond to one or more declarations found
2136
+ by the lookup; they shall all have the same target scope, and the
2137
+ target scope of the *declarator* is that scope.
2138
+ - Otherwise, the terminal name of E is not looked up. The declaration’s
2139
+ target scope is the innermost enclosing namespace scope; if the
2140
+ declaration is contained by a block scope, the declaration shall
2141
+ correspond to a reachable [[module.reach]] declaration that inhabits
2142
+ the innermost block scope.
2143
+
2144
+ Otherwise:
2145
+
2146
+ - If the *id-expression* in the *declarator-id* of the *declarator* is a
2147
+ *qualified-id* Q, let S be its lookup context [[basic.lookup.qual]];
2148
+ the declaration shall inhabit a namespace scope.
2149
+ - Otherwise, let S be the entity associated with the scope inhabited by
2150
+ the *declarator*.
2151
+ - If the *declarator* declares an explicit instantiation or a partial or
2152
+ explicit specialization, the *declarator* does not bind a name. If it
2153
+ declares a class member, the terminal name of the *declarator-id* is
2154
+ not looked up; otherwise, only those lookup results that are nominable
2155
+ in S are considered when identifying any function template
2156
+ specialization being declared [[temp.deduct.decl]].
2157
+ \[*Example 1*:
2158
+ ``` cpp
2159
+ namespace N {
2160
+ inline namespace O {
2161
+ template<class T> void f(T); // #1
2162
+ template<class T> void g(T) {}
2163
+ }
2164
+ namespace P {
2165
+ template<class T> void f(T*); // #2, more specialized than #1
2166
+ template<class> int g;
2167
+ }
2168
+ using P::f,P::g;
2169
+ }
2170
+ template<> void N::f(int*) {} // OK, #2 is not nominable
2171
+ template void N::g(int); // error: lookup is ambiguous
2172
+ ```
2173
+
2174
+ — *end example*]
2175
+ - Otherwise, the terminal name of the *declarator-id* is not looked up.
2176
+ If it is a qualified name, the *declarator* shall correspond to one or
2177
+ more declarations nominable in S; all the declarations shall have the
2178
+ same target scope and the target scope of the *declarator* is that
2179
+ scope.
2180
+ \[*Example 2*:
2181
+ ``` cpp
2182
+ namespace Q {
2183
+ namespace V {
2184
+ void f();
2185
+ }
2186
+ void V::f() { ... } // OK
2187
+ void V::g() { ... } // error: g() is not yet a member of V
2188
+ namespace V {
2189
+ void g();
2190
+ }
2191
+ }
2192
+
2193
+ namespace R {
2194
+ void Q::V::g() { ... } // error: R doesn't enclose Q
2195
+ }
2196
+ ```
2197
+
2198
+ — *end example*]
2199
+ - If the declaration inhabits a block scope S and declares a function
2200
+ [[dcl.fct]] or uses the `extern` specifier, the declaration shall not
2201
+ be attached to a named module [[module.unit]]; its target scope is the
2202
+ innermost enclosing namespace scope, but the name is bound in S.
2203
+ \[*Example 3*:
2204
+ ``` cpp
2205
+ namespace X {
2206
+ void p() {
2207
+ q(); // error: q not yet declared
2208
+ extern void q(); // q is a member of namespace X
2209
+ extern void r(); // r is a member of namespace X
2210
+ }
2211
+
2212
+ void middle() {
2213
+ q(); // error: q not found
2214
+ }
2215
+
2216
+ void q() { ... } // definition of X::q
2217
+ }
2218
+
2219
+ void q() { ... } // some other, unrelated q
2220
+ void X::r() { ... } // error: r cannot be declared by qualified-id
2221
+ ```
2222
+
2223
+ — *end example*]
2224
+
2225
  A `static`, `thread_local`, `extern`, `mutable`, `friend`, `inline`,
2226
+ `virtual`, `constexpr`, `consteval`, `constinit`, or `typedef` specifier
2227
+ or an *explicit-specifier* applies directly to each *declarator-id* in a
2228
+ declaration; the type specified for each *declarator-id* depends on both
2229
+ the *decl-specifier-seq* and its *declarator*.
 
2230
 
2231
+ Thus, (for each *declarator*) a declaration has the form
2232
 
2233
  ``` cpp
2234
  T D
2235
  ```
2236
 
 
2245
  T D
2246
  ```
2247
 
2248
  the *decl-specifier-seq* `T` determines the type `T`.
2249
 
2250
+ [*Example 4*:
2251
 
2252
  In the declaration
2253
 
2254
  ``` cpp
2255
  int unsigned i;
 
2259
  [[dcl.type.simple]].
2260
 
2261
  — *end example*]
2262
 
2263
  In a declaration *attribute-specifier-seq*ₒₚₜ `T` `D` where `D` is an
2264
+ unadorned name, the type of the declared entity is “`T`”.
2265
 
2266
  In a declaration `T` `D` where `D` has the form
2267
 
2268
  ``` bnf
2269
  '(' 'D1' ')'
 
2285
 
2286
  ``` bnf
2287
  '*' attribute-specifier-seqₒₚₜ cv-qualifier-seqₒₚₜ 'D1'
2288
  ```
2289
 
2290
+ and the type of the contained *declarator-id* in the declaration `T`
2291
+ `D1` is “*derived-declarator-type-list* `T`”, the type of the
2292
+ *declarator-id* in `D` is “*derived-declarator-type-list*
2293
+ *cv-qualifier-seq* pointer to `T`”. The *cv-qualifier*s apply to the
2294
+ pointer and not to the object pointed to. Similarly, the optional
2295
+ *attribute-specifier-seq* [[dcl.attr.grammar]] appertains to the pointer
2296
+ and not to the object pointed to.
2297
 
2298
  [*Example 1*:
2299
 
2300
  The declarations
2301
 
 
2359
  ``` bnf
2360
  '&' attribute-specifier-seqₒₚₜ 'D1'
2361
  '&&' attribute-specifier-seqₒₚₜ 'D1'
2362
  ```
2363
 
2364
+ and the type of the contained *declarator-id* in the declaration `T`
2365
+ `D1` is “*derived-declarator-type-list* `T`”, the type of the
2366
+ *declarator-id* in `D` is “*derived-declarator-type-list* reference to
2367
+ `T`”. The optional *attribute-specifier-seq* appertains to the reference
2368
+ type. Cv-qualified references are ill-formed except when the
2369
+ cv-qualifiers are introduced through the use of a *typedef-name*
2370
+ [[dcl.typedef]], [[temp.param]] or *decltype-specifier*
2371
+ [[dcl.type.decltype]], in which case the cv-qualifiers are ignored.
2372
 
2373
  [*Example 1*:
2374
 
2375
  ``` cpp
2376
  typedef int& A;
 
2459
  would be to bind it to the “object” obtained by indirection through a
2460
  null pointer, which causes undefined behavior. As described in 
2461
  [[class.bit]], a reference cannot be bound directly to a
2462
  bit-field. — *end note*]
2463
 
2464
+ If a *typedef-name* [[dcl.typedef]], [[temp.param]] or a
2465
+ *decltype-specifier* [[dcl.type.decltype]] denotes a type `TR` that is a
2466
  reference to a type `T`, an attempt to create the type “lvalue reference
2467
  to cv `TR`” creates the type “lvalue reference to `T`”, while an attempt
2468
  to create the type “rvalue reference to cv `TR`” creates the type `TR`.
2469
 
2470
  [*Note 3*: This rule is known as reference collapsing. — *end note*]
 
2493
  function type has *cv-qualifier*s or a *ref-qualifier*; see 
2494
  [[dcl.fct]]. — *end note*]
2495
 
2496
  #### Pointers to members <a id="dcl.mptr">[[dcl.mptr]]</a>
2497
 
2498
+ The component names of a *ptr-operator* are those of its
2499
+ *nested-name-specifier*, if any.
2500
+
2501
  In a declaration `T` `D` where `D` has the form
2502
 
2503
  ``` bnf
2504
  nested-name-specifier '*' attribute-specifier-seqₒₚₜ cv-qualifier-seqₒₚₜ 'D1'
2505
  ```
2506
 
2507
  and the *nested-name-specifier* denotes a class, and the type of the
2508
+ contained *declarator-id* in the declaration `T` `D1` is
2509
+ “*derived-declarator-type-list* `T`”, the type of the *declarator-id* in
2510
  `D` is “*derived-declarator-type-list* *cv-qualifier-seq* pointer to
2511
  member of class *nested-name-specifier* of type `T`”. The optional
2512
  *attribute-specifier-seq* [[dcl.attr.grammar]] appertains to the
2513
  pointer-to-member.
2514
 
 
2583
  A type of the form “array of `N` `U`” or “array of unknown bound of `U`”
2584
  is an *array type*. The optional *attribute-specifier-seq* appertains to
2585
  the array type.
2586
 
2587
  `U` is called the array *element type*; this type shall not be a
2588
+ reference type, a function type, an array of unknown bound, or
2589
+ cv `void`.
2590
 
2591
  [*Note 1*: An array can be constructed from one of the fundamental
2592
  types (except `void`), from a pointer, from a pointer to member, from a
2593
  class, from an enumeration type, or from an array of known
2594
  bound. — *end note*]
 
2619
  — *end example*]
2620
 
2621
  [*Note 2*: An “array of `N` *cv-qualifier-seq* `U`” has cv-qualified
2622
  type; see  [[basic.type.qualifier]]. — *end note*]
2623
 
2624
+ An object of type “array of `N` `U`” consists of a contiguously
2625
+ allocated non-empty set of `N` subobjects of type `U`, known as the
2626
+ *elements* of the array, and numbered `0` to `N-1`.
2627
 
2628
  In addition to declarations in which an incomplete object type is
2629
  allowed, an array bound may be omitted in some cases in the declaration
2630
  of a function parameter [[dcl.fct]]. An array bound may also be omitted
2631
  when an object (but not a non-static data member) of array type is
2632
+ initialized and the declarator is followed by an initializer
2633
+ [[dcl.init]], [[class.mem]], [[expr.type.conv]], [[expr.new]]. In these
2634
  cases, the array bound is calculated from the number of initial elements
2635
  (say, `N`) supplied [[dcl.init.aggr]], and the type of the array is
2636
  “array of `N` `U`”.
2637
 
2638
+ Furthermore, if there is a reachable declaration of the entity that
2639
+ inhabits the same scope in which the bound was specified, an omitted
2640
+ array bound is taken to be the same as in that earlier declaration, and
2641
+ similarly for the definition of a static data member of a class.
2642
 
2643
  [*Example 3*:
2644
 
2645
  ``` cpp
2646
  extern int x[10];
2647
  struct S {
2648
  static int y[10];
2649
  };
2650
 
2651
+ int x[]; // OK, bound is 10
2652
+ int S::y[]; // OK, bound is 10
2653
 
2654
  void f() {
2655
  extern int x[];
2656
  int i = sizeof(x); // error: incomplete object type
2657
  }
 
2661
 
2662
  [*Note 3*:
2663
 
2664
  When several “array of” specifications are adjacent, a multidimensional
2665
  array type is created; only the first of the constant expressions that
2666
+ specify the bounds of the arrays can be omitted.
2667
 
2668
  [*Example 4*:
2669
 
2670
  ``` cpp
2671
  int x3d[3][5][7];
 
2763
  parameter-declaration-list ',' parameter-declaration
2764
  ```
2765
 
2766
  ``` bnf
2767
  parameter-declaration:
2768
+ attribute-specifier-seqₒₚₜ thisₒₚₜ decl-specifier-seq declarator
2769
  attribute-specifier-seqₒₚₜ decl-specifier-seq declarator '=' initializer-clause
2770
+ attribute-specifier-seqₒₚₜ thisₒₚₜ decl-specifier-seq abstract-declaratorₒₚₜ
2771
  attribute-specifier-seqₒₚₜ decl-specifier-seq abstract-declaratorₒₚₜ '=' initializer-clause
2772
  ```
2773
 
2774
  The optional *attribute-specifier-seq* in a *parameter-declaration*
2775
  appertains to the parameter.
 
2818
  accessing arguments passed using the ellipsis (see  [[expr.call]] and 
2819
  [[support.runtime]]). — *end note*]
2820
 
2821
  The type of a function is determined using the following rules. The type
2822
  of each parameter (including function parameter packs) is determined
2823
+ from its own *parameter-declaration* [[dcl.decl]]. After determining the
2824
+ type of each parameter, any parameter of type “array of `T`” or of
2825
  function type `T` is adjusted to be “pointer to `T`”. After producing
2826
  the list of parameter types, any top-level *cv-qualifier*s modifying a
2827
  parameter type are deleted when forming the function type. The resulting
2828
  list of transformed parameter types and the presence or absence of the
2829
  ellipsis or a function parameter pack is the function’s
 
2831
 
2832
  [*Note 3*: This transformation does not affect the types of the
2833
  parameters. For example, `int(*)(const int p, decltype(p)*)` and
2834
  `int(*)(int, const int*)` are identical types. — *end note*]
2835
 
2836
+ [*Example 2*:
2837
+
2838
+ ``` cpp
2839
+ void f(char*); // #1
2840
+ void f(char[]) {} // defines #1
2841
+ void f(const char*) {} // OK, another overload
2842
+ void f(char *const) {} // error: redefines #1
2843
+
2844
+ void g(char(*)[2]); // #2
2845
+ void g(char[3][2]) {} // defines #2
2846
+ void g(char[3][3]) {} // OK, another overload
2847
+
2848
+ void h(int x(const int)); // #3
2849
+ void h(int (*)(int)) {} // defines #3
2850
+ ```
2851
+
2852
+ — *end example*]
2853
+
2854
+ An *explicit-object-parameter-declaration* is a *parameter-declaration*
2855
+ with a `this` specifier. An explicit-object-parameter-declaration shall
2856
+ appear only as the first *parameter-declaration* of a
2857
+ *parameter-declaration-list* of either:
2858
+
2859
+ - a *member-declarator* that declares a member function [[class.mem]],
2860
+ or
2861
+ - a *lambda-declarator* [[expr.prim.lambda]].
2862
+
2863
+ A *member-declarator* with an explicit-object-parameter-declaration
2864
+ shall not include a *ref-qualifier* or a *cv-qualifier-seq* and shall
2865
+ not be declared `static` or `virtual`.
2866
+
2867
+ [*Example 3*:
2868
+
2869
+ ``` cpp
2870
+ struct C {
2871
+ void f(this C& self);
2872
+ template <typename Self> void g(this Self&& self, int);
2873
+
2874
+ void h(this C) const; // error: const not allowed here
2875
+ };
2876
+
2877
+ void test(C c) {
2878
+ c.f(); // OK, calls C::f
2879
+ c.g(42); // OK, calls C::g<C&>
2880
+ std::move(c).g(42); // OK, calls C::g<C>
2881
+ }
2882
+ ```
2883
+
2884
+ — *end example*]
2885
+
2886
+ A function parameter declared with an
2887
+ explicit-object-parameter-declaration is an *explicit object parameter*.
2888
+ An explicit object parameter shall not be a function parameter pack
2889
+ [[temp.variadic]]. An *explicit object member function* is a non-static
2890
+ member function with an explicit object parameter. An
2891
+ *implicit object member function* is a non-static member function
2892
+ without an explicit object parameter.
2893
+
2894
+ The *object parameter* of a non-static member function is either the
2895
+ explicit object parameter or the implicit object parameter
2896
+ [[over.match.funcs]].
2897
+
2898
+ A *non-object parameter* is a function parameter that is not the
2899
+ explicit object parameter. The *non-object-parameter-type-list* of a
2900
+ member function is the parameter-type-list of that function with the
2901
+ explicit object parameter, if any, omitted.
2902
+
2903
+ [*Note 4*: The non-object-parameter-type-list consists of the adjusted
2904
+ types of all the non-object parameters. — *end note*]
2905
+
2906
  A function type with a *cv-qualifier-seq* or a *ref-qualifier*
2907
+ (including a type named by *typedef-name*
2908
+ [[dcl.typedef]], [[temp.param]]) shall appear only as:
2909
 
2910
  - the function type for a non-static member function,
2911
  - the function type to which a pointer to member refers,
2912
  - the top-level function type of a function typedef declaration or
2913
  *alias-declaration*,
2914
  - the *type-id* in the default argument of a *type-parameter*
2915
  [[temp.param]], or
2916
  - the *type-id* of a *template-argument* for a *type-parameter*
2917
  [[temp.arg.type]].
2918
 
2919
+ [*Example 4*:
2920
 
2921
  ``` cpp
2922
  typedef int FIC(int) const;
2923
  FIC f; // error: does not declare a member function
2924
  struct S {
 
2931
 
2932
  The effect of a *cv-qualifier-seq* in a function declarator is not the
2933
  same as adding cv-qualification on top of the function type. In the
2934
  latter case, the cv-qualifiers are ignored.
2935
 
2936
+ [*Note 5*: A function type that has a *cv-qualifier-seq* is not a
2937
  cv-qualified type; there are no cv-qualified function
2938
  types. — *end note*]
2939
 
2940
+ [*Example 5*:
2941
 
2942
  ``` cpp
2943
  typedef void F();
2944
  struct S {
2945
+ const F f; // OK, equivalent to: void f();
2946
  };
2947
  ```
2948
 
2949
  — *end example*]
2950
 
2951
  The return type, the parameter-type-list, the *ref-qualifier*, the
2952
  *cv-qualifier-seq*, and the exception specification, but not the default
2953
  arguments [[dcl.fct.default]] or the trailing *requires-clause*
2954
  [[dcl.decl]], are part of the function type.
2955
 
2956
+ [*Note 6*: Function types are checked during the assignments and
2957
  initializations of pointers to functions, references to functions, and
2958
  pointers to member functions. — *end note*]
2959
 
2960
+ [*Example 6*:
2961
 
2962
  The declaration
2963
 
2964
  ``` cpp
2965
  int fseek(FILE*, long, int);
 
2968
  declares a function taking three arguments of the specified types, and
2969
  returning `int` [[dcl.type]].
2970
 
2971
  — *end example*]
2972
 
2973
+ [*Note 7*: A single name can be used for several different functions in
2974
+ a single scope; this is function overloading [[over]]. *end note*]
 
 
2975
 
2976
+ The return type shall be a non-array object type, a reference type, or
2977
+ cv `void`.
2978
+
2979
+ [*Note 8*: An array of placeholder type is considered an array
2980
+ type. — *end note*]
2981
 
2982
  A volatile-qualified return type is deprecated; see 
2983
  [[depr.volatile.type]].
2984
 
2985
  Types shall not be defined in return or parameter types.
2986
 
2987
  A typedef of function type may be used to declare a function but shall
2988
  not be used to define a function [[dcl.fct.def]].
2989
 
2990
+ [*Example 7*:
2991
 
2992
  ``` cpp
2993
  typedef void F();
2994
+ F fv; // OK, equivalent to void fv();
2995
  F fv { } // error
2996
+ void fv() { } // OK, definition of fv
2997
  ```
2998
 
2999
  — *end example*]
3000
 
3001
  An identifier can optionally be provided as a parameter name; if present
3002
  in a function definition [[dcl.fct.def]], it names a parameter.
3003
 
3004
+ [*Note 9*: In particular, parameter names are also optional in function
3005
  definitions and names used for a parameter in different declarations and
3006
+ the definition of a function need not be the same. *end note*]
 
 
 
3007
 
3008
+ [*Example 8*:
3009
 
3010
  The declaration
3011
 
3012
  ``` cpp
3013
  int i,
 
3033
  to indicate that indirection through a pointer to a function yields a
3034
  function, which is then called.
3035
 
3036
  — *end example*]
3037
 
3038
+ [*Note 10*:
3039
 
3040
  Typedefs and *trailing-return-type*s are sometimes convenient when the
3041
  return type of a function is complex. For example, the function `fpif`
3042
+ above can be declared
3043
 
3044
  ``` cpp
3045
  typedef int IFUNC(int);
3046
  IFUNC* fpif(int);
3047
  ```
 
3068
  — *end note*]
3069
 
3070
  A *non-template function* is a function that is not a function template
3071
  specialization.
3072
 
3073
+ [*Note 11*: A function template is not a function. — *end note*]
3074
 
3075
  An *abbreviated function template* is a function declaration that has
3076
  one or more generic parameter type placeholders [[dcl.spec.auto]]. An
3077
  abbreviated function template is equivalent to a function template
3078
  [[temp.fct]] whose *template-parameter-list* includes one invented type
 
3081
  *placeholder-type-specifier* of the form `auto`, the invented parameter
3082
  is an unconstrained *type-parameter*. For a *placeholder-type-specifier*
3083
  of the form *type-constraint* `auto`, the invented parameter is a
3084
  *type-parameter* with that *type-constraint*. The invented type
3085
  *template-parameter* is a template parameter pack if the corresponding
3086
+ *parameter-declaration* declares a function parameter pack. If the
3087
+ placeholder contains `decltype(auto)`, the program is ill-formed. The
3088
+ adjusted function parameters of an abbreviated function template are
3089
  derived from the *parameter-declaration-clause* by replacing each
3090
  occurrence of a placeholder with the name of the corresponding invented
3091
  *template-parameter*.
3092
 
3093
+ [*Example 9*:
3094
 
3095
  ``` cpp
3096
  template<typename T> concept C1 = /* ... */;
3097
  template<typename T> concept C2 = /* ... */;
3098
  template<typename... Ts> concept C3 = /* ... */;
 
3101
  void g2(C1 auto&...);
3102
  void g3(C3 auto...);
3103
  void g4(C3 auto);
3104
  ```
3105
 
3106
+ The declarations above are functionally equivalent (but not equivalent)
3107
+ to their respective declarations below:
3108
 
3109
  ``` cpp
3110
  template<C1 T, C2 U> void g1(const T*, U&);
3111
  template<C1... Ts> void g2(Ts&...);
3112
  template<C3... Ts> void g3(Ts...);
 
3121
  ```
3122
 
3123
  — *end example*]
3124
 
3125
  An abbreviated function template can have a *template-head*. The
3126
+ invented *template-parameter*s are appended to the
3127
  *template-parameter-list* after the explicitly declared
3128
+ *template-parameter*s.
3129
 
3130
+ [*Example 10*:
3131
 
3132
  ``` cpp
3133
  template<typename> concept C = /* ... */;
3134
 
3135
  template <typename T, C U>
 
3159
  function parameter pack [[temp.variadic]]. Otherwise, the
3160
  *parameter-declaration* is part of a *template-parameter-list* and
3161
  declares a template parameter pack; see  [[temp.param]]. A function
3162
  parameter pack is a pack expansion [[temp.variadic]].
3163
 
3164
+ [*Example 11*:
3165
 
3166
  ``` cpp
3167
  template<typename... T> void f(T (* ...t)(int, int));
3168
 
3169
  int add(int, int);
 
3219
  template parameter pack or a function parameter pack. If it is specified
3220
  in a *parameter-declaration-clause*, it shall not occur within a
3221
  *declarator* or *abstract-declarator* of a *parameter-declaration*.[^4]
3222
 
3223
  For non-template functions, default arguments can be added in later
3224
+ declarations of a function that inhabit the same scope. Declarations
3225
+ that inhabit different scopes have completely distinct sets of default
3226
+ arguments. That is, declarations in inner scopes do not acquire default
3227
+ arguments from declarations in outer scopes, and vice versa. In a given
3228
+ function declaration, each parameter subsequent to a parameter with a
3229
+ default argument shall have a default argument supplied in this or a
3230
+ previous declaration, unless the parameter was expanded from a parameter
3231
+ pack, or shall be a function parameter pack.
3232
 
3233
  [*Note 2*: A default argument cannot be redefined by a later
3234
  declaration (not even to the same value)
3235
  [[basic.def.odr]]. — *end note*]
3236
 
 
3264
  — *end example*]
3265
 
3266
  For a given inline function defined in different translation units, the
3267
  accumulated sets of default arguments at the end of the translation
3268
  units shall be the same; no diagnostic is required. If a friend
3269
+ declaration D specifies a default argument expression, that declaration
3270
+ shall be a definition and there shall be no other declaration of the
3271
+ function or function template which is reachable from D or from which D
3272
+ is reachable.
3273
 
3274
  The default argument has the same semantic constraints as the
3275
  initializer in a declaration of a variable of the parameter type, using
3276
  the copy-initialization semantics [[dcl.init]]. The names in the default
3277
+ argument are looked up, and the semantic constraints are checked, at the
3278
+ point where the default argument appears, except that an immediate
3279
+ invocation [[expr.const]] that is a potentially-evaluated subexpression
3280
+ [[intro.execution]] of the *initializer-clause* in a
3281
+ *parameter-declaration* is neither evaluated nor checked for whether it
3282
+ is a constant expression at that point. Name lookup and checking of
3283
+ semantic constraints for default arguments of templated functions are
3284
+ performed as described in  [[temp.inst]].
3285
 
3286
  [*Example 3*:
3287
 
3288
  In the following code, `g` will be called with the value `f(2)`:
3289
 
 
3301
  }
3302
  ```
3303
 
3304
  — *end example*]
3305
 
3306
+ [*Note 3*: A default argument is a complete-class context
3307
+ [[class.mem]]. Access checking applies to names in default arguments as
3308
+ described in [[class.access]]. *end note*]
 
3309
 
3310
  Except for member functions of class templates, the default arguments in
3311
  a member function definition that appears outside of the class
3312
  definition are added to the set of default arguments provided by the
3313
  member function declaration in the class definition; the program is
 
3324
  void f(int i = 3);
3325
  void g(int i, int j = 99);
3326
  };
3327
 
3328
  void C::f(int i = 3) {} // error: default argument already specified in class scope
3329
+ void C::g(int i = 88, int j) {} // in this translation unit, C::g can be called with no arguments
3330
  ```
3331
 
3332
  — *end example*]
3333
 
3334
+ [*Note 4*: A local variable cannot be odr-used [[term.odr.use]] in a
3335
  default argument. — *end note*]
3336
 
3337
  [*Example 5*:
3338
 
3339
  ``` cpp
 
3347
 
3348
  — *end example*]
3349
 
3350
  [*Note 5*:
3351
 
3352
+ The keyword `this` cannot appear in a default argument of a member
3353
  function; see  [[expr.prim.this]].
3354
 
3355
  [*Example 6*:
3356
 
3357
  ``` cpp
 
3364
 
3365
  — *end note*]
3366
 
3367
  A default argument is evaluated each time the function is called with no
3368
  argument for the corresponding parameter. A parameter shall not appear
3369
+ as a potentially-evaluated expression in a default argument.
3370
+
3371
+ [*Note 6*: Parameters of a function declared before a default argument
3372
+ are in scope and can hide namespace and class member
3373
+ names. — *end note*]
3374
 
3375
  [*Example 7*:
3376
 
3377
  ``` cpp
3378
  int a;
3379
  int f(int a, int b = a); // error: parameter a used as default argument
3380
  typedef int I;
3381
  int g(float I, int b = I(2)); // error: parameter I found
3382
+ int h(int a, int b = sizeof(a)); // OK, unevaluated operand[term.unevaluated.operand]
3383
  ```
3384
 
3385
  — *end example*]
3386
 
3387
  A non-static member shall not appear in a default argument unless it
 
3427
  int (*p2)() = &f; // error: type mismatch
3428
  ```
3429
 
3430
  — *end example*]
3431
 
3432
+ When an overload set contains a declaration of a function that inhabits
3433
+ a scope S, any default argument associated with any reachable
3434
+ declaration that inhabits S is available to the call.
3435
+
3436
+ [*Note 7*: The candidate might have been found through a
3437
+ *using-declarator* from which the declaration that provides the default
3438
+ argument is not reachable. — *end note*]
3439
 
3440
  A virtual function call [[class.virtual]] uses the default arguments in
3441
  the declaration of the virtual function determined by the static type of
3442
  the pointer or reference denoting the object. An overriding function in
3443
  a derived class does not acquire default arguments from the function it
 
3462
 
3463
  — *end example*]
3464
 
3465
  ## Initializers <a id="dcl.init">[[dcl.init]]</a>
3466
 
3467
+ ### General <a id="dcl.init.general">[[dcl.init.general]]</a>
3468
+
3469
+ The process of initialization described in [[dcl.init]] applies to all
3470
  initializations regardless of syntactic context, including the
3471
  initialization of a function parameter [[expr.call]], the initialization
3472
  of a return value [[stmt.return]], or when an initializer follows a
3473
  declarator.
3474
 
 
3523
  expr-or-braced-init-list:
3524
  expression
3525
  braced-init-list
3526
  ```
3527
 
3528
+ [*Note 1*: The rules in [[dcl.init]] apply even if the grammar permits
3529
+ only the *brace-or-equal-initializer* form of *initializer* in a given
3530
+ context. — *end note*]
3531
 
3532
  Except for objects declared with the `constexpr` specifier, for which
3533
  see  [[dcl.constexpr]], an *initializer* in the definition of a variable
3534
  can consist of arbitrary expressions involving literals and previously
3535
  declared variables and functions, regardless of the variable’s storage
 
3551
 
3552
  [*Note 3*: The order of initialization of variables with static storage
3553
  duration is described in  [[basic.start]] and 
3554
  [[stmt.dcl]]. — *end note*]
3555
 
3556
+ A declaration D of a variable with linkage shall not have an
3557
+ *initializer* if D inhabits a block scope.
3558
 
3559
  To *zero-initialize* an object or reference of type `T` means:
3560
 
3561
+ - if `T` is a scalar type [[term.scalar.type]], the object is
3562
+ initialized to the value obtained by converting the integer literal
3563
+ `0` (zero) to `T`;[^5]
3564
  - if `T` is a (possibly cv-qualified) non-union class type, its padding
3565
+ bits [[term.padding.bits]] are initialized to zero bits and each
3566
+ non-static data member, each non-virtual base class subobject, and, if
3567
+ the object is not a base class subobject, each virtual base class
3568
+ subobject is zero-initialized;
3569
  - if `T` is a (possibly cv-qualified) union type, its padding bits
3570
+ [[term.padding.bits]] are initialized to zero bits and the object’s
3571
+ first non-static named data member is zero-initialized;
3572
  - if `T` is an array type, each element is zero-initialized;
3573
  - if `T` is a reference type, no initialization is performed.
3574
 
3575
  To *default-initialize* an object of type `T` means:
3576
 
 
3620
  [*Note 4*: For every object of static storage duration, static
3621
  initialization [[basic.start.static]] is performed at program startup
3622
  before any other initialization takes place. In some cases, additional
3623
  initialization is done later. — *end note*]
3624
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3625
  If no initializer is specified for an object, the object is
3626
  default-initialized.
3627
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3628
  If the entity being initialized does not have class type, the
3629
  *expression-list* in a parenthesized initializer shall be a single
3630
  expression.
3631
 
3632
  The initialization that occurs in the `=` form of a
3633
  *brace-or-equal-initializer* or *condition* [[stmt.select]], as well as
3634
  in argument passing, function return, throwing an exception
3635
  [[except.throw]], handling an exception [[except.handle]], and aggregate
3636
+ member initialization other than by a *designated-initializer-clause*
3637
+ [[dcl.init.aggr]], is called *copy-initialization*.
3638
 
3639
+ [*Note 5*: Copy-initialization can invoke a move
3640
  [[class.copy.ctor]]. — *end note*]
3641
 
3642
  The initialization that occurs
3643
 
3644
  - for an *initializer* that is a parenthesized *expression-list* or a
 
3663
  - If the destination type is an array of characters, an array of
3664
  `char8_t`, an array of `char16_t`, an array of `char32_t`, or an array
3665
  of `wchar_t`, and the initializer is a *string-literal*, see 
3666
  [[dcl.init.string]].
3667
  - If the initializer is `()`, the object is value-initialized.
3668
+ \[*Note 6*:
3669
+ Since `()` is not permitted by the syntax for *initializer*,
3670
+ ``` cpp
3671
+ X a();
3672
+ ```
3673
+
3674
+ is not the declaration of an object of class `X`, but the declaration
3675
+ of a function taking no arguments and returning an `X`. The form `()`
3676
+ is permitted in certain other initialization contexts
3677
+ [[expr.new]], [[expr.type.conv]], [[class.base.init]].
3678
+ — *end note*]
3679
  - Otherwise, if the destination type is an array, the object is
3680
  initialized as follows. Let x₁, …, xₖ be the elements of the
3681
  *expression-list*. If the destination type is an array of unknown
3682
  bound, it is defined as having k elements. Let n denote the array size
3683
  after this potential adjustment. If k is greater than n, the program
 
3690
  - Otherwise, if the destination type is a (possibly cv-qualified) class
3691
  type:
3692
  - If the initializer expression is a prvalue and the cv-unqualified
3693
  version of the source type is the same class as the class of the
3694
  destination, the initializer expression is used to initialize the
3695
+ destination object. \[*Example 2*: `T x = T(T(T()));`
3696
+ value-initializes `x`. — *end example*]
3697
  - Otherwise, if the initialization is direct-initialization, or if it
3698
  is copy-initialization where the cv-unqualified version of the
3699
  source type is the same class as, or a derived class of, the class
3700
  of the destination, constructors are considered. The applicable
3701
  constructors are enumerated [[over.match.ctor]], and the best one is
 
3718
  \[*Note 7*:
3719
  By contrast with direct-list-initialization, narrowing conversions
3720
  [[dcl.init.list]] are permitted, designators are not permitted, a
3721
  temporary object bound to a reference does not have its lifetime
3722
  extended [[class.temporary]], and there is no brace elision.
3723
+ \[*Example 3*:
3724
  ``` cpp
3725
  struct A {
3726
  int a;
3727
  int&& r;
3728
  };
 
3780
  int c = b;
3781
  ```
3782
 
3783
  — *end note*]
3784
 
3785
+ An immediate invocation [[expr.const]] that is not evaluated where it
3786
+ appears [[dcl.fct.default]], [[class.mem.general]] is evaluated and
3787
+ checked for whether it is a constant expression at the point where the
3788
+ enclosing *initializer* is used in a function call, a constructor
3789
+ definition, or an aggregate initialization.
3790
+
3791
  An *initializer-clause* followed by an ellipsis is a pack expansion
3792
  [[temp.variadic]].
3793
 
3794
+ Initialization includes the evaluation of all subexpressions of each
3795
+ *initializer-clause* of the initializer (possibly nested within
3796
+ *braced-init-list*s) and the creation of any temporary objects for
3797
+ function arguments or return values [[class.temporary]].
3798
+
3799
  If the initializer is a parenthesized *expression-list*, the expressions
3800
  are evaluated in the order specified for function calls [[expr.call]].
3801
 
3802
  The same *identifier* shall not appear in multiple *designator*s of a
3803
  *designated-initializer-list*.
 
3819
  from an explicit initializer or by default-initialization, is called the
3820
  *initializing declaration* of that variable.
3821
 
3822
  [*Note 10*: In most cases this is the defining declaration
3823
  [[basic.def]] of the variable, but the initializing declaration of a
3824
+ non-inline static data member [[class.static.data]] can be the
3825
+ declaration within the class definition and not the definition (if any)
3826
+ outside it. — *end note*]
3827
 
3828
  ### Aggregates <a id="dcl.init.aggr">[[dcl.init.aggr]]</a>
3829
 
3830
  An *aggregate* is an array or a class [[class]] with
3831
 
3832
  - no user-declared or inherited constructors [[class.ctor]],
3833
  - no private or protected direct non-static data members
3834
  [[class.access]],
3835
+ - no private or protected direct base classes [[class.access.base]], and
3836
+ - no virtual functions [[class.virtual]] or virtual base classes
3837
+ [[class.mi]].
3838
 
3839
  [*Note 1*: Aggregate initialization does not allow accessing protected
3840
  and private base class’ members or constructors. — *end note*]
3841
 
3842
  The *elements* of an aggregate are:
 
3849
  When an aggregate is initialized by an initializer list as specified in 
3850
  [[dcl.init.list]], the elements of the initializer list are taken as
3851
  initializers for the elements of the aggregate. The *explicitly
3852
  initialized elements* of the aggregate are determined as follows:
3853
 
3854
+ - If the initializer list is a brace-enclosed
3855
+ *designated-initializer-list*, the aggregate shall be of class type,
3856
+ the *identifier* in each *designator* shall name a direct non-static
3857
+ data member of the class, and the explicitly initialized elements of
3858
+ the aggregate are the elements that are, or contain, those members.
3859
+ - If the initializer list is a brace-enclosed *initializer-list*, the
3860
+ explicitly initialized elements of the aggregate are the first n
3861
+ elements of the aggregate, where n is the number of elements in the
3862
+ initializer list.
3863
  - Otherwise, the initializer list must be `{}`, and there are no
3864
  explicitly initialized elements.
3865
 
3866
  For each explicitly initialized element:
3867
 
3868
+ - If the element is an anonymous union member and the initializer list
3869
+ is a brace-enclosed *designated-initializer-list*, the element is
3870
+ initialized by the *braced-init-list* `{ `*D*` }`, where *D* is the
3871
+ *designated-initializer-clause* naming a member of the anonymous union
3872
+ member. There shall be only one such *designated-initializer-clause*.
 
3873
  \[*Example 1*:
3874
  ``` cpp
3875
  struct C {
3876
  union {
3877
  int a;
 
3888
  *brace-or-equal-initializer* of the corresponding
3889
  *designated-initializer-clause*. If that initializer is of the form
3890
  *assignment-expression* or `= `*assignment-expression* and a narrowing
3891
  conversion [[dcl.init.list]] is required to convert the expression,
3892
  the program is ill-formed.
3893
+ \[*Note 2*: If the initialization is by
3894
+ *designated-initializer-clause*, its form determines whether
3895
+ copy-initialization or direct-initialization is
3896
+ performed. — *end note*]
3897
+ \[*Note 3*: If an initializer is itself an initializer list, the
3898
  element is list-initialized, which will result in a recursive
3899
  application of the rules in this subclause if the element is an
3900
  aggregate. — *end note*]
3901
  \[*Example 2*:
3902
  ``` cpp
 
3992
 
3993
  The destructor for each element of class type is potentially invoked
3994
  [[class.dtor]] from the context where the aggregate initialization
3995
  occurs.
3996
 
3997
+ [*Note 4*: This provision ensures that destructors can be called for
3998
  fully-constructed subobjects in case an exception is thrown
3999
  [[except.ctor]]. — *end note*]
4000
 
4001
  An array of unknown bound initialized with a brace-enclosed
4002
  *initializer-list* containing `n` *initializer-clause*s is defined as
 
4014
  — *end example*]
4015
 
4016
  An array of unknown bound shall not be initialized with an empty
4017
  *braced-init-list* `{}`.[^6]
4018
 
4019
+ [*Note 5*:
4020
 
4021
  A default member initializer does not determine the bound for a member
4022
  array of unknown bound. Since the default member initializer is ignored
4023
  if a suitable *mem-initializer* is present [[class.base.init]], the
4024
  default member initializer is not considered to initialize the array of
 
4034
 
4035
  — *end example*]
4036
 
4037
  — *end note*]
4038
 
4039
+ [*Note 6*:
4040
 
4041
  Static data members, non-static data members of anonymous union members,
4042
  and unnamed bit-fields are not considered elements of the aggregate.
4043
 
4044
  [*Example 6*:
 
4121
  }; // Initialization not required for A::s3 because A::i3 is also not initialized
4122
  ```
4123
 
4124
  — *end example*]
4125
 
4126
+ When initializing a multidimensional array, the *initializer-clause*s
4127
  initialize the elements with the last (rightmost) index of the array
4128
  varying the fastest [[dcl.array]].
4129
 
4130
  [*Example 10*:
4131
 
 
4195
  *assignment-expression* can initialize an element, the element is
4196
  initialized. Otherwise, if the element is itself a subaggregate, brace
4197
  elision is assumed and the *assignment-expression* is considered for the
4198
  initialization of the first element of the subaggregate.
4199
 
4200
+ [*Note 7*: As specified above, brace elision cannot apply to
4201
  subaggregates with no elements; an *initializer-clause* for the entire
4202
  subobject is required. — *end note*]
4203
 
4204
  [*Example 12*:
4205
 
 
4220
  is initialized with 4, `b.a2` is initialized with `a`, `b.z` is
4221
  initialized with whatever `a.operator int()` returns.
4222
 
4223
  — *end example*]
4224
 
4225
+ [*Note 8*: An aggregate array or an aggregate class can contain
4226
  elements of a class type with a user-declared constructor
4227
  [[class.ctor]]. Initialization of these aggregate objects is described
4228
  in  [[class.expl.init]]. — *end note*]
4229
 
4230
+ [*Note 9*: Whether the initialization of aggregates with static storage
4231
  duration is static or dynamic is specified in  [[basic.start.static]],
4232
  [[basic.start.dynamic]], and  [[stmt.dcl]]. — *end note*]
4233
 
4234
  When a union is initialized with an initializer list, there shall not be
4235
  more than one explicitly initialized element.
 
4247
  u g = { .a = 1, .b = "asdf" }; // error
4248
  ```
4249
 
4250
  — *end example*]
4251
 
4252
+ [*Note 10*: As described above, the braces around the
4253
  *initializer-clause* for a union member can be omitted if the union is a
4254
  member of another aggregate. — *end note*]
4255
 
4256
  ### Character arrays <a id="dcl.init.string">[[dcl.init.string]]</a>
4257
 
4258
  An array of ordinary character type [[basic.fundamental]], `char8_t`
4259
+ array, `char16_t` array, `char32_t` array, or `wchar_t` array may be
4260
  initialized by an ordinary string literal, UTF-8 string literal, UTF-16
4261
  string literal, UTF-32 string literal, or wide string literal,
4262
  respectively, or by an appropriately-typed *string-literal* enclosed in
4263
+ braces [[lex.string]]. Additionally, an array of `char` or
4264
+ `unsigned char` may be initialized by a UTF-8 string literal, or by such
4265
+ a string literal enclosed in braces. Successive characters of the value
4266
+ of the *string-literal* initialize the elements of the array, with an
4267
+ integral conversion [[conv.integral]] if necessary for the source and
4268
+ destination value.
4269
 
4270
  [*Example 1*:
4271
 
4272
  ``` cpp
4273
  char msg[] = "Syntax error on line %s\n";
 
4295
  element not explicitly initialized shall be zero-initialized
4296
  [[dcl.init]].
4297
 
4298
  ### References <a id="dcl.init.ref">[[dcl.init.ref]]</a>
4299
 
4300
+ A variable whose declared type is “reference to `T`” [[dcl.ref]] shall
4301
+ be initialized.
4302
 
4303
  [*Example 1*:
4304
 
4305
  ``` cpp
4306
  int g(int) noexcept;
 
4365
  “*cv3* `T3`”, where “*cv1* `T1`” is reference-compatible with “*cv3*
4366
  `T3`”[^7] (this conversion is selected by enumerating the applicable
4367
  conversion functions [[over.match.ref]] and choosing the best one
4368
  through overload resolution [[over.match]]),
4369
 
4370
+ then the reference binds to the initializer expression lvalue in the
4371
+ first case and to the lvalue result of the conversion in the second
4372
+ case (or, in either case, to the appropriate base class subobject of
4373
+ the object).
4374
  \[*Note 2*: The usual lvalue-to-rvalue [[conv.lval]], array-to-pointer
4375
  [[conv.array]], and function-to-pointer [[conv.func]] standard
4376
  conversions are not needed, and therefore are suppressed, when such
4377
  direct bindings to lvalues are done. — *end note*]
4378
  \[*Example 3*:
 
4406
  - has a class type (i.e., `T2` is a class type), where `T1` is not
4407
  reference-related to `T2`, and can be converted to an rvalue or
4408
  function lvalue of type “*cv3* `T3`”, where “*cv1* `T1`” is
4409
  reference-compatible with “*cv3* `T3`” (see  [[over.match.ref]]),
4410
 
4411
+ then the initializer expression in the first case and the converted
4412
+ expression in the second case is called the converted initializer. If
4413
+ the converted initializer is a prvalue, its type `T4` is adjusted to
4414
+ type “*cv1* `T4`” [[conv.qual]] and the temporary materialization
4415
+ conversion [[conv.rval]] is applied. In any case, the reference binds
4416
+ to the resulting glvalue (or to an appropriate base class subobject).
 
4417
  \[*Example 5*:
4418
  ``` cpp
4419
  struct A { };
4420
  struct B : A { } b;
4421
  extern B f();
4422
+ const A& rca2 = f(); // binds to the A subobject of the B rvalue.
4423
  A&& rra = f(); // same as above
4424
  struct X {
4425
  operator B();
4426
  operator int&();
4427
  } x;
4428
+ const A& r = x; // binds to the A subobject of the result of the conversion
4429
  int i2 = 42;
4430
+ int&& rri = static_cast<int&&>(i2); // binds directly to i2
4431
+ B&& rrb = x; // binds directly to the result of operator B
4432
  ```
4433
 
4434
  — *end example*]
4435
  - Otherwise:
4436
  - If `T1` or `T2` is a class type and `T1` is not reference-related to
4437
  `T2`, user-defined conversions are considered using the rules for
4438
  copy-initialization of an object of type “*cv1* `T1`” by
4439
+ user-defined conversion
4440
+ [[dcl.init]], [[over.match.copy]], [[over.match.conv]]; the program
4441
+ is ill-formed if the corresponding non-reference copy-initialization
4442
+ would be ill-formed. The result of the call to the conversion
4443
+ function, as described for the non-reference copy-initialization, is
4444
+ then used to direct-initialize the reference. For this
4445
+ direct-initialization, user-defined conversions are not considered.
4446
  - Otherwise, the initializer expression is implicitly converted to a
4447
+ prvalue of type “`T1`”. The temporary materialization conversion is
4448
+ applied, considering the type of the prvalue to be “*cv1* `T1`”, and
4449
+ the reference is bound to the result.
4450
 
4451
  If `T1` is reference-related to `T2`:
4452
  - *cv1* shall be the same cv-qualification as, or greater
4453
  cv-qualification than, *cv2*; and
4454
  - if the reference is an rvalue reference, the initializer expression
4455
+ shall not be an lvalue. \[*Note 3*: This can be affected by whether
4456
+ the initializer expression is move-eligible
4457
+ [[expr.prim.id.unqual]]. — *end note*]
4458
 
4459
  \[*Example 6*:
4460
  ``` cpp
4461
  struct Banana { };
4462
  struct Enigma { operator const Banana(); };
 
4487
 
4488
  In all cases except the last (i.e., implicitly converting the
4489
  initializer expression to the referenced type), the reference is said to
4490
  *bind directly* to the initializer expression.
4491
 
4492
+ [*Note 4*: [[class.temporary]] describes the lifetime of temporaries
4493
  bound to references. — *end note*]
4494
 
4495
  ### List-initialization <a id="dcl.init.list">[[dcl.init.list]]</a>
4496
 
4497
  *List-initialization* is initialization of an object or reference from a
 
4513
  - as the initializer in a *new-expression* [[expr.new]]
4514
  - in a `return` statement [[stmt.return]]
4515
  - as a *for-range-initializer* [[stmt.iter]]
4516
  - as a function argument [[expr.call]]
4517
  - as a subscript [[expr.sub]]
4518
+ - as an argument to a constructor invocation
4519
+ [[dcl.init]], [[expr.type.conv]]
4520
  - as an initializer for a non-static data member [[class.mem]]
4521
  - in a *mem-initializer* [[class.base.init]]
4522
  - on the right-hand side of an assignment [[expr.ass]]
4523
 
4524
  [*Example 1*:
 
4550
  `template<class T> C(T)` of a class `C` does not create an
4551
  initializer-list constructor, because an initializer list argument
4552
  causes the corresponding parameter to be a non-deduced context
4553
  [[temp.deduct.call]]. — *end note*]
4554
 
4555
+ The template `std::initializer_list` is not predefined; if a standard
4556
+ library declaration [[initializer.list.syn]], [[std.modules]] of
4557
+ `std::initializer_list` is not reachable from [[module.reach]] a use of
4558
  `std::initializer_list` — even an implicit use in which the type is not
4559
  named [[dcl.spec.auto]] — the program is ill-formed.
4560
 
4561
  List-initialization of an object or reference of type `T` is defined as
4562
  follows:
 
4595
  int m1;
4596
  double m2, m3;
4597
  };
4598
  S2 s21 = { 1, 2, 3.0 }; // OK
4599
  S2 s22 { 1.0, 2, 3 }; // error: narrowing
4600
+ S2 s23 { }; // OK, default to 0,0,0
4601
  ```
4602
 
4603
  — *end example*]
4604
  - Otherwise, if the initializer list has no elements and `T` is a class
4605
  type with a default constructor, the object is value-initialized.
4606
  - Otherwise, if `T` is a specialization of `std::initializer_list<E>`,
4607
  the object is constructed as described below.
4608
  - Otherwise, if `T` is a class type, constructors are considered. The
4609
  applicable constructors are enumerated and the best one is chosen
4610
+ through overload resolution [[over.match]], [[over.match.list]]. If a
4611
+ narrowing conversion (see below) is required to convert any of the
4612
  arguments, the program is ill-formed.
4613
  \[*Example 4*:
4614
  ``` cpp
4615
  struct S {
4616
  S(std::initializer_list<double>); // #1
 
4639
  // no initializer-list constructors
4640
  S(int, double, double); // #1
4641
  S(); // #2
4642
  // ...
4643
  };
4644
+ S s1 = { 1, 2, 3.0 }; // OK, invoke #1
4645
  S s2 { 1.0, 2, 3 }; // error: narrowing
4646
+ S s3 { }; // OK, invoke #2
4647
  ```
4648
 
4649
  — *end example*]
4650
  - Otherwise, if `T` is an enumeration with a fixed underlying type
4651
  [[dcl.enum]] `U`, the *initializer-list* has a single element `v`, `v`
 
4686
  int x2 {2.0}; // error: narrowing
4687
  ```
4688
 
4689
  — *end example*]
4690
  - Otherwise, if `T` is a reference type, a prvalue is generated. The
4691
+ prvalue initializes its result object by copy-list-initialization from
4692
+ the initializer list. The prvalue is then used to direct-initialize
4693
+ the reference. The type of the prvalue is the type referenced by `T`,
4694
+ unless `T` is “reference to array of unknown bound of `U`”, in which
4695
+ case the type of the prvalue is the type of `x` in the declaration
4696
+ `U x[] H`, where H is the initializer list.
4697
  \[*Note 3*: As usual, the binding will fail and the program is
4698
  ill-formed if the reference type is an lvalue reference to a non-const
4699
  type. — *end note*]
4700
  \[*Example 9*:
4701
  ``` cpp
4702
  struct S {
4703
  S(std::initializer_list<double>); // #1
4704
  S(const std::string&); // #2
4705
  // ...
4706
  };
4707
+ const S& r1 = { 1, 2, 3.0 }; // OK, invoke #1
4708
+ const S& r2 { "Spinach" }; // OK, invoke #2
4709
  S& r3 = { 1, 2, 3 }; // error: initializer is not an lvalue
4710
  const int& i1 = { 1 }; // OK
4711
  const int& i2 = { 1.1 }; // error: narrowing
4712
+ const int (&iar)[2] = { 1, 2 }; // OK, iar is bound to temporary array
4713
 
4714
  struct A { } a;
4715
  struct B { explicit B(const A&); };
4716
  const B& b2{a}; // error: cannot copy-list-initialize B temporary from A
4717
  ```
 
4830
  member, so the program is ill-formed [[class.base.init]].
4831
 
4832
  — *end example*]
4833
 
4834
  [*Note 6*: The implementation is free to allocate the array in
4835
+ read-only memory if an explicit array with the same initializer can be
4836
  so allocated. — *end note*]
4837
 
4838
  A *narrowing conversion* is an implicit conversion
4839
 
4840
  - from a floating-point type to an integer type, or
4841
+ - from a floating-point type `T` to another floating-point type whose
4842
+ floating-point conversion rank is neither greater than nor equal to
4843
+ that of `T`, except where the source is a constant expression and the
4844
  actual value after conversion is within the range of values that can
4845
  be represented (even if it cannot be represented exactly), or
4846
  - from an integer type or unscoped enumeration type to a floating-point
4847
  type, except where the source is a constant expression and the actual
4848
  value after conversion will fit into the target type and will produce
4849
  the original value when converted back to the original type, or
4850
  - from an integer type or unscoped enumeration type to an integer type
4851
  that cannot represent all the values of the original type, except
4852
+ where
4853
+ - the source is a bit-field whose width w is less than that of its
4854
+ type (or, for an enumeration type, its underlying type) and the
4855
+ target type can represent all the values of a hypothetical extended
4856
+ integer type with width w and with the same signedness as the
4857
+ original type or
4858
+ - the source is a constant expression whose value after integral
4859
  promotions will fit into the target type, or
4860
  - from a pointer type or a pointer-to-member type to `bool`.
4861
 
4862
  [*Note 7*: As indicated above, such conversions are not allowed at the
4863
  top level in list-initializations. — *end note*]
 
4866
 
4867
  ``` cpp
4868
  int x = 999; // x is not a constant expression
4869
  const int y = 999;
4870
  const int z = 99;
4871
+ char c1 = x; // OK, though it potentially narrows (in this case, it does narrow)
4872
+ char c2{x}; // error: potentially narrows
4873
  char c3{y}; // error: narrows (assuming char is 8 bits)
4874
+ char c4{z}; // OK, no narrowing needed
4875
+ unsigned char uc1 = {5}; // OK, no narrowing needed
4876
  unsigned char uc2 = {-1}; // error: narrows
4877
  unsigned int ui1 = {-1}; // error: narrows
4878
  signed int si1 =
4879
  { (unsigned int)-1 }; // error: narrows
4880
  int ii = {2.0}; // error: narrows
4881
+ float f1 { x }; // error: potentially narrows
4882
+ float f2 { 7 }; // OK, 7 can be exactly represented as a float
4883
  bool b = {"meow"}; // error: narrows
4884
  int f(int);
4885
+ int a[] = { 2, f(2), f(2.0) }; // OK, the double-to-int conversion is not at the top level
4886
  ```
4887
 
4888
  — *end example*]
4889
 
4890
  ## Function definitions <a id="dcl.fct.def">[[dcl.fct.def]]</a>
 
4939
 
4940
  A *ctor-initializer* is used only in a constructor; see  [[class.ctor]]
4941
  and  [[class.init]].
4942
 
4943
  [*Note 1*: A *cv-qualifier-seq* affects the type of `this` in the body
4944
+ of a member function; see  [[expr.prim.this]]. — *end note*]
4945
 
4946
  [*Note 2*:
4947
 
4948
  Unused parameters need not be named. For example,
4949
 
 
4953
  }
4954
  ```
4955
 
4956
  — *end note*]
4957
 
4958
+ A *function-local predefined variable* is a variable with static storage
4959
+ duration that is implicitly defined in a function parameter scope.
 
4960
 
4961
  The function-local predefined variable `__func__` is defined as if a
4962
  definition of the form
4963
 
4964
  ``` cpp
 
4989
 
4990
  - be a special member function or a comparison operator function
4991
  [[over.binary]], and
4992
  - not have default arguments.
4993
 
4994
+ An explicitly defaulted special member function `F` is allowed to
4995
+ differ from the corresponding special member function `F₂` that would
4996
+ have been implicitly declared, as follows:
4997
 
4998
+ - `F` and `F` may have differing *ref-qualifier*s;
4999
+ - if `F₂` has an implicit object parameter of type “reference to `C`”,
5000
+ `F₁` may be an explicit object member function whose explicit object
5001
+ parameter is of type “reference to `C`”, in which case the type of
5002
+ `F₁` would differ from the type of `F₂` in that the type of `F₁` has
5003
+ an additional parameter;
5004
+ - `F₁` and `F₂` may have differing exception specifications; and
5005
+ - if `F₂` has a non-object parameter of type `const C&`, the
5006
+ corresponding non-object parameter of `F₁` may be of type `C&`.
5007
 
5008
+ If the type of `F` differs from the type of `F` in a way other than as
5009
+ allowed by the preceding rules, then:
5010
 
5011
+ - if `F` is an assignment operator, and the return type of `F` differs
5012
+ from the return type of `F` or `F`’s non-object parameter type is
5013
+ not a reference, the program is ill-formed;
5014
+ - otherwise, if `F` is explicitly defaulted on its first declaration,
5015
+ it is defined as deleted;
5016
  - otherwise, the program is ill-formed.
5017
 
5018
+ A function explicitly defaulted on its first declaration is implicitly
5019
+ inline [[dcl.inline]], and is implicitly constexpr [[dcl.constexpr]] if
5020
+ it is constexpr-suitable.
 
 
5021
 
5022
  [*Example 1*:
5023
 
5024
  ``` cpp
5025
  struct S {
 
5026
  S(int a = 0) = default; // error: default argument
5027
  void operator=(const S&) = default; // error: non-matching return type
5028
  ~S() noexcept(false) = default; // OK, despite mismatched exception specification
5029
  private:
5030
  int i;
5031
+ S(S&); // OK, private copy constructor
5032
  };
5033
+ S::S(S&) = default; // OK, defines copy constructor
5034
 
5035
  struct T {
5036
  T();
5037
  T(T &&) noexcept(false);
5038
  };
 
5047
 
5048
  — *end example*]
5049
 
5050
  Explicitly-defaulted functions and implicitly-declared functions are
5051
  collectively called *defaulted* functions, and the implementation shall
5052
+ provide implicit definitions for them
5053
+ [[class.ctor]], [[class.dtor]], [[class.copy.ctor]], [[class.copy.assign]]
5054
+ as described below, including possibly defining them as deleted. A
5055
+ defaulted prospective destructor [[class.dtor]] that is not a destructor
5056
+ is defined as deleted. A defaulted special member function that is
5057
+ neither a prospective destructor nor an eligible special member function
5058
+ [[special]] is defined as deleted. A function is *user-provided* if it
5059
+ is user-declared and not explicitly defaulted or deleted on its first
5060
+ declaration. A user-provided explicitly-defaulted function (i.e.,
5061
+ explicitly defaulted after its first declaration) is implicitly defined
5062
+ at the point where it is explicitly defaulted; if such a function is
5063
+ implicitly defined as deleted, the program is ill-formed. A
5064
+ non-user-provided defaulted function (i.e., implicitly declared or
5065
+ explicitly defaulted in the class) that is not defined as deleted is
5066
+ implicitly defined when it is odr-used [[basic.def.odr]] or needed for
5067
+ constant evaluation [[expr.const]].
5068
 
5069
  [*Note 1*: Declaring a function as defaulted after its first
5070
  declaration can provide efficient execution and concise definition while
5071
  enabling a stable binary interface to an evolving code
5072
  base. — *end note*]
 
5091
 
5092
  — *end example*]
5093
 
5094
  ### Deleted definitions <a id="dcl.fct.def.delete">[[dcl.fct.def.delete]]</a>
5095
 
5096
+ A *deleted definition* of a function is a function definition whose
5097
+ *function-body* is of the form `= delete ;` or an explicitly-defaulted
5098
+ definition of the function where the function is defined as deleted. A
5099
+ *deleted function* is a function with a deleted definition or a function
5100
+ that is implicitly defined as deleted.
5101
 
5102
  A program that refers to a deleted function implicitly or explicitly,
5103
  other than to declare it, is ill-formed.
5104
 
5105
  [*Note 1*: This includes calling the function implicitly or explicitly
5106
  and forming a pointer or pointer-to-member to the function. It applies
5107
  even for references in expressions that are not potentially-evaluated.
5108
+ For an overload set, only the function selected by overload resolution
5109
+ is referenced. The implicit odr-use [[term.odr.use]] of a virtual
5110
+ function does not, by itself, constitute a reference. — *end note*]
 
5111
 
5112
  [*Example 1*:
5113
 
5114
  One can prevent default initialization and initialization by
5115
  non-`double`s with
 
5218
 
5219
  — *end example*]
5220
 
5221
  The *promise type* of a coroutine is
5222
  `std::coroutine_traits<R, P₁, …, Pₙ>::promise_type`, where `R` is the
5223
+ return type of the function, and `P₁` … `Pₙ` is the sequence of types of
5224
+ the non-object function parameters, preceded by the type of the object
5225
+ parameter [[dcl.fct]] if the coroutine is a non-static member function.
5226
+ The promise type shall be a class type.
5227
 
5228
+ In the following, `pᵢ` is an lvalue of type `Pᵢ`, where `p₁` denotes the
5229
+ object parameter and `p_i+1` denotes the iᵗʰ non-object function
5230
+ parameter for a non-static member function, and `pᵢ` denotes the iᵗʰ
5231
+ function parameter otherwise. For a non-static member function, `q₁` is
5232
+ an lvalue that denotes `*this`; any other `qᵢ` is an lvalue that denotes
5233
+ the parameter copy corresponding to `pᵢ`, as described below.
5234
 
5235
  A coroutine behaves as if its *function-body* were replaced by:
5236
 
5237
  ``` bnf
5238
  '{'
 
5253
  ```
5254
 
5255
  where
5256
 
5257
  - the *await-expression* containing the call to `initial_suspend` is the
5258
+ *initial await expression*, and
5259
  - the *await-expression* containing the call to `final_suspend` is the
5260
+ *final await expression*, and
5261
  - *initial-await-resume-called* is initially `false` and is set to
5262
  `true` immediately before the evaluation of the *await-resume*
5263
+ expression [[expr.await]] of the initial await expression, and
5264
  - *promise-type* denotes the promise type, and
5265
  - the object denoted by the exposition-only name *`promise`* is the
5266
  *promise object* of the coroutine, and
5267
  - the label denoted by the name *`final-suspend`* is defined for
5268
  exposition only [[stmt.return.coroutine]], and
5269
  - *promise-constructor-arguments* is determined as follows: overload
5270
  resolution is performed on a promise constructor call created by
5271
+ assembling an argument list `q₁` … `qₙ`. If a viable constructor is
5272
+ found [[over.match.viable]], then *promise-constructor-arguments* is
5273
+ `(q₁, …, qₙ)`, otherwise *promise-constructor-arguments* is empty, and
5274
+ - a coroutine is suspended at the *initial suspend point* if it is
5275
+ suspended at the initial await expression, and
5276
+ - a coroutine is suspended at a *final suspend point* if it is suspended
5277
+ - at a final await expression or
5278
+ - due to an exception exiting from `unhandled_exception()`.
5279
 
5280
+ If searches for the names `return_void` and `return_value` in the scope
5281
+ of the promise type each find any declarations, the program is
5282
  ill-formed.
5283
 
5284
+ [*Note 1*: If `return_void` is found, flowing off the end of a
5285
+ coroutine is equivalent to a `co_return` with no operand. Otherwise,
5286
+ flowing off the end of a coroutine results in undefined behavior
5287
+ [[stmt.return.coroutine]]. — *end note*]
5288
 
5289
  The expression `promise.get_return_object()` is used to initialize the
5290
+ returned reference or prvalue result object of a call to a coroutine.
5291
+ The call to `get_return_object` is sequenced before the call to
5292
  `initial_suspend` and is invoked at most once.
5293
 
5294
  A suspended coroutine can be resumed to continue execution by invoking a
5295
  resumption member function [[coroutine.handle.resumption]] of a
5296
  coroutine handle [[coroutine.handle]] that refers to the coroutine. The
5297
+ evaluation that invoked a resumption member function is called the
5298
  *resumer*. Invoking a resumption member function for a coroutine that is
5299
  not suspended results in undefined behavior.
5300
 
5301
  An implementation may need to allocate additional storage for a
5302
  coroutine. This storage is known as the *coroutine state* and is
5303
  obtained by calling a non-array allocation function
5304
  [[basic.stc.dynamic.allocation]]. The allocation function’s name is
5305
+ looked up by searching for it in the scope of the promise type.
 
 
 
 
 
 
 
 
 
5306
 
5307
+ - If the search finds any declarations, overload resolution is performed
5308
+ on a function call created by assembling an argument list. The first
5309
+ argument is the amount of space requested, and is a prvalue of type
5310
+ `std::size_t`. The lvalues `p₁` `pₙ` are the successive arguments.
5311
+ If no viable function is found [[over.match.viable]], overload
5312
+ resolution is performed again on a function call created by passing
5313
+ just the amount of space required as a prvalue of type `std::size_t`.
5314
+ - If the search finds no declarations, a search is performed in the
5315
+ global scope. Overload resolution is performed on a function call
5316
+ created by passing the amount of space required as a prvalue of type
5317
+ `std::size_t`.
5318
+
5319
+ If a search for the name `get_return_object_on_allocation_failure` in
5320
+ the scope of the promise type [[class.member.lookup]] finds any
5321
+ declarations, then the result of a call to an allocation function used
5322
+ to obtain storage for the coroutine state is assumed to return `nullptr`
5323
+ if it fails to obtain storage, and if a global allocation function is
5324
+ selected, the `::operator new(size_t, nothrow_t)` form is used. The
5325
+ allocation function used in this case shall have a non-throwing
5326
+ *noexcept-specifier*. If the allocation function returns `nullptr`, the
5327
+ coroutine returns control to the caller of the coroutine and the return
5328
+ value is obtained by a call to
5329
  `T::get_return_object_on_allocation_failure()`, where `T` is the promise
5330
  type.
5331
 
5332
  [*Example 2*:
5333
 
 
5342
  struct promise_type {
5343
  int current_value;
5344
  static auto get_return_object_on_allocation_failure() { return generator{nullptr}; }
5345
  auto get_return_object() { return generator{handle::from_promise(*this)}; }
5346
  auto initial_suspend() { return std::suspend_always{}; }
5347
+ auto final_suspend() noexcept { return std::suspend_always{}; }
5348
  void unhandled_exception() { std::terminate(); }
5349
  void return_void() {}
5350
  auto yield_value(int value) {
5351
  current_value = value;
5352
  return std::suspend_always{};
 
5372
 
5373
  The coroutine state is destroyed when control flows off the end of the
5374
  coroutine or the `destroy` member function
5375
  [[coroutine.handle.resumption]] of a coroutine handle
5376
  [[coroutine.handle]] that refers to the coroutine is invoked. In the
5377
+ latter case, control in the coroutine is considered to be transferred
5378
+ out of the function [[stmt.dcl]]. The storage for the coroutine state is
5379
+ released by calling a non-array deallocation function
5380
+ [[basic.stc.dynamic.deallocation]]. If `destroy` is called for a
5381
+ coroutine that is not suspended, the program has undefined behavior.
 
5382
 
5383
+ The deallocation function’s name is looked up by searching for it in the
5384
+ scope of the promise type. If nothing is found, a search is performed in
5385
+ the global scope. If both a usual deallocation function with only a
5386
+ pointer parameter and a usual deallocation function with both a pointer
5387
+ parameter and a size parameter are found, then the selected deallocation
5388
+ function shall be the one with two parameters. Otherwise, the selected
5389
+ deallocation function shall be the function with one parameter. If no
5390
+ usual deallocation function is found, the program is ill-formed. The
5391
+ selected deallocation function shall be called with the address of the
5392
+ block of storage to be reclaimed as its first argument. If a
5393
+ deallocation function with a parameter of type `std::size_t` is used,
5394
+ the size of the block is passed as the corresponding argument.
 
5395
 
5396
  When a coroutine is invoked, after initializing its parameters
5397
  [[expr.call]], a copy is created for each coroutine parameter. For a
5398
  parameter of type cv `T`, the copy is a variable of type cv `T` with
5399
  automatic storage duration that is direct-initialized from an xvalue of
 
5414
  parameter has ended is likely to result in undefined
5415
  behavior. — *end note*]
5416
 
5417
  If the evaluation of the expression `promise.unhandled_exception()`
5418
  exits via an exception, the coroutine is considered suspended at the
5419
+ final suspend point and the exception propagates to the caller or
5420
+ resumer.
5421
 
5422
  The expression `co_await` `promise.final_suspend()` shall not be
5423
  potentially-throwing [[except.spec]].
5424
 
5425
  ## Structured binding declarations <a id="dcl.struct.bind">[[dcl.struct.bind]]</a>
5426
 
5427
  A structured binding declaration introduces the *identifier*s `v₀`,
5428
+ `v₁`, `v₂`, … of the *identifier-list* as names of *structured
5429
+ binding*s. Let cv denote the *cv-qualifier*s in the *decl-specifier-seq*
5430
+ and *S* consist of the *storage-class-specifier*s of the
5431
+ *decl-specifier-seq* (if any). A cv that includes `volatile` is
5432
+ deprecated; see  [[depr.volatile.type]]. First, a variable with a unique
5433
+ name *`e`* is introduced. If the *assignment-expression* in the
5434
+ *initializer* has array type *cv1* `A` and no *ref-qualifier* is
5435
+ present, *`e`* is defined by
5436
 
5437
  ``` bnf
5438
  attribute-specifier-seqₒₚₜ *S* cv 'A' e ';'
5439
  ```
5440
 
 
5456
  If the *initializer* refers to one of the names introduced by the
5457
  structured binding declaration, the program is ill-formed.
5458
 
5459
  If `E` is an array type with element type `T`, the number of elements in
5460
  the *identifier-list* shall be equal to the number of elements of `E`.
5461
+ Each `vᵢ` is the name of an lvalue that refers to the element i of the
5462
  array and whose type is `T`; the referenced type is `T`.
5463
 
5464
  [*Note 2*: The top-level cv-qualifiers of `T` are cv. — *end note*]
5465
 
5466
  [*Example 1*:
 
5476
  Otherwise, if the *qualified-id* `std::tuple_size<E>` names a complete
5477
  class type with a member named `value`, the expression
5478
  `std::tuple_size<E>::value` shall be a well-formed integral constant
5479
  expression and the number of elements in the *identifier-list* shall be
5480
  equal to the value of that expression. Let `i` be an index prvalue of
5481
+ type `std::size_t` corresponding to `v`. If a search for the name `get`
5482
+ in the scope of `E` [[class.member.lookup]] finds at least one
5483
+ declaration that is a function template whose first template parameter
5484
+ is a non-type parameter, the initializer is `e.get<i>()`. Otherwise, the
5485
+ initializer is `get<i>(e)`, where `get` undergoes argument-dependent
5486
+ lookup [[basic.lookup.argdep]]. In either case, `get<i>` is interpreted
5487
+ as a *template-id*.
 
5488
 
5489
  [*Note 3*: Ordinary unqualified lookup [[basic.lookup.unqual]] is not
5490
  performed. — *end note*]
5491
 
5492
  In either case, *`e`* is an lvalue if the type of the entity *`e`* is an
 
5507
  of `E` or of the same base class of `E`, well-formed when named as
5508
  `e.name` in the context of the structured binding, `E` shall not have an
5509
  anonymous union member, and the number of elements in the
5510
  *identifier-list* shall be equal to the number of non-static data
5511
  members of `E`. Designating the non-static data members of `E` as `m₀`,
5512
+ `m₁`, `m₂`, … (in declaration order), each `vᵢ` is the name of an lvalue
5513
+ that refers to the member `m`ᵢ of *`e`* and whose type is that of `e.mᵢ`
5514
+ [[expr.ref]]; the referenced type is the declared type of `mᵢ` if that
5515
+ type is a reference type, or the type of `e.mᵢ` otherwise. The lvalue is
5516
+ a bit-field if that member is a bit-field.
5517
 
5518
  [*Example 2*:
5519
 
5520
  ``` cpp
5521
+ struct S { mutable int x1 : 2; volatile double y1; };
5522
  S f();
5523
  const auto [ x, y ] = f();
5524
  ```
5525
 
5526
+ The type of the *id-expression* `x` is “`int`”, the type of the
5527
  *id-expression* `y` is “`const volatile double`”.
5528
 
5529
  — *end example*]
5530
 
5531
  ## Enumerations <a id="enum">[[enum]]</a>
 
5615
 
5616
  — *end example*]
5617
 
5618
  — *end note*]
5619
 
5620
+ The *identifier* in an *enum-head-name* is not looked up and is
5621
+ introduced by the *enum-specifier* or *opaque-enum-declaration*. If the
5622
+ *enum-head-name* of an *opaque-enum-declaration* contains a
5623
  *nested-name-specifier*, the declaration shall be an explicit
5624
  specialization [[temp.expl.spec]].
5625
 
5626
  The enumeration type declared with an *enum-key* of only `enum` is an
5627
  *unscoped enumeration*, and its *enumerator*s are *unscoped
 
5632
  declaration of a scoped enumeration. The *type-specifier-seq* of an
5633
  *enum-base* shall name an integral type; any cv-qualification is
5634
  ignored. An *opaque-enum-declaration* declaring an unscoped enumeration
5635
  shall not omit the *enum-base*. The identifiers in an *enumerator-list*
5636
  are declared as constants, and can appear wherever constants are
5637
+ required. The same identifier shall not appear as the name of multiple
5638
+ enumerators in an *enumerator-list*. An *enumerator-definition* with `=`
5639
+ gives the associated *enumerator* the value indicated by the
5640
+ *constant-expression*. If the first *enumerator* has no *initializer*,
5641
+ the value of the corresponding constant is zero. An
5642
+ *enumerator-definition* without an *initializer* gives the *enumerator*
5643
+ the value obtained by increasing the value of the previous *enumerator*
5644
+ by one.
5645
 
5646
  [*Example 2*:
5647
 
5648
  ``` cpp
5649
  enum { a, b, c=0 };
 
5669
  A scoped enumeration shall not be later redeclared as unscoped or with a
5670
  different underlying type. An unscoped enumeration shall not be later
5671
  redeclared as scoped and each redeclaration shall include an *enum-base*
5672
  specifying the same underlying type as in the original declaration.
5673
 
5674
+ If an *enum-head-name* contains a *nested-name-specifier*, the enclosing
5675
+ *enum-specifier* or *opaque-enum-declaration* D shall not inhabit a
5676
+ class scope and shall correspond to one or more declarations nominable
5677
+ in the class, class template, or namespace to which the
5678
+ *nested-name-specifier* refers [[basic.scope.scope]]. All those
5679
+ declarations shall have the same target scope; the target scope of D is
5680
+ that scope.
 
 
5681
 
5682
  Each enumeration defines a type that is different from all other types.
5683
  Each enumeration also has an *underlying type*. The underlying type can
5684
  be explicitly specified using an *enum-base*. For a scoped enumeration
5685
  type, the underlying type is `int` if it is not explicitly specified. In
 
5703
  preceding enumerator unless the incremented value is not representable
5704
  in that type, in which case the type is an unspecified integral type
5705
  sufficient to contain the incremented value. If no such type exists,
5706
  the program is ill-formed.
5707
 
5708
+ An enumeration whose underlying type is fixed is an incomplete type
5709
+ until immediately after its *enum-base* (if any), at which point it
5710
+ becomes a complete type. An enumeration whose underlying type is not
5711
+ fixed is an incomplete type until the closing `}` of its
5712
+ *enum-specifier*, at which point it becomes a complete type.
 
5713
 
5714
  For an enumeration whose underlying type is not fixed, the underlying
5715
  type is an integral type that can represent all the enumerator values
5716
  defined in the enumeration. If no integral type can represent all the
5717
  enumerator values, the enumeration is ill-formed. It is
 
5729
  all the values of the enumeration type is M. It is possible to define an
5730
  enumeration that has values not defined by any of its enumerators. If
5731
  the *enumerator-list* is empty, the values of the enumeration are as if
5732
  the enumeration had a single enumerator with value 0.[^9]
5733
 
5734
+ An enumeration has the same size, value representation, and alignment
5735
+ requirements [[basic.align]] as its underlying type. Furthermore, each
5736
+ value of an enumeration has the same representation as the corresponding
5737
+ value of the underlying type.
5738
+
5739
  Two enumeration types are *layout-compatible enumerations* if they have
5740
  the same underlying type.
5741
 
5742
  The value of an enumerator or an object of an unscoped enumeration type
5743
  is converted to an integer by integral promotion [[conv.prom]].
 
5758
  values `0`, `1`, `20`, and `21`. Since enumerations are distinct types,
5759
  objects of type `color` can be assigned only values of type `color`.
5760
 
5761
  ``` cpp
5762
  color c = 1; // error: type mismatch, no conversion from int to color
5763
+ int i = yellow; // OK, yellow converted to integral value 1, integral promotion
5764
  ```
5765
 
5766
  Note that this implicit `enum` to `int` conversion is not provided for a
5767
  scoped enumeration:
5768
 
 
5773
  if (y) { } // error: no Col to bool conversion
5774
  ```
5775
 
5776
  — *end example*]
5777
 
5778
+ The name of each unscoped enumerator is also bound in the scope that
5779
+ immediately contains the *enum-specifier*. An unnamed enumeration that
 
5780
  does not have a typedef name for linkage purposes [[dcl.typedef]] and
5781
  that has a first enumerator is denoted, for linkage purposes
5782
  [[basic.link]], by its underlying type and its first enumerator; such an
5783
  enumeration is said to have an enumerator as a name for linkage
5784
+ purposes.
 
5785
 
5786
  [*Note 3*: Each unnamed enumeration with no enumerators is a distinct
5787
  type. — *end note*]
5788
 
5789
  [*Example 4*:
 
5806
  }
5807
  ```
5808
 
5809
  — *end example*]
5810
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5811
  ### The `using enum` declaration <a id="enum.udecl">[[enum.udecl]]</a>
5812
 
5813
  ``` bnf
5814
  using-enum-declaration:
5815
+ using enum using-enum-declarator ';'
5816
  ```
5817
 
5818
+ ``` bnf
5819
+ using-enum-declarator:
5820
+ nested-name-specifierₒₚₜ identifier
5821
+ nested-name-specifierₒₚₜ simple-template-id
5822
+ ```
5823
+
5824
+ A *using-enum-declarator* names the set of declarations found by lookup
5825
+ [[basic.lookup.unqual]], [[basic.lookup.qual]] for the
5826
+ *using-enum-declarator*. The *using-enum-declarator* shall designate a
5827
+ non-dependent type with a reachable *enum-specifier*.
5828
 
5829
+ A *using-enum-declaration* is equivalent to a *using-declaration* for
5830
+ each enumerator.
5831
 
5832
  [*Note 1*:
5833
 
5834
+ A *using-enum-declaration* in class scope makes the enumerators of the
5835
+ named enumeration available via member lookup.
 
5836
 
5837
  [*Example 1*:
5838
 
5839
  ``` cpp
5840
  enum class fruit { orange, apple };
 
5872
 
5873
  — *end note*]
5874
 
5875
  ## Namespaces <a id="basic.namespace">[[basic.namespace]]</a>
5876
 
5877
+ ### General <a id="basic.namespace.general">[[basic.namespace.general]]</a>
 
 
 
 
5878
 
5879
+ A namespace is an optionally-named entity whose scope can contain
5880
+ declarations of any kind of entity. The name of a namespace can be used
5881
+ to access entities that belong to that namespace; that is, the *members*
5882
+ of the namespace. Unlike other entities, the definition of a namespace
5883
+ can be split over several parts of one or more translation units and
5884
+ modules.
5885
+
5886
+ [*Note 1*: A *namespace-definition* is exported if it contains any
5887
  *export-declaration*s [[module.interface]]. A namespace is never
5888
+ attached to a named module and never has a name with module
5889
+ linkage. — *end note*]
5890
 
5891
  [*Example 1*:
5892
 
5893
  ``` cpp
5894
  export module M;
 
5897
  namespace N3 { export int n; } // N3 is exported
5898
  ```
5899
 
5900
  — *end example*]
5901
 
5902
+ There is a *global namespace* with no declaration; see 
5903
+ [[basic.scope.namespace]]. The global namespace belongs to the global
5904
+ scope; it is not an unnamed namespace [[namespace.unnamed]].
5905
+
5906
+ [*Note 2*: Lacking a declaration, it cannot be found by name
5907
+ lookup. — *end note*]
5908
 
5909
  ### Namespace definition <a id="namespace.def">[[namespace.def]]</a>
5910
 
5911
+ #### General <a id="namespace.def.general">[[namespace.def.general]]</a>
5912
+
5913
  ``` bnf
5914
  namespace-name:
5915
  identifier
5916
  namespace-alias
5917
  ```
 
5947
  ``` bnf
5948
  namespace-body:
5949
  declaration-seqₒₚₜ
5950
  ```
5951
 
5952
+ Every *namespace-definition* shall inhabit a namespace scope
5953
  [[basic.scope.namespace]].
5954
 
5955
+ In a *named-namespace-definition* D, the *identifier* is the name of the
5956
+ namespace. The *identifier* is looked up by searching for it in the
5957
+ scopes of the namespace A in which D appears and of every element of the
5958
+ inline namespace set of A. If the lookup finds a *namespace-definition*
5959
+ for a namespace N, D *extends* N, and the target scope of D is the scope
5960
+ to which N belongs. If the lookup finds nothing, the *identifier* is
5961
+ introduced as a *namespace-name* into A.
 
 
5962
 
5963
  Because a *namespace-definition* contains *declaration*s in its
5964
  *namespace-body* and a *namespace-definition* is itself a *declaration*,
5965
  it follows that *namespace-definition*s can be nested.
5966
 
 
5977
  }
5978
  ```
5979
 
5980
  — *end example*]
5981
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5982
  If the optional initial `inline` keyword appears in a
5983
  *namespace-definition* for a particular namespace, that namespace is
5984
  declared to be an *inline namespace*. The `inline` keyword may be used
5985
  on a *namespace-definition* that extends a namespace only if it was
5986
  previously used on the *namespace-definition* that initially declared
 
5988
 
5989
  The optional *attribute-specifier-seq* in a *named-namespace-definition*
5990
  appertains to the namespace being defined or extended.
5991
 
5992
  Members of an inline namespace can be used in most respects as though
5993
+ they were members of the innermost enclosing namespace. Specifically,
5994
+ the inline namespace and its enclosing namespace are both added to the
5995
+ set of associated namespaces used in argument-dependent lookup
5996
  [[basic.lookup.argdep]] whenever one of them is, and a *using-directive*
5997
  [[namespace.udir]] that names the inline namespace is implicitly
5998
  inserted into the enclosing namespace as for an unnamed namespace
5999
  [[namespace.unnamed]]. Furthermore, each member of the inline namespace
6000
+ can subsequently be partially specialized [[temp.spec.partial]],
6001
  explicitly instantiated [[temp.explicit]], or explicitly specialized
6002
  [[temp.expl.spec]] as though it were a member of the enclosing
6003
  namespace. Finally, looking up a name in the enclosing namespace via
6004
  explicit qualification [[namespace.qual]] will include members of the
6005
+ inline namespace even if there are declarations of that name in the
6006
+ enclosing namespace.
6007
 
6008
  These properties are transitive: if a namespace `N` contains an inline
6009
  namespace `M`, which in turn contains an inline namespace `O`, then the
6010
  members of `O` can be used as though they were members of `M` or `N`.
6011
  The *inline namespace set* of `N` is the transitive closure of all
6012
+ inline namespaces in `N`.
 
 
 
6013
 
6014
  A *nested-namespace-definition* with an *enclosing-namespace-specifier*
6015
  `E`, *identifier* `I` and *namespace-body* `B` is equivalent to
6016
 
6017
  ``` cpp
 
6019
  ```
6020
 
6021
  where the optional `inline` is present if and only if the *identifier*
6022
  `I` is preceded by `inline`.
6023
 
6024
+ [*Example 2*:
6025
 
6026
  ``` cpp
6027
  namespace A::inline B::C {
6028
  int i;
6029
  }
 
6082
  }
6083
  ```
6084
 
6085
  — *end example*]
6086
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6087
  ### Namespace alias <a id="namespace.alias">[[namespace.alias]]</a>
6088
 
6089
  A *namespace-alias-definition* declares an alternate name for a
6090
  namespace according to the following grammar:
6091
 
 
6102
  ``` bnf
6103
  qualified-namespace-specifier:
6104
  nested-name-specifierₒₚₜ namespace-name
6105
  ```
6106
 
6107
+ The *identifier* in a *namespace-alias-definition* becomes a
6108
+ *namespace-alias* and denotes the namespace denoted by the
6109
+ *qualified-namespace-specifier*.
6110
 
6111
  [*Note 1*: When looking up a *namespace-name* in a
6112
  *namespace-alias-definition*, only namespace names are considered, see 
6113
  [[basic.lookup.udir]]. — *end note*]
6114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6115
  ### Using namespace directive <a id="namespace.udir">[[namespace.udir]]</a>
6116
 
6117
  ``` bnf
6118
  using-directive:
6119
  attribute-specifier-seqₒₚₜ using namespace nested-name-specifierₒₚₜ namespace-name ';'
 
6127
  [[basic.lookup.udir]]. — *end note*]
6128
 
6129
  The optional *attribute-specifier-seq* appertains to the
6130
  *using-directive*.
6131
 
6132
+ [*Note 2*: A *using-directive* makes the names in the nominated
6133
+ namespace usable in the scope in which the *using-directive* appears
6134
+ after the *using-directive* [[basic.lookup.unqual]], [[namespace.qual]].
6135
+ During unqualified name lookup, the names appear as if they were
6136
+ declared in the nearest enclosing namespace which contains both the
6137
+ *using-directive* and the nominated namespace. — *end note*]
6138
 
6139
+ [*Note 3*: A *using-directive* does not introduce any
6140
+ names. — *end note*]
 
 
 
6141
 
6142
  [*Example 1*:
6143
 
6144
  ``` cpp
6145
  namespace A {
 
6169
  }
6170
  ```
6171
 
6172
  — *end example*]
6173
 
6174
+ [*Note 4*: A *using-directive* is transitive: if a scope contains a
6175
+ *using-directive* that nominates a namespace that itself contains
6176
+ *using-directive*s, the namespaces nominated by those *using-directive*s
6177
+ are also eligible to be considered. *end note*]
 
 
 
 
6178
 
6179
  [*Example 2*:
6180
 
6181
  ``` cpp
6182
  namespace M {
 
6219
  }
6220
  ```
6221
 
6222
  — *end example*]
6223
 
6224
+ [*Note 5*: Declarations in a namespace that appear after a
6225
+ *using-directive* for that namespace can be found through that
6226
+ *using-directive* after they appear. *end note*]
 
 
6227
 
6228
+ [*Note 6*:
6229
 
6230
  If name lookup finds a declaration for a name in two different
6231
  namespaces, and the declarations do not declare the same entity and do
6232
  not declare functions or function templates, the use of the name is
6233
  ill-formed [[basic.lookup]]. In particular, the name of a variable,
 
6248
  using namespace A;
6249
  using namespace B;
6250
 
6251
  void f() {
6252
  X(1); // error: name X found in two namespaces
6253
+ g(); // OK, name g refers to the same entity
6254
+ h(); // OK, overload resolution selects A::h
6255
  }
6256
  ```
6257
 
6258
  — *end note*]
6259
 
6260
+ [*Note 7*:
 
 
6261
 
6262
+ The order in which namespaces are considered and the relationships among
6263
+ the namespaces implied by the *using-directive*s do not affect overload
6264
+ resolution. Neither is any function excluded because another has the
6265
+ same signature, even if one is in a namespace reachable through
6266
+ *using-directive*s in the namespace of the other.[^10]
6267
 
6268
+ *end note*]
 
 
6269
 
6270
  [*Example 3*:
6271
 
6272
  ``` cpp
6273
  namespace D {
6274
  int d1;
6275
  void f(char);
6276
  }
6277
  using namespace D;
6278
 
6279
+ int d1; // OK, no conflict with D::d1
6280
 
6281
  namespace E {
6282
  int e;
6283
  void f(int);
6284
  }
 
6291
 
6292
  void f() {
6293
  d1++; // error: ambiguous ::d1 or D::d1?
6294
  ::d1++; // OK
6295
  D::d1++; // OK
6296
+ d2++; // OK, D::d2
6297
+ e++; // OK, E::e
6298
  f(1); // error: ambiguous: D::f(int) or E::f(int)?
6299
+ f('a'); // OK, D::f(char)
6300
  }
6301
  ```
6302
 
6303
  — *end example*]
6304
 
 
6318
  ``` bnf
6319
  using-declarator:
6320
  typenameₒₚₜ nested-name-specifier unqualified-id
6321
  ```
6322
 
6323
+ The component names of a *using-declarator* are those of its
6324
+ *nested-name-specifier* and *unqualified-id*. Each *using-declarator* in
6325
+ a *using-declaration*[^11]
 
 
 
 
 
 
 
6326
 
6327
+ names the set of declarations found by lookup [[basic.lookup.qual]] for
6328
+ the *using-declarator*, except that class and enumeration declarations
6329
+ that would be discarded are merely ignored when checking for ambiguity
6330
+ [[basic.lookup]], conversion function templates with a dependent return
6331
+ type are ignored, and certain functions are hidden as described below.
6332
+ If the terminal name of the *using-declarator* is dependent
6333
+ [[temp.dep.type]], the *using-declarator* is considered to name a
6334
+ constructor if and only if the *nested-name-specifier* has a terminal
6335
+ name that is the same as the *unqualified-id*. If the lookup in any
6336
+ instantiation finds that a *using-declarator* that is not considered to
6337
+ name a constructor does do so, or that a *using-declarator* that is
6338
+ considered to name a constructor does not, the program is ill-formed.
6339
 
6340
  If the *using-declarator* names a constructor, it declares that the
6341
+ class *inherits* the named set of constructor declarations from the
6342
+ nominated base class.
6343
+
6344
+ [*Note 1*: Otherwise, the *unqualified-id* in the *using-declarator* is
6345
+ bound to the *using-declarator*, which is replaced during name lookup
6346
+ with the declarations it names [[basic.lookup]]. If such a declaration
6347
+ is of an enumeration, the names of its enumerators are not bound. For
6348
+ the keyword `typename`, see [[temp.res]]. — *end note*]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6349
 
6350
  In a *using-declaration* used as a *member-declaration*, each
6351
  *using-declarator* shall either name an enumerator or have a
6352
+ *nested-name-specifier* naming a base class of the current class
6353
+ [[expr.prim.this]].
6354
 
6355
+ [*Example 1*:
6356
 
6357
  ``` cpp
6358
  enum class button { up, down };
6359
  struct S {
6360
  using button::up;
 
6363
  ```
6364
 
6365
  — *end example*]
6366
 
6367
  If a *using-declarator* names a constructor, its *nested-name-specifier*
6368
+ shall name a direct base class of the current class. If the immediate
6369
+ (class) scope is associated with a class template, it shall derive from
6370
+ the specified base class or have at least one dependent base class.
6371
 
6372
+ [*Example 2*:
6373
 
6374
  ``` cpp
6375
+ struct B {
6376
+ void f(char);
6377
+ enum E { e };
6378
+ union { int x; };
6379
+ };
6380
+
6381
+ struct C {
6382
+ int f();
6383
+ };
6384
+
6385
+ struct D : B {
6386
+ using B::f; // OK, B is a base of D
6387
+ using B::e; // OK, e is an enumerator of base B
6388
+ using B::x; // OK, x is a union member of base B
6389
+ using C::f; // error: C isn't a base of D
6390
+ void f(int) { f('c'); } // calls B::f(char)
6391
+ void g(int) { g('c'); } // recursively calls D::g(int)
6392
+ };
6393
  template <typename... bases>
6394
  struct X : bases... {
6395
+ using bases::f...;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6396
  };
6397
+ X<B, C> x; // OK, B::f and C::f named
6398
  ```
6399
 
6400
  — *end example*]
6401
 
6402
  [*Note 2*: Since destructors do not have names, a *using-declaration*
6403
+ cannot refer to a destructor for a base class. *end note*]
 
 
 
6404
 
6405
  If a constructor or assignment operator brought from a base class into a
6406
  derived class has the signature of a copy/move constructor or assignment
6407
+ operator for the derived class
6408
+ [[class.copy.ctor]], [[class.copy.assign]], the *using-declaration* does
6409
+ not by itself suppress the implicit declaration of the derived class
6410
+ member; the member from the base class is hidden or overridden by the
6411
  implicitly-declared copy/move constructor or assignment operator of the
6412
  derived class, as described below.
6413
 
6414
  A *using-declaration* shall not name a *template-id*.
6415
 
6416
+ [*Example 3*:
6417
 
6418
  ``` cpp
6419
  struct A {
6420
  template <class T> void f(T);
6421
  template <class T> struct X { };
 
6431
  A *using-declaration* shall not name a namespace.
6432
 
6433
  A *using-declaration* that names a class member other than an enumerator
6434
  shall be a *member-declaration*.
6435
 
6436
+ [*Example 4*:
6437
 
6438
  ``` cpp
6439
  struct X {
6440
  int i;
6441
  static int s;
 
6447
  }
6448
  ```
6449
 
6450
  — *end example*]
6451
 
6452
+ If a declaration is named by two *using-declarator*s that inhabit the
6453
+ same class scope, the program is ill-formed.
6454
 
6455
+ [*Note 3*: A *using-declarator* whose *nested-name-specifier* names a
6456
+ namespace does not name declarations added to the namespace after it.
6457
+ Thus, additional overloads added after the *using-declaration* are
6458
+ ignored, but default function arguments [[dcl.fct.default]], default
6459
+ template arguments [[temp.param]], and template specializations
6460
+ [[temp.spec.partial]], [[temp.expl.spec]] are considered. — *end note*]
6461
 
6462
+ [*Example 5*:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6463
 
6464
  ``` cpp
6465
  namespace A {
6466
  void f(int);
6467
  }
 
6481
  }
6482
  ```
6483
 
6484
  — *end example*]
6485
 
6486
+ If a declaration named by a *using-declaration* that inhabits the target
6487
+ scope of another declaration potentially conflicts with it
6488
+ [[basic.scope.scope]], and either is reachable from the other, the
6489
+ program is ill-formed. If two declarations named by *using-declaration*s
6490
+ that inhabit the same scope potentially conflict, either is reachable
6491
+ from the other, and they do not both declare functions or function
6492
+ templates, the program is ill-formed.
6493
 
6494
+ [*Note 4*: Overload resolution possibly cannot distinguish between
6495
+ conflicting function declarations. *end note*]
 
6496
 
6497
+ [*Example 6*:
6498
 
6499
  ``` cpp
6500
  namespace A {
6501
  int x;
6502
+ int f(int);
6503
+ int g;
6504
+ void h();
6505
  }
6506
 
6507
  namespace B {
6508
  int i;
6509
  struct g { };
6510
  struct x { };
6511
  void f(int);
6512
  void f(double);
6513
+ void g(char); // OK, hides struct g
6514
  }
6515
 
6516
  void func() {
6517
  int i;
6518
+ using B::i; // error: conflicts
6519
  void f(char);
6520
+ using B::f; // OK, each f is a function
6521
+ using A::f; // OK, but interferes with B::f(int)
6522
+ f(1); // error: ambiguous
6523
+ static_cast<int(*)(int)>(f)(1); // OK, calls A::f
6524
  f(3.5); // calls B::f(double)
6525
  using B::g;
6526
  g('a'); // calls B::g(char)
6527
  struct g g1; // g1 has class type B::g
6528
+ using A::g; // error: conflicts with B::g
6529
+ void h();
6530
+ using A::h; // error: conflicts
6531
  using B::x;
6532
+ using A::x; // OK, hides struct B::x
6533
  x = 99; // assigns to A::x
6534
  struct x x1; // x1 has class type B::x
6535
  }
6536
  ```
6537
 
6538
  — *end example*]
6539
 
6540
+ The set of declarations named by a *using-declarator* that inhabits a
6541
+ class `C` does not include member functions and member function
6542
+ templates of a base class that correspond to (and thus would conflict
6543
+ with) a declaration of a function or function template in `C`.
 
 
 
 
6544
 
6545
+ [*Example 7*:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6546
 
6547
  ``` cpp
6548
  struct B {
6549
  virtual void f(int);
6550
  virtual void f(char);
 
6552
  void h(int);
6553
  };
6554
 
6555
  struct D : B {
6556
  using B::f;
6557
+ void f(int); // OK, D::f(int) overrides B::f(int);
6558
 
6559
  using B::g;
6560
  void g(char); // OK
6561
 
6562
  using B::h;
6563
+ void h(int); // OK, D::h(int) hides B::h(int)
6564
  };
6565
 
6566
  void k(D* p)
6567
  {
6568
  p->f(1); // calls D::f(int)
 
6586
  D1 d1(0); // error: ambiguous
6587
 
6588
  struct D2 : B1, B2 {
6589
  using B1::B1;
6590
  using B2::B2;
6591
+ D2(int); // OK, D2::D2(int) hides B1::B1(int) and B2::B2(int)
6592
  };
6593
  D2 d2(0); // calls D2::D2(int)
6594
  ```
6595
 
6596
  — *end example*]
6597
 
6598
+ [*Note 5*: For the purpose of forming a set of candidates during
6599
+ overload resolution, the functions named by a *using-declaration* in a
6600
+ derived class are treated as though they were direct members of the
6601
+ derived class. In particular, the implicit object parameter is treated
6602
+ as if it were a reference to the derived class rather than to the base
6603
+ class [[over.match.funcs]]. This has no effect on the type of the
6604
+ function, and in all other respects the function remains part of the
6605
+ base class. — *end note*]
6606
 
6607
+ Constructors that are named by a *using-declaration* are treated as
6608
  though they were constructors of the derived class when looking up the
6609
  constructors of the derived class [[class.qual]] or forming a set of
6610
+ overload candidates
6611
+ [[over.match.ctor]], [[over.match.copy]], [[over.match.list]].
6612
 
6613
+ [*Note 6*: If such a constructor is selected to perform the
6614
  initialization of an object of class type, all subobjects other than the
6615
  base class from which the constructor originated are implicitly
6616
  initialized [[class.inhctor.init]]. A constructor of a derived class is
6617
  sometimes preferred to a constructor of a base class if they would
6618
  otherwise be ambiguous [[over.match.best]]. — *end note*]
6619
 
6620
+ In a *using-declarator* that does not name a constructor, every
6621
+ declaration named shall be accessible. In a *using-declarator* that
6622
+ names a constructor, no access check is performed.
 
 
 
 
 
 
 
6623
 
6624
+ [*Note 7*:
6625
 
6626
  Because a *using-declarator* designates a base class member (and not a
6627
  member subobject or a member function of a base class subobject), a
6628
  *using-declarator* cannot be used to resolve inherited member
6629
  ambiguities.
6630
 
6631
+ [*Example 8*:
6632
 
6633
  ``` cpp
6634
  struct A { int x(); };
6635
  struct B : A { };
6636
  struct C : A {
 
6649
 
6650
  — *end example*]
6651
 
6652
  — *end note*]
6653
 
6654
+ A *using-declaration* has the usual accessibility for a
6655
+ *member-declaration*. Base-class constructors considered because of a
6656
+ *using-declarator* are accessible if they would be accessible when used
6657
+ to construct an object of the base class; the accessibility of the
6658
+ *using-declaration* is ignored.
 
6659
 
6660
+ [*Example 9*:
6661
 
6662
  ``` cpp
6663
  class A {
6664
  private:
6665
  void f(char);
 
6676
  };
6677
  ```
6678
 
6679
  — *end example*]
6680
 
 
 
 
 
6681
  ## The `asm` declaration <a id="dcl.asm">[[dcl.asm]]</a>
6682
 
6683
  An `asm` declaration has the form
6684
 
6685
  ``` bnf
 
6694
  [*Note 1*: Typically it is used to pass information through the
6695
  implementation to an assembler. — *end note*]
6696
 
6697
  ## Linkage specifications <a id="dcl.link">[[dcl.link]]</a>
6698
 
6699
+ All functions and variables whose names have external linkage and all
6700
+ function types have a *language linkage*.
6701
 
6702
  [*Note 1*: Some of the properties associated with an entity with
6703
  language linkage are specific to each implementation and are not
6704
+ described here. For example, a particular language linkage might be
6705
  associated with a particular form of representing names of objects and
6706
  functions with external linkage, or with a particular calling
6707
  convention, etc. — *end note*]
6708
 
6709
+ The default language linkage of all function types, functions, and
6710
+ variables is C++ language linkage. Two function types with different
6711
+ language linkages are distinct types even if they are otherwise
6712
+ identical.
6713
 
6714
  Linkage [[basic.link]] between C++ and non-C++ code fragments can be
6715
  achieved using a *linkage-specification*:
6716
 
6717
  ``` bnf
6718
  linkage-specification:
6719
  extern string-literal '{' declaration-seqₒₚₜ '}'
6720
+ extern string-literal name-declaration
6721
  ```
6722
 
6723
  The *string-literal* indicates the required language linkage. This
6724
  document specifies the semantics for the *string-literal*s `"C"` and
6725
  `"C++"`. Use of a *string-literal* other than `"C"` or `"C++"` is
 
6727
 
6728
  [*Note 2*: Therefore, a linkage-specification with a *string-literal*
6729
  that is unknown to the implementation requires a
6730
  diagnostic. — *end note*]
6731
 
6732
+ *Recommended practice:* The spelling of the *string-literal* should be
6733
+ taken from the document defining that language. For example, `Ada` (not
6734
+ `ADA`) and `Fortran` or `FORTRAN`, depending on the vintage.
 
6735
 
6736
+ Every implementation shall provide for linkage to the C programming
6737
+ language, `"C"`, and C++, `"C++"`.
 
6738
 
6739
  [*Example 1*:
6740
 
6741
  ``` cpp
6742
+ complex sqrt(complex); // C++{} language linkage by default
6743
  extern "C" {
6744
+ double sqrt(double); // C language linkage
6745
  }
6746
  ```
6747
 
6748
  — *end example*]
6749
 
6750
+ A *module-import-declaration* appearing in a linkage specification with
6751
+ other than C++ language linkage is conditionally-supported with
6752
+ *implementation-defined* semantics.
 
6753
 
6754
  Linkage specifications nest. When linkage specifications nest, the
6755
+ innermost one determines the language linkage.
6756
+
6757
+ [*Note 3*: A linkage specification does not establish a
6758
+ scope. *end note*]
6759
+
6760
+ A *linkage-specification* shall inhabit a namespace scope. In a
6761
+ *linkage-specification*, the specified language linkage applies to the
6762
+ function types of all function declarators and to all functions and
6763
+ variables whose names have external linkage.
6764
 
6765
  [*Example 2*:
6766
 
6767
  ``` cpp
6768
+ extern "C" // f1 and its function type have C language linkage;
6769
  void f1(void(*pf)(int)); // pf is a pointer to a C function
6770
 
6771
  extern "C" typedef void FUNC();
6772
+ FUNC f2; // f2 has C++{} language linkage and
6773
+ // its type has C language linkage
6774
 
6775
+ extern "C" FUNC f3; // f3 and its type have C language linkage
6776
 
6777
+ void (*pf2)(FUNC*); // the variable pf2 has C++{} language linkage; its type
6778
+ // is ``pointer to C++{} function that takes one parameter of type
6779
  // pointer to C function''
6780
  extern "C" {
6781
+ static void f4(); // the name of the function f4 has internal linkage,
6782
+ // so f4 has no language linkage; its type has C language linkage
6783
  }
6784
 
6785
  extern "C" void f5() {
6786
+ extern void f4(); // OK, name linkage (internal) and function type linkage (C language linkage)
6787
  // obtained from previous declaration.
6788
  }
6789
 
6790
+ extern void f4(); // OK, name linkage (internal) and function type linkage (C language linkage)
6791
  // obtained from previous declaration.
6792
 
6793
  void f6() {
6794
+ extern void f4(); // OK, name linkage (internal) and function type linkage (C language linkage)
6795
  // obtained from previous declaration.
6796
  }
6797
  ```
6798
 
6799
  — *end example*]
6800
 
6801
  A C language linkage is ignored in determining the language linkage of
6802
+ class members, friend functions with a trailing *requires-clause*, and
6803
+ the function type of non-static class member functions.
6804
 
6805
  [*Example 3*:
6806
 
6807
  ``` cpp
6808
  extern "C" typedef void FUNC_c();
6809
 
6810
  class C {
6811
+ void mf1(FUNC_c*); // the function mf1 and its type have C++{} language linkage;
6812
+ // the parameter has type ``pointer to C function''
6813
 
6814
+ FUNC_c mf2; // the function mf2 and its type have C++{} language linkage
 
6815
 
6816
+ static FUNC_c* q; // the data member q has C++{} language linkage;
6817
+ // its type is ``pointer to C function''
6818
  };
6819
 
6820
  extern "C" {
6821
  class X {
6822
+ void mf(); // the function mf and its type have C++{} language linkage
6823
+ void mf2(void(*)()); // the function mf2 has C++{} language linkage;
 
6824
  // the parameter has type ``pointer to C function''
6825
  };
6826
  }
6827
  ```
6828
 
6829
  — *end example*]
6830
 
6831
+ If two declarations of an entity give it different language linkages,
6832
+ the program is ill-formed; no diagnostic is required if neither
6833
+ declaration is reachable from the other. A redeclaration of an entity
6834
+ without a linkage specification inherits the language linkage of the
6835
+ entity and (if applicable) its type.
 
 
 
 
 
 
 
6836
 
6837
+ Two declarations declare the same entity if they (re)introduce the same
6838
+ name, one declares a function or variable with C language linkage, and
6839
+ the other declares such an entity or declares a variable that belongs to
6840
+ the global scope.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6841
 
6842
  [*Example 4*:
6843
 
6844
  ``` cpp
6845
  int x;
 
6879
  extern "C" static void g(); // error
6880
  ```
6881
 
6882
  — *end example*]
6883
 
6884
+ [*Note 4*: Because the language linkage is part of a function type,
6885
  when indirecting through a pointer to C function, the function to which
6886
  the resulting lvalue refers is considered a C function. — *end note*]
6887
 
6888
  Linkage from C++ to objects defined in other languages and to objects
6889
  defined in C++ from other languages is *implementation-defined* and
 
7006
  name lookup [[basic.lookup]] is performed on any of the identifiers
7007
  contained in an *attribute-token*. The *attribute-token* determines
7008
  additional requirements on the *attribute-argument-clause* (if any).
7009
 
7010
  Each *attribute-specifier-seq* is said to *appertain* to some entity or
7011
+ statement, identified by the syntactic context where it appears
7012
+ [[stmt.stmt]], [[dcl.dcl]], [[dcl.decl]]. If an
7013
  *attribute-specifier-seq* that appertains to some entity or statement
7014
  contains an *attribute* or *alignment-specifier* that is not allowed to
7015
  apply to that entity or statement, the program is ill-formed. If an
7016
  *attribute-specifier-seq* appertains to a friend declaration
7017
  [[class.friend]], that declaration shall be a definition.
7018
 
7019
  [*Note 3*: An *attribute-specifier-seq* cannot appeartain to an
7020
  explicit instantiation [[temp.explicit]]. — *end note*]
7021
 
7022
  For an *attribute-token* (including an *attribute-scoped-token*) not
7023
+ specified in this document, the behavior is *implementation-defined*;
7024
+ any such *attribute-token* that is not recognized by the implementation
7025
+ is ignored.
7026
+
7027
+ [*Note 4*: A program is ill-formed if it contains an *attribute*
7028
+ specified in [[dcl.attr]] that violates the rules specifying to which
7029
+ entity or statement the attribute can apply or the syntax rules for the
7030
+ attribute’s *attribute-argument-clause*, if any. — *end note*]
7031
+
7032
+ [*Note 5*: The *attribute*s specified in [[dcl.attr]] have optional
7033
+ semantics: given a well-formed program, removing all instances of any
7034
+ one of those *attribute*s results in a program whose set of possible
7035
+ executions [[intro.abstract]] for a given input is a subset of those of
7036
+ the original program for the same input, absent implementation-defined
7037
+ guarantees with respect to that *attribute*. — *end note*]
7038
+
7039
+ An *attribute-token* is reserved for future standardization if
7040
 
7041
  - it is not an *attribute-scoped-token* and is not specified in this
7042
  document, or
7043
  - it is an *attribute-scoped-token* and its *attribute-namespace* is
7044
  `std` followed by zero or more digits.
7045
 
7046
+ Each implementation should choose a distinctive name for the
7047
+ *attribute-namespace* in an *attribute-scoped-token*.
7048
 
7049
  Two consecutive left square bracket tokens shall appear only when
7050
  introducing an *attribute-specifier* or within the *balanced-token-seq*
7051
  of an *attribute-argument-clause*.
7052
 
7053
+ [*Note 6*: If two consecutive left square brackets appear where an
7054
  *attribute-specifier* is not allowed, the program is ill-formed even if
7055
  the brackets match an alternative grammar production. — *end note*]
7056
 
7057
  [*Example 2*:
7058
 
 
7157
  extern unsigned char c[sizeof(double)]; // error: different alignment in declaration
7158
  ```
7159
 
7160
  — *end example*]
7161
 
7162
+ ### Assumption attribute <a id="dcl.attr.assume">[[dcl.attr.assume]]</a>
7163
+
7164
+ The *attribute-token* `assume` may be applied to a null statement; such
7165
+ a statement is an *assumption*. An *attribute-argument-clause* shall be
7166
+ present and shall have the form:
7167
+
7168
+ ``` bnf
7169
+ '(' conditional-expression ')'
7170
+ ```
7171
+
7172
+ The expression is contextually converted to `bool` [[conv.general]]. The
7173
+ expression is not evaluated. If the converted expression would evaluate
7174
+ to `true` at the point where the assumption appears, the assumption has
7175
+ no effect. Otherwise, the behavior is undefined.
7176
+
7177
+ [*Note 1*: The expression is potentially evaluated [[basic.def.odr]].
7178
+ The use of assumptions is intended to allow implementations to analyze
7179
+ the form of the expression and deduce information used to optimize the
7180
+ program. Implementations are not required to deduce any information from
7181
+ any particular assumption. — *end note*]
7182
+
7183
+ [*Example 1*:
7184
+
7185
+ ``` cpp
7186
+ int divide_by_32(int x) {
7187
+ [[assume(x >= 0)]];
7188
+ return x/32; // The instructions produced for the division
7189
+ // may omit handling of negative values.
7190
+ }
7191
+ int f(int y) {
7192
+ [[assume(++y == 43)]]; // y is not incremented
7193
+ return y; // statement may be replaced with return 42;
7194
+ }
7195
+ ```
7196
+
7197
+ — *end example*]
7198
+
7199
  ### Carries dependency attribute <a id="dcl.attr.depend">[[dcl.attr.depend]]</a>
7200
 
7201
  The *attribute-token* `carries_dependency` specifies dependency
7202
+ propagation into and out of functions. No *attribute-argument-clause*
7203
+ shall be present. The attribute may be applied to a parameter of a
7204
+ function or lambda, in which case it specifies that the initialization
7205
+ of the parameter carries a dependency to [[intro.multithread]] each
7206
+ lvalue-to-rvalue conversion [[conv.lval]] of that object. The attribute
7207
+ may also be applied to a function or a lambda call operator, in which
7208
+ case it specifies that the return value, if any, carries a dependency to
7209
+ the evaluation of the function call expression.
 
 
7210
 
7211
  The first declaration of a function shall specify the
7212
  `carries_dependency` attribute for its *declarator-id* if any
7213
  declaration of the function specifies the `carries_dependency`
7214
  attribute. Furthermore, the first declaration of a function shall
 
7220
  parameters is declared without the `carries_dependency` attribute in its
7221
  first declaration in another translation unit, the program is
7222
  ill-formed, no diagnostic required.
7223
 
7224
  [*Note 1*: The `carries_dependency` attribute does not change the
7225
+ meaning of the program, but might result in generation of more efficient
7226
  code. — *end note*]
7227
 
7228
  [*Example 1*:
7229
 
7230
  ``` cpp
 
7276
  entities whose use is still allowed, but is discouraged for some reason.
7277
 
7278
  [*Note 1*: In particular, `deprecated` is appropriate for names and
7279
  entities that are deemed obsolescent or unsafe. — *end note*]
7280
 
7281
+ An *attribute-argument-clause* may be present and, if present, it shall
 
7282
  have the form:
7283
 
7284
  ``` bnf
7285
  '(' string-literal ')'
7286
  ```
7287
 
7288
+ [*Note 2*: The *string-literal* in the *attribute-argument-clause* can
7289
+ be used to explain the rationale for deprecation and/or to suggest a
7290
+ replacing entity. — *end note*]
7291
 
7292
  The attribute may be applied to the declaration of a class, a
7293
  *typedef-name*, a variable, a non-static data member, a function, a
7294
+ namespace, an enumeration, an enumerator, a concept, or a template
7295
+ specialization.
7296
 
7297
+ An entity declared without the `deprecated` attribute can later be
7298
+ redeclared with the attribute and vice-versa.
7299
 
7300
  [*Note 3*: Thus, an entity initially declared without the attribute can
7301
  be marked as deprecated by a subsequent redeclaration. However, after an
7302
  entity is marked as deprecated, later redeclarations do not un-deprecate
7303
  the entity. — *end note*]
 
7314
  attribute applied to the name or entity.
7315
 
7316
  ### Fallthrough attribute <a id="dcl.attr.fallthrough">[[dcl.attr.fallthrough]]</a>
7317
 
7318
  The *attribute-token* `fallthrough` may be applied to a null statement
7319
+ [[stmt.expr]]; such a statement is a fallthrough statement. No
7320
+ *attribute-argument-clause* shall be present. A fallthrough statement
7321
+ may only appear within an enclosing `switch` statement [[stmt.switch]].
7322
+ The next statement that would be executed after a fallthrough statement
7323
+ shall be a labeled statement whose label is a case label or default
7324
+ label for the same `switch` statement and, if the fallthrough statement
7325
+ is contained in an iteration statement, the next statement shall be part
7326
+ of the same execution of the substatement of the innermost enclosing
7327
+ iteration statement. The program is ill-formed if there is no such
7328
+ statement.
 
7329
 
7330
  *Recommended practice:* The use of a fallthrough statement should
7331
  suppress a warning that an implementation might otherwise issue for a
7332
  case or default label that is reachable from another case or default
7333
  label along some path of execution. Implementations should issue a
 
7367
  — *end example*]
7368
 
7369
  ### Likelihood attributes <a id="dcl.attr.likelihood">[[dcl.attr.likelihood]]</a>
7370
 
7371
  The *attribute-token*s `likely` and `unlikely` may be applied to labels
7372
+ or statements. No *attribute-argument-clause* shall be present. The
7373
+ *attribute-token* `likely` shall not appear in an
7374
+ *attribute-specifier-seq* that contains the *attribute-token*
7375
+ `unlikely`.
 
7376
 
7377
  *Recommended practice:* The use of the `likely` attribute is intended to
7378
  allow implementations to optimize for the case where paths of execution
7379
  including it are arbitrarily more likely than any alternative path of
7380
  execution that does not include such an attribute on a statement or
 
7414
  — *end example*]
7415
 
7416
  ### Maybe unused attribute <a id="dcl.attr.unused">[[dcl.attr.unused]]</a>
7417
 
7418
  The *attribute-token* `maybe_unused` indicates that a name or entity is
7419
+ possibly intentionally unused. No *attribute-argument-clause* shall be
7420
+ present.
7421
 
7422
  The attribute may be applied to the declaration of a class, a
7423
  *typedef-name*, a variable (including a structured binding declaration),
7424
  a non-static data member, a function, an enumeration, or an enumerator.
7425
 
 
7449
 
7450
  — *end example*]
7451
 
7452
  ### Nodiscard attribute <a id="dcl.attr.nodiscard">[[dcl.attr.nodiscard]]</a>
7453
 
7454
+ The *attribute-token* `nodiscard` may be applied to a function or a
7455
+ lambda call operator or to the declaration of a class or enumeration. An
 
7456
  *attribute-argument-clause* may be present and, if present, shall have
7457
  the form:
7458
 
7459
  ``` bnf
7460
  '(' string-literal ')'
 
7477
  is either
7478
 
7479
  - a function call expression [[expr.call]] that calls a function
7480
  declared `nodiscard` in a reachable declaration or whose return type
7481
  is a nodiscard type, or
7482
+ - an explicit type conversion
7483
+ [[expr.type.conv]], [[expr.static.cast]], [[expr.cast]] that
7484
+ constructs an object through a constructor declared `nodiscard` in a
7485
+ reachable declaration, or that initializes an object of a nodiscard
7486
+ type.
7487
 
7488
  *Recommended practice:* Appearance of a nodiscard call as a
7489
  potentially-evaluated discarded-value expression [[expr.prop]] is
7490
  discouraged unless explicitly cast to `void`. Implementations should
7491
  issue a warning in such cases.
 
7527
  — *end example*]
7528
 
7529
  ### Noreturn attribute <a id="dcl.attr.noreturn">[[dcl.attr.noreturn]]</a>
7530
 
7531
  The *attribute-token* `noreturn` specifies that a function does not
7532
+ return. No *attribute-argument-clause* shall be present. The attribute
7533
+ may be applied to a function or a lambda call operator. The first
 
7534
  declaration of a function shall specify the `noreturn` attribute if any
7535
  declaration of that function specifies the `noreturn` attribute. If a
7536
  function is declared with the `noreturn` attribute in one translation
7537
  unit and the same function is declared without the `noreturn` attribute
7538
  in another translation unit, the program is ill-formed, no diagnostic
 
7564
  — *end example*]
7565
 
7566
  ### No unique address attribute <a id="dcl.attr.nouniqueaddr">[[dcl.attr.nouniqueaddr]]</a>
7567
 
7568
  The *attribute-token* `no_unique_address` specifies that a non-static
7569
+ data member is a potentially-overlapping subobject [[intro.object]]. No
 
7570
  *attribute-argument-clause* shall be present. The attribute may
7571
  appertain to a non-static data member other than a bit-field.
7572
 
7573
  [*Note 1*: The non-static data member can share the address of another
7574
  non-static data member or that of a base class, and any padding that
 
7604
  [basic.fundamental]: basic.md#basic.fundamental
7605
  [basic.life]: basic.md#basic.life
7606
  [basic.link]: basic.md#basic.link
7607
  [basic.lookup]: basic.md#basic.lookup
7608
  [basic.lookup.argdep]: basic.md#basic.lookup.argdep
 
7609
  [basic.lookup.elab]: basic.md#basic.lookup.elab
7610
+ [basic.lookup.general]: basic.md#basic.lookup.general
7611
  [basic.lookup.qual]: basic.md#basic.lookup.qual
7612
  [basic.lookup.udir]: basic.md#basic.lookup.udir
7613
  [basic.lookup.unqual]: basic.md#basic.lookup.unqual
7614
  [basic.namespace]: #basic.namespace
7615
+ [basic.namespace.general]: #basic.namespace.general
 
 
7616
  [basic.scope.namespace]: basic.md#basic.scope.namespace
7617
+ [basic.scope.scope]: basic.md#basic.scope.scope
 
7618
  [basic.start]: basic.md#basic.start
7619
  [basic.start.dynamic]: basic.md#basic.start.dynamic
7620
  [basic.start.static]: basic.md#basic.start.static
7621
  [basic.stc]: basic.md#basic.stc
7622
  [basic.stc.auto]: basic.md#basic.stc.auto
 
7624
  [basic.stc.dynamic.allocation]: basic.md#basic.stc.dynamic.allocation
7625
  [basic.stc.dynamic.deallocation]: basic.md#basic.stc.dynamic.deallocation
7626
  [basic.stc.static]: basic.md#basic.stc.static
7627
  [basic.stc.thread]: basic.md#basic.stc.thread
7628
  [basic.type.qualifier]: basic.md#basic.type.qualifier
 
7629
  [class]: class.md#class
7630
  [class.access]: class.md#class.access
7631
+ [class.access.base]: class.md#class.access.base
7632
  [class.base.init]: class.md#class.base.init
7633
  [class.bit]: class.md#class.bit
 
 
7634
  [class.conv.ctor]: class.md#class.conv.ctor
7635
  [class.conv.fct]: class.md#class.conv.fct
7636
  [class.copy.assign]: class.md#class.copy.assign
7637
  [class.copy.ctor]: class.md#class.copy.ctor
7638
  [class.copy.elision]: class.md#class.copy.elision
 
7642
  [class.expl.init]: class.md#class.expl.init
7643
  [class.friend]: class.md#class.friend
7644
  [class.inhctor.init]: class.md#class.inhctor.init
7645
  [class.init]: class.md#class.init
7646
  [class.mem]: class.md#class.mem
7647
+ [class.mem.general]: class.md#class.mem.general
7648
+ [class.member.lookup]: basic.md#class.member.lookup
7649
  [class.mfct]: class.md#class.mfct
7650
  [class.mi]: class.md#class.mi
7651
  [class.name]: class.md#class.name
7652
  [class.pre]: class.md#class.pre
7653
  [class.qual]: basic.md#class.qual
 
7658
  [class.union.anon]: class.md#class.union.anon
7659
  [class.virtual]: class.md#class.virtual
7660
  [conv]: expr.md#conv
7661
  [conv.array]: expr.md#conv.array
7662
  [conv.func]: expr.md#conv.func
7663
+ [conv.general]: expr.md#conv.general
7664
+ [conv.integral]: expr.md#conv.integral
7665
  [conv.lval]: expr.md#conv.lval
7666
  [conv.prom]: expr.md#conv.prom
7667
  [conv.ptr]: expr.md#conv.ptr
7668
  [conv.qual]: expr.md#conv.qual
7669
  [conv.rval]: expr.md#conv.rval
 
7672
  [dcl.align]: #dcl.align
7673
  [dcl.ambig.res]: #dcl.ambig.res
7674
  [dcl.array]: #dcl.array
7675
  [dcl.asm]: #dcl.asm
7676
  [dcl.attr]: #dcl.attr
7677
+ [dcl.attr.assume]: #dcl.attr.assume
7678
  [dcl.attr.depend]: #dcl.attr.depend
7679
  [dcl.attr.deprecated]: #dcl.attr.deprecated
7680
  [dcl.attr.fallthrough]: #dcl.attr.fallthrough
7681
  [dcl.attr.grammar]: #dcl.attr.grammar
7682
  [dcl.attr.likelihood]: #dcl.attr.likelihood
 
7686
  [dcl.attr.unused]: #dcl.attr.unused
7687
  [dcl.constexpr]: #dcl.constexpr
7688
  [dcl.constinit]: #dcl.constinit
7689
  [dcl.dcl]: #dcl.dcl
7690
  [dcl.decl]: #dcl.decl
7691
+ [dcl.decl.general]: #dcl.decl.general
7692
  [dcl.enum]: #dcl.enum
7693
  [dcl.fct]: #dcl.fct
7694
  [dcl.fct.def]: #dcl.fct.def
7695
  [dcl.fct.def.coroutine]: #dcl.fct.def.coroutine
7696
  [dcl.fct.def.default]: #dcl.fct.def.default
 
7699
  [dcl.fct.default]: #dcl.fct.default
7700
  [dcl.fct.spec]: #dcl.fct.spec
7701
  [dcl.friend]: #dcl.friend
7702
  [dcl.init]: #dcl.init
7703
  [dcl.init.aggr]: #dcl.init.aggr
7704
+ [dcl.init.general]: #dcl.init.general
7705
  [dcl.init.list]: #dcl.init.list
7706
  [dcl.init.ref]: #dcl.init.ref
7707
  [dcl.init.string]: #dcl.init.string
7708
  [dcl.inline]: #dcl.inline
7709
  [dcl.link]: #dcl.link
7710
  [dcl.meaning]: #dcl.meaning
7711
+ [dcl.meaning.general]: #dcl.meaning.general
7712
  [dcl.mptr]: #dcl.mptr
7713
  [dcl.name]: #dcl.name
7714
  [dcl.pre]: #dcl.pre
7715
  [dcl.ptr]: #dcl.ptr
7716
  [dcl.ref]: #dcl.ref
7717
  [dcl.spec]: #dcl.spec
7718
  [dcl.spec.auto]: #dcl.spec.auto
7719
+ [dcl.spec.auto.general]: #dcl.spec.auto.general
7720
+ [dcl.spec.general]: #dcl.spec.general
7721
  [dcl.stc]: #dcl.stc
7722
  [dcl.struct.bind]: #dcl.struct.bind
7723
  [dcl.type]: #dcl.type
7724
  [dcl.type.auto.deduct]: #dcl.type.auto.deduct
7725
  [dcl.type.class.deduct]: #dcl.type.class.deduct
7726
  [dcl.type.cv]: #dcl.type.cv
7727
  [dcl.type.decltype]: #dcl.type.decltype
7728
  [dcl.type.elab]: #dcl.type.elab
7729
+ [dcl.type.general]: #dcl.type.general
7730
  [dcl.type.simple]: #dcl.type.simple
7731
  [dcl.typedef]: #dcl.typedef
7732
  [depr.volatile.type]: future.md#depr.volatile.type
7733
  [enum]: #enum
7734
  [enum.udecl]: #enum.udecl
7735
  [except.ctor]: except.md#except.ctor
7736
  [except.handle]: except.md#except.handle
7737
+ [except.pre]: except.md#except.pre
7738
  [except.spec]: except.md#except.spec
7739
  [except.throw]: except.md#except.throw
7740
  [expr.alignof]: expr.md#expr.alignof
7741
  [expr.ass]: expr.md#expr.ass
7742
  [expr.await]: expr.md#expr.await
7743
  [expr.call]: expr.md#expr.call
7744
  [expr.cast]: expr.md#expr.cast
7745
+ [expr.comma]: expr.md#expr.comma
7746
  [expr.const]: expr.md#expr.const
7747
  [expr.const.cast]: expr.md#expr.const.cast
7748
  [expr.mptr.oper]: expr.md#expr.mptr.oper
7749
  [expr.new]: expr.md#expr.new
7750
  [expr.post.incr]: expr.md#expr.post.incr
7751
  [expr.pre.incr]: expr.md#expr.pre.incr
7752
+ [expr.prim.id.unqual]: expr.md#expr.prim.id.unqual
7753
  [expr.prim.lambda]: expr.md#expr.prim.lambda
7754
  [expr.prim.this]: expr.md#expr.prim.this
7755
  [expr.prop]: expr.md#expr.prop
7756
  [expr.ref]: expr.md#expr.ref
7757
  [expr.static.cast]: expr.md#expr.static.cast
7758
  [expr.sub]: expr.md#expr.sub
7759
  [expr.type.conv]: expr.md#expr.type.conv
7760
  [expr.unary]: expr.md#expr.unary
7761
  [expr.unary.op]: expr.md#expr.unary.op
7762
  [expr.yield]: expr.md#expr.yield
7763
+ [initializer.list.syn]: support.md#initializer.list.syn
7764
+ [intro.abstract]: intro.md#intro.abstract
7765
  [intro.compliance]: intro.md#intro.compliance
7766
  [intro.execution]: basic.md#intro.execution
7767
  [intro.multithread]: basic.md#intro.multithread
7768
  [intro.object]: basic.md#intro.object
 
7769
  [lex.digraph]: lex.md#lex.digraph
7770
  [lex.key]: lex.md#lex.key
7771
  [lex.name]: lex.md#lex.name
7772
  [lex.string]: lex.md#lex.string
7773
  [module.interface]: module.md#module.interface
7774
+ [module.reach]: module.md#module.reach
7775
+ [module.unit]: module.md#module.unit
7776
  [namespace.alias]: #namespace.alias
7777
  [namespace.def]: #namespace.def
7778
+ [namespace.def.general]: #namespace.def.general
7779
  [namespace.qual]: basic.md#namespace.qual
7780
  [namespace.udecl]: #namespace.udecl
7781
  [namespace.udir]: #namespace.udir
7782
  [namespace.unnamed]: #namespace.unnamed
7783
  [over]: over.md#over
7784
  [over.binary]: over.md#over.binary
7785
+ [over.literal]: over.md#over.literal
7786
  [over.match]: over.md#over.match
7787
  [over.match.best]: over.md#over.match.best
7788
  [over.match.class.deduct]: over.md#over.match.class.deduct
7789
  [over.match.conv]: over.md#over.match.conv
7790
  [over.match.copy]: over.md#over.match.copy
 
7794
  [over.match.ref]: over.md#over.match.ref
7795
  [over.match.viable]: over.md#over.match.viable
7796
  [over.oper]: over.md#over.oper
7797
  [over.sub]: over.md#over.sub
7798
  [special]: class.md#special
7799
+ [std.modules]: library.md#std.modules
7800
  [stmt.ambig]: stmt.md#stmt.ambig
7801
  [stmt.dcl]: stmt.md#stmt.dcl
7802
  [stmt.expr]: stmt.md#stmt.expr
7803
  [stmt.if]: stmt.md#stmt.if
7804
  [stmt.iter]: stmt.md#stmt.iter
 
 
7805
  [stmt.return]: stmt.md#stmt.return
7806
  [stmt.return.coroutine]: stmt.md#stmt.return.coroutine
7807
  [stmt.select]: stmt.md#stmt.select
7808
  [stmt.stmt]: stmt.md#stmt.stmt
7809
  [stmt.switch]: stmt.md#stmt.switch
7810
  [support.runtime]: support.md#support.runtime
7811
  [temp.arg.type]: temp.md#temp.arg.type
7812
+ [temp.decls]: temp.md#temp.decls
7813
  [temp.deduct]: temp.md#temp.deduct
7814
  [temp.deduct.call]: temp.md#temp.deduct.call
7815
+ [temp.deduct.decl]: temp.md#temp.deduct.decl
7816
  [temp.deduct.guide]: temp.md#temp.deduct.guide
7817
+ [temp.dep.type]: temp.md#temp.dep.type
7818
  [temp.expl.spec]: temp.md#temp.expl.spec
7819
  [temp.explicit]: temp.md#temp.explicit
7820
  [temp.fct]: temp.md#temp.fct
7821
  [temp.inst]: temp.md#temp.inst
7822
  [temp.local]: temp.md#temp.local
 
7823
  [temp.names]: temp.md#temp.names
 
7824
  [temp.param]: temp.md#temp.param
7825
  [temp.pre]: temp.md#temp.pre
7826
  [temp.res]: temp.md#temp.res
7827
+ [temp.spec.partial]: temp.md#temp.spec.partial
7828
  [temp.variadic]: temp.md#temp.variadic
7829
+ [term.odr.use]: basic.md#term.odr.use
7830
+ [term.padding.bits]: basic.md#term.padding.bits
7831
+ [term.scalar.type]: basic.md#term.scalar.type
7832
+ [term.unevaluated.operand]: expr.md#term.unevaluated.operand
7833
 
7834
  [^1]: There is no special provision for a *decl-specifier-seq* that
7835
  lacks a *type-specifier* or that has a *type-specifier* that only
7836
  specifies *cv-qualifier*s. The “implicit int” rule of C is no longer
7837
  supported.
 
7859
  reference type.
7860
 
7861
  [^8]: Implementations are permitted to provide additional predefined
7862
  variables with names that are reserved to the implementation
7863
  [[lex.name]]. If a predefined variable is not odr-used
7864
+ [[term.odr.use]], its string value need not be present in the
7865
  program image.
7866
 
7867
  [^9]: This set of values is used to define promotion and conversion
7868
  semantics for the enumeration type. It does not preclude an
7869
  expression of enumeration type from having a value that falls
7870
  outside this range.
7871
 
7872
+ [^10]: During name lookup in a class hierarchy, some ambiguities can be
 
 
 
7873
  resolved by considering whether one member hides the other along
7874
+ some paths [[class.member.lookup]]. There is no such
7875
+ disambiguation when considering the set of names found as a result
7876
+ of following \*using-directive\*s.
7877
 
7878
+ [^11]: A *using-declaration* with more than one *using-declarator* is
7879
  equivalent to a corresponding sequence of *using-declaration*s with
7880
  one *using-declarator* each.