From Jason Turner

[dcl.meaning]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmphh600ljr/{from.md → to.md} +305 -134
tmp/tmphh600ljr/{from.md → to.md} RENAMED
@@ -1,38 +1,134 @@
1
  ### Meaning of declarators <a id="dcl.meaning">[[dcl.meaning]]</a>
2
 
3
- A declarator contains exactly one *declarator-id*; it names the
4
- identifier that is declared. An *unqualified-id* occurring in a
5
- *declarator-id* shall be a simple *identifier* except for the
6
- declaration of some special functions ([[class.ctor]], [[class.conv]],
7
- [[class.dtor]], [[over.oper]]) and for the declaration of template
8
- specializations or partial specializations [[temp.spec]]. When the
9
- *declarator-id* is qualified, the declaration shall refer to a
10
- previously declared member of the class or namespace to which the
11
- qualifier refers (or, in the case of a namespace, of an element of the
12
- inline namespace set of that namespace [[namespace.def]]) or to a
13
- specialization thereof; the member shall not merely have been introduced
14
- by a *using-declaration* in the scope of the class or namespace
15
- nominated by the *nested-name-specifier* of the *declarator-id*. The
16
- *nested-name-specifier* of a qualified *declarator-id* shall not begin
17
- with a *decltype-specifier*.
18
 
19
- [*Note 1*: If the qualifier is the global `::` scope resolution
20
- operator, the *declarator-id* refers to a name declared in the global
21
- namespace scope. *end note*]
 
 
 
 
 
 
22
 
23
  The optional *attribute-specifier-seq* following a *declarator-id*
24
  appertains to the entity that is declared.
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  A `static`, `thread_local`, `extern`, `mutable`, `friend`, `inline`,
27
- `virtual`, `constexpr`, or `typedef` specifier or an
28
- *explicit-specifier* applies directly to each *declarator-id* in an
29
- *init-declarator-list* or *member-declarator-list*; the type specified
30
- for each *declarator-id* depends on both the *decl-specifier-seq* and
31
- its *declarator*.
32
 
33
- Thus, a declaration of a particular identifier has the form
34
 
35
  ``` cpp
36
  T D
37
  ```
38
 
@@ -47,11 +143,11 @@ First, the *decl-specifier-seq* determines a type. In a declaration
47
  T D
48
  ```
49
 
50
  the *decl-specifier-seq* `T` determines the type `T`.
51
 
52
- [*Example 1*:
53
 
54
  In the declaration
55
 
56
  ``` cpp
57
  int unsigned i;
@@ -61,11 +157,11 @@ the type specifiers `int` `unsigned` determine the type “`unsigned int`”
61
  [[dcl.type.simple]].
62
 
63
  — *end example*]
64
 
65
  In a declaration *attribute-specifier-seq*ₒₚₜ `T` `D` where `D` is an
66
- unadorned identifier the type of this identifier is “`T`”.
67
 
68
  In a declaration `T` `D` where `D` has the form
69
 
70
  ``` bnf
71
  '(' 'D1' ')'
@@ -87,17 +183,17 @@ In a declaration `T` `D` where `D` has the form
87
 
88
  ``` bnf
89
  '*' attribute-specifier-seqₒₚₜ cv-qualifier-seqₒₚₜ 'D1'
90
  ```
91
 
92
- and the type of the identifier in the declaration `T` `D1` is
93
- “*derived-declarator-type-list* `T`”, then the type of the identifier of
94
- `D` is “*derived-declarator-type-list* *cv-qualifier-seq* pointer to
95
- `T`”. The *cv-qualifier*s apply to the pointer and not to the object
96
- pointed to. Similarly, the optional *attribute-specifier-seq*
97
- [[dcl.attr.grammar]] appertains to the pointer and not to the object
98
- pointed to.
99
 
100
  [*Example 1*:
101
 
102
  The declarations
103
 
@@ -161,18 +257,18 @@ In a declaration `T` `D` where `D` has either of the forms
161
  ``` bnf
162
  '&' attribute-specifier-seqₒₚₜ 'D1'
163
  '&&' attribute-specifier-seqₒₚₜ 'D1'
164
  ```
165
 
166
- and the type of the identifier in the declaration `T` `D1` is
167
- “*derived-declarator-type-list* `T`”, then the type of the identifier of
168
- `D` is “*derived-declarator-type-list* reference to `T`”. The optional
169
- *attribute-specifier-seq* appertains to the reference type. Cv-qualified
170
- references are ill-formed except when the cv-qualifiers are introduced
171
- through the use of a *typedef-name* ([[dcl.typedef]], [[temp.param]])
172
- or *decltype-specifier* [[dcl.type.simple]], in which case the
173
- cv-qualifiers are ignored.
174
 
175
  [*Example 1*:
176
 
177
  ``` cpp
178
  typedef int& A;
@@ -261,12 +357,12 @@ well-defined program, because the only way to create such a reference
261
  would be to bind it to the “object” obtained by indirection through a
262
  null pointer, which causes undefined behavior. As described in 
263
  [[class.bit]], a reference cannot be bound directly to a
264
  bit-field. — *end note*]
265
 
266
- If a *typedef-name* ([[dcl.typedef]], [[temp.param]]) or a
267
- *decltype-specifier* [[dcl.type.simple]] denotes a type `TR` that is a
268
  reference to a type `T`, an attempt to create the type “lvalue reference
269
  to cv `TR`” creates the type “lvalue reference to `T`”, while an attempt
270
  to create the type “rvalue reference to cv `TR`” creates the type `TR`.
271
 
272
  [*Note 3*: This rule is known as reference collapsing. — *end note*]
@@ -295,19 +391,22 @@ decltype(r2)&& r7 = i; // r7 has the type int&
295
  function type has *cv-qualifier*s or a *ref-qualifier*; see 
296
  [[dcl.fct]]. — *end note*]
297
 
298
  #### Pointers to members <a id="dcl.mptr">[[dcl.mptr]]</a>
299
 
 
 
 
300
  In a declaration `T` `D` where `D` has the form
301
 
302
  ``` bnf
303
  nested-name-specifier '*' attribute-specifier-seqₒₚₜ cv-qualifier-seqₒₚₜ 'D1'
304
  ```
305
 
306
  and the *nested-name-specifier* denotes a class, and the type of the
307
- identifier in the declaration `T` `D1` is
308
- “*derived-declarator-type-list* `T`”, then the type of the identifier of
309
  `D` is “*derived-declarator-type-list* *cv-qualifier-seq* pointer to
310
  member of class *nested-name-specifier* of type `T`”. The optional
311
  *attribute-specifier-seq* [[dcl.attr.grammar]] appertains to the
312
  pointer-to-member.
313
 
@@ -382,12 +481,12 @@ unknown bound of `T`”, except as specified below.
382
  A type of the form “array of `N` `U`” or “array of unknown bound of `U`”
383
  is an *array type*. The optional *attribute-specifier-seq* appertains to
384
  the array type.
385
 
386
  `U` is called the array *element type*; this type shall not be a
387
- placeholder type [[dcl.spec.auto]], a reference type, a function type,
388
- an array of unknown bound, or cv `void`.
389
 
390
  [*Note 1*: An array can be constructed from one of the fundamental
391
  types (except `void`), from a pointer, from a pointer to member, from a
392
  class, from an enumeration type, or from an array of known
393
  bound. — *end note*]
@@ -418,39 +517,39 @@ typedef const AA CAA; // type is ``array of 2 array of 3 const int''
418
  — *end example*]
419
 
420
  [*Note 2*: An “array of `N` *cv-qualifier-seq* `U`” has cv-qualified
421
  type; see  [[basic.type.qualifier]]. — *end note*]
422
 
423
- An object of type “array of `N` `U`” contains a contiguously allocated
424
- non-empty set of `N` subobjects of type `U`, known as the *elements* of
425
- the array, and numbered `0` to `N-1`.
426
 
427
  In addition to declarations in which an incomplete object type is
428
  allowed, an array bound may be omitted in some cases in the declaration
429
  of a function parameter [[dcl.fct]]. An array bound may also be omitted
430
  when an object (but not a non-static data member) of array type is
431
- initialized and the declarator is followed by an initializer (
432
- [[dcl.init]], [[class.mem]], [[expr.type.conv]], [[expr.new]]). In these
433
  cases, the array bound is calculated from the number of initial elements
434
  (say, `N`) supplied [[dcl.init.aggr]], and the type of the array is
435
  “array of `N` `U`”.
436
 
437
- Furthermore, if there is a preceding declaration of the entity in the
438
- same scope in which the bound was specified, an omitted array bound is
439
- taken to be the same as in that earlier declaration, and similarly for
440
- the definition of a static data member of a class.
441
 
442
  [*Example 3*:
443
 
444
  ``` cpp
445
  extern int x[10];
446
  struct S {
447
  static int y[10];
448
  };
449
 
450
- int x[]; // OK: bound is 10
451
- int S::y[]; // OK: bound is 10
452
 
453
  void f() {
454
  extern int x[];
455
  int i = sizeof(x); // error: incomplete object type
456
  }
@@ -460,11 +559,11 @@ void f() {
460
 
461
  [*Note 3*:
462
 
463
  When several “array of” specifications are adjacent, a multidimensional
464
  array type is created; only the first of the constant expressions that
465
- specify the bounds of the arrays may be omitted.
466
 
467
  [*Example 4*:
468
 
469
  ``` cpp
470
  int x3d[3][5][7];
@@ -562,13 +661,13 @@ parameter-declaration-list:
562
  parameter-declaration-list ',' parameter-declaration
563
  ```
564
 
565
  ``` bnf
566
  parameter-declaration:
567
- attribute-specifier-seqₒₚₜ decl-specifier-seq declarator
568
  attribute-specifier-seqₒₚₜ decl-specifier-seq declarator '=' initializer-clause
569
- attribute-specifier-seqₒₚₜ decl-specifier-seq abstract-declaratorₒₚₜ
570
  attribute-specifier-seqₒₚₜ decl-specifier-seq abstract-declaratorₒₚₜ '=' initializer-clause
571
  ```
572
 
573
  The optional *attribute-specifier-seq* in a *parameter-declaration*
574
  appertains to the parameter.
@@ -617,12 +716,12 @@ However, the first argument must be of a type that can be converted to a
617
  accessing arguments passed using the ellipsis (see  [[expr.call]] and 
618
  [[support.runtime]]). — *end note*]
619
 
620
  The type of a function is determined using the following rules. The type
621
  of each parameter (including function parameter packs) is determined
622
- from its own *decl-specifier-seq* and *declarator*. After determining
623
- the type of each parameter, any parameter of type “array of `T`” or of
624
  function type `T` is adjusted to be “pointer to `T`”. After producing
625
  the list of parameter types, any top-level *cv-qualifier*s modifying a
626
  parameter type are deleted when forming the function type. The resulting
627
  list of transformed parameter types and the presence or absence of the
628
  ellipsis or a function parameter pack is the function’s
@@ -630,24 +729,94 @@ ellipsis or a function parameter pack is the function’s
630
 
631
  [*Note 3*: This transformation does not affect the types of the
632
  parameters. For example, `int(*)(const int p, decltype(p)*)` and
633
  `int(*)(int, const int*)` are identical types. — *end note*]
634
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
635
  A function type with a *cv-qualifier-seq* or a *ref-qualifier*
636
- (including a type named by *typedef-name* ([[dcl.typedef]],
637
- [[temp.param]])) shall appear only as:
638
 
639
  - the function type for a non-static member function,
640
  - the function type to which a pointer to member refers,
641
  - the top-level function type of a function typedef declaration or
642
  *alias-declaration*,
643
  - the *type-id* in the default argument of a *type-parameter*
644
  [[temp.param]], or
645
  - the *type-id* of a *template-argument* for a *type-parameter*
646
  [[temp.arg.type]].
647
 
648
- [*Example 2*:
649
 
650
  ``` cpp
651
  typedef int FIC(int) const;
652
  FIC f; // error: does not declare a member function
653
  struct S {
@@ -660,35 +829,35 @@ FIC S::*pm = &S::f; // OK
660
 
661
  The effect of a *cv-qualifier-seq* in a function declarator is not the
662
  same as adding cv-qualification on top of the function type. In the
663
  latter case, the cv-qualifiers are ignored.
664
 
665
- [*Note 4*: A function type that has a *cv-qualifier-seq* is not a
666
  cv-qualified type; there are no cv-qualified function
667
  types. — *end note*]
668
 
669
- [*Example 3*:
670
 
671
  ``` cpp
672
  typedef void F();
673
  struct S {
674
- const F f; // OK: equivalent to: void f();
675
  };
676
  ```
677
 
678
  — *end example*]
679
 
680
  The return type, the parameter-type-list, the *ref-qualifier*, the
681
  *cv-qualifier-seq*, and the exception specification, but not the default
682
  arguments [[dcl.fct.default]] or the trailing *requires-clause*
683
  [[dcl.decl]], are part of the function type.
684
 
685
- [*Note 5*: Function types are checked during the assignments and
686
  initializations of pointers to functions, references to functions, and
687
  pointers to member functions. — *end note*]
688
 
689
- [*Example 4*:
690
 
691
  The declaration
692
 
693
  ``` cpp
694
  int fseek(FILE*, long, int);
@@ -697,50 +866,46 @@ int fseek(FILE*, long, int);
697
  declares a function taking three arguments of the specified types, and
698
  returning `int` [[dcl.type]].
699
 
700
  — *end example*]
701
 
702
- A single name can be used for several different functions in a single
703
- scope; this is function overloading [[over]]. All declarations for a
704
- function shall have equivalent return types, parameter-type-lists, and
705
- *requires-clause*s [[temp.over.link]].
706
 
707
- Functions shall not have a return type of type array or function,
708
- although they may have a return type of type pointer or reference to
709
- such things. There shall be no arrays of functions, although there can
710
- be arrays of pointers to functions.
 
711
 
712
  A volatile-qualified return type is deprecated; see 
713
  [[depr.volatile.type]].
714
 
715
  Types shall not be defined in return or parameter types.
716
 
717
  A typedef of function type may be used to declare a function but shall
718
  not be used to define a function [[dcl.fct.def]].
719
 
720
- [*Example 5*:
721
 
722
  ``` cpp
723
  typedef void F();
724
- F fv; // OK: equivalent to void fv();
725
  F fv { } // error
726
- void fv() { } // OK: definition of fv
727
  ```
728
 
729
  — *end example*]
730
 
731
  An identifier can optionally be provided as a parameter name; if present
732
  in a function definition [[dcl.fct.def]], it names a parameter.
733
 
734
- [*Note 6*: In particular, parameter names are also optional in function
735
  definitions and names used for a parameter in different declarations and
736
- the definition of a function need not be the same. If a parameter name
737
- is present in a function declaration that is not a definition, it cannot
738
- be used outside of its function declarator because that is the extent of
739
- its potential scope [[basic.scope.param]]. — *end note*]
740
 
741
- [*Example 6*:
742
 
743
  The declaration
744
 
745
  ``` cpp
746
  int i,
@@ -766,15 +931,15 @@ calling of a function `fpi`, and then using indirection through the
766
  to indicate that indirection through a pointer to a function yields a
767
  function, which is then called.
768
 
769
  — *end example*]
770
 
771
- [*Note 7*:
772
 
773
  Typedefs and *trailing-return-type*s are sometimes convenient when the
774
  return type of a function is complex. For example, the function `fpif`
775
- above could have been declared
776
 
777
  ``` cpp
778
  typedef int IFUNC(int);
779
  IFUNC* fpif(int);
780
  ```
@@ -801,11 +966,11 @@ template <class T, class U> decltype((*(T*)0) + (*(U*)0)) add(T t, U u);
801
  — *end note*]
802
 
803
  A *non-template function* is a function that is not a function template
804
  specialization.
805
 
806
- [*Note 8*: A function template is not a function. — *end note*]
807
 
808
  An *abbreviated function template* is a function declaration that has
809
  one or more generic parameter type placeholders [[dcl.spec.auto]]. An
810
  abbreviated function template is equivalent to a function template
811
  [[temp.fct]] whose *template-parameter-list* includes one invented type
@@ -814,18 +979,18 @@ function declaration, in order of appearance. For a
814
  *placeholder-type-specifier* of the form `auto`, the invented parameter
815
  is an unconstrained *type-parameter*. For a *placeholder-type-specifier*
816
  of the form *type-constraint* `auto`, the invented parameter is a
817
  *type-parameter* with that *type-constraint*. The invented type
818
  *template-parameter* is a template parameter pack if the corresponding
819
- *parameter-declaration* declares a function parameter pack [[dcl.fct]].
820
- If the placeholder contains `decltype(auto)`, the program is ill-formed.
821
- The adjusted function parameters of an abbreviated function template are
822
  derived from the *parameter-declaration-clause* by replacing each
823
  occurrence of a placeholder with the name of the corresponding invented
824
  *template-parameter*.
825
 
826
- [*Example 7*:
827
 
828
  ``` cpp
829
  template<typename T> concept C1 = /* ... */;
830
  template<typename T> concept C2 = /* ... */;
831
  template<typename... Ts> concept C3 = /* ... */;
@@ -834,12 +999,12 @@ void g1(const C1 auto*, C2 auto&);
834
  void g2(C1 auto&...);
835
  void g3(C3 auto...);
836
  void g4(C3 auto);
837
  ```
838
 
839
- These declarations are functionally equivalent (but not equivalent) to
840
- the following declarations.
841
 
842
  ``` cpp
843
  template<C1 T, C2 U> void g1(const T*, U&);
844
  template<C1... Ts> void g2(Ts&...);
845
  template<C3... Ts> void g3(Ts...);
@@ -854,15 +1019,15 @@ template<> void g1<int>(const int*, const double&); // OK, specialization of g1<
854
  ```
855
 
856
  — *end example*]
857
 
858
  An abbreviated function template can have a *template-head*. The
859
- invented *template-parameters* are appended to the
860
  *template-parameter-list* after the explicitly declared
861
- *template-parameters*.
862
 
863
- [*Example 8*:
864
 
865
  ``` cpp
866
  template<typename> concept C = /* ... */;
867
 
868
  template <typename T, C U>
@@ -892,11 +1057,11 @@ only be used in a *parameter-declaration*. When it is part of a
892
  function parameter pack [[temp.variadic]]. Otherwise, the
893
  *parameter-declaration* is part of a *template-parameter-list* and
894
  declares a template parameter pack; see  [[temp.param]]. A function
895
  parameter pack is a pack expansion [[temp.variadic]].
896
 
897
- [*Example 9*:
898
 
899
  ``` cpp
900
  template<typename... T> void f(T (* ...t)(int, int));
901
 
902
  int add(int, int);
@@ -952,18 +1117,18 @@ latter case, the *initializer-clause* shall be an
952
  template parameter pack or a function parameter pack. If it is specified
953
  in a *parameter-declaration-clause*, it shall not occur within a
954
  *declarator* or *abstract-declarator* of a *parameter-declaration*.[^4]
955
 
956
  For non-template functions, default arguments can be added in later
957
- declarations of a function in the same scope. Declarations in different
958
- scopes have completely distinct sets of default arguments. That is,
959
- declarations in inner scopes do not acquire default arguments from
960
- declarations in outer scopes, and vice versa. In a given function
961
- declaration, each parameter subsequent to a parameter with a default
962
- argument shall have a default argument supplied in this or a previous
963
- declaration, unless the parameter was expanded from a parameter pack, or
964
- shall be a function parameter pack.
965
 
966
  [*Note 2*: A default argument cannot be redefined by a later
967
  declaration (not even to the same value)
968
  [[basic.def.odr]]. — *end note*]
969
 
@@ -997,22 +1162,26 @@ C<int> c; // OK, instantiates declaration void C::f(int n
997
  — *end example*]
998
 
999
  For a given inline function defined in different translation units, the
1000
  accumulated sets of default arguments at the end of the translation
1001
  units shall be the same; no diagnostic is required. If a friend
1002
- declaration specifies a default argument expression, that declaration
1003
- shall be a definition and shall be the only declaration of the function
1004
- or function template in the translation unit.
 
1005
 
1006
  The default argument has the same semantic constraints as the
1007
  initializer in a declaration of a variable of the parameter type, using
1008
  the copy-initialization semantics [[dcl.init]]. The names in the default
1009
- argument are bound, and the semantic constraints are checked, at the
1010
- point where the default argument appears. Name lookup and checking of
1011
- semantic constraints for default arguments in function templates and in
1012
- member functions of class templates are performed as described in 
1013
- [[temp.inst]].
 
 
 
1014
 
1015
  [*Example 3*:
1016
 
1017
  In the following code, `g` will be called with the value `f(2)`:
1018
 
@@ -1030,14 +1199,13 @@ void h() {
1030
  }
1031
  ```
1032
 
1033
  — *end example*]
1034
 
1035
- [*Note 3*: In member function declarations, names in default arguments
1036
- are looked up as described in  [[basic.lookup.unqual]]. Access checking
1037
- applies to names in default arguments as described in
1038
- [[class.access]]. — *end note*]
1039
 
1040
  Except for member functions of class templates, the default arguments in
1041
  a member function definition that appears outside of the class
1042
  definition are added to the set of default arguments provided by the
1043
  member function declaration in the class definition; the program is
@@ -1054,16 +1222,16 @@ class C {
1054
  void f(int i = 3);
1055
  void g(int i, int j = 99);
1056
  };
1057
 
1058
  void C::f(int i = 3) {} // error: default argument already specified in class scope
1059
- void C::g(int i = 88, int j) {} // in this translation unit, C::g can be called with no argument
1060
  ```
1061
 
1062
  — *end example*]
1063
 
1064
- [*Note 4*: A local variable cannot be odr-used [[basic.def.odr]] in a
1065
  default argument. — *end note*]
1066
 
1067
  [*Example 5*:
1068
 
1069
  ``` cpp
@@ -1077,11 +1245,11 @@ void f() {
1077
 
1078
  — *end example*]
1079
 
1080
  [*Note 5*:
1081
 
1082
- The keyword `this` may not appear in a default argument of a member
1083
  function; see  [[expr.prim.this]].
1084
 
1085
  [*Example 6*:
1086
 
1087
  ``` cpp
@@ -1094,22 +1262,24 @@ class A {
1094
 
1095
  — *end note*]
1096
 
1097
  A default argument is evaluated each time the function is called with no
1098
  argument for the corresponding parameter. A parameter shall not appear
1099
- as a potentially-evaluated expression in a default argument. Parameters
1100
- of a function declared before a default argument are in scope and can
1101
- hide namespace and class member names.
 
 
1102
 
1103
  [*Example 7*:
1104
 
1105
  ``` cpp
1106
  int a;
1107
  int f(int a, int b = a); // error: parameter a used as default argument
1108
  typedef int I;
1109
  int g(float I, int b = I(2)); // error: parameter I found
1110
- int h(int a, int b = sizeof(a)); // OK, unevaluated operand
1111
  ```
1112
 
1113
  — *end example*]
1114
 
1115
  A non-static member shall not appear in a default argument unless it
@@ -1155,16 +1325,17 @@ int (*p1)(int) = &f;
1155
  int (*p2)() = &f; // error: type mismatch
1156
  ```
1157
 
1158
  — *end example*]
1159
 
1160
- When a declaration of a function is introduced by way of a
1161
- *using-declaration* [[namespace.udecl]], any default argument
1162
- information associated with the declaration is made known as well. If
1163
- the function is redeclared thereafter in the namespace with additional
1164
- default arguments, the additional arguments are also known at any point
1165
- following the redeclaration where the *using-declaration* is in scope.
 
1166
 
1167
  A virtual function call [[class.virtual]] uses the default arguments in
1168
  the declaration of the virtual function determined by the static type of
1169
  the pointer or reference denoting the object. An overriding function in
1170
  a derived class does not acquire default arguments from the function it
 
1
  ### Meaning of declarators <a id="dcl.meaning">[[dcl.meaning]]</a>
2
 
3
+ #### General <a id="dcl.meaning.general">[[dcl.meaning.general]]</a>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
+ A declarator contains exactly one *declarator-id*; it names the entity
6
+ that is declared. If the *unqualified-id* occurring in a *declarator-id*
7
+ is a *template-id*, the declarator shall appear in the *declaration* of
8
+ a *template-declaration* [[temp.decls]], *explicit-specialization*
9
+ [[temp.expl.spec]], or *explicit-instantiation* [[temp.explicit]].
10
+
11
+ [*Note 1*: An *unqualified-id* that is not an *identifier* is used to
12
+ declare certain functions
13
+ [[class.conv.fct]], [[class.dtor]], [[over.oper]], [[over.literal]]. — *end note*]
14
 
15
  The optional *attribute-specifier-seq* following a *declarator-id*
16
  appertains to the entity that is declared.
17
 
18
+ If the declaration is a friend declaration:
19
+
20
+ - The *declarator* does not bind a name.
21
+ - If the *id-expression* E in the *declarator-id* of the *declarator* is
22
+ a *qualified-id* or a *template-id*:
23
+ - If the friend declaration is not a template declaration, then in the
24
+ lookup for the terminal name of E:
25
+ - if the *unqualified-id* in E is a *template-id*, all function
26
+ declarations are discarded;
27
+ - otherwise, if the *declarator* corresponds [[basic.scope.scope]]
28
+ to any declaration found of a non-template function, all function
29
+ template declarations are discarded;
30
+ - each remaining function template is replaced with the
31
+ specialization chosen by deduction from the friend declaration
32
+ [[temp.deduct.decl]] or discarded if deduction fails.
33
+ - The *declarator* shall correspond to one or more declarations found
34
+ by the lookup; they shall all have the same target scope, and the
35
+ target scope of the *declarator* is that scope.
36
+ - Otherwise, the terminal name of E is not looked up. The declaration’s
37
+ target scope is the innermost enclosing namespace scope; if the
38
+ declaration is contained by a block scope, the declaration shall
39
+ correspond to a reachable [[module.reach]] declaration that inhabits
40
+ the innermost block scope.
41
+
42
+ Otherwise:
43
+
44
+ - If the *id-expression* in the *declarator-id* of the *declarator* is a
45
+ *qualified-id* Q, let S be its lookup context [[basic.lookup.qual]];
46
+ the declaration shall inhabit a namespace scope.
47
+ - Otherwise, let S be the entity associated with the scope inhabited by
48
+ the *declarator*.
49
+ - If the *declarator* declares an explicit instantiation or a partial or
50
+ explicit specialization, the *declarator* does not bind a name. If it
51
+ declares a class member, the terminal name of the *declarator-id* is
52
+ not looked up; otherwise, only those lookup results that are nominable
53
+ in S are considered when identifying any function template
54
+ specialization being declared [[temp.deduct.decl]].
55
+ \[*Example 1*:
56
+ ``` cpp
57
+ namespace N {
58
+ inline namespace O {
59
+ template<class T> void f(T); // #1
60
+ template<class T> void g(T) {}
61
+ }
62
+ namespace P {
63
+ template<class T> void f(T*); // #2, more specialized than #1
64
+ template<class> int g;
65
+ }
66
+ using P::f,P::g;
67
+ }
68
+ template<> void N::f(int*) {} // OK, #2 is not nominable
69
+ template void N::g(int); // error: lookup is ambiguous
70
+ ```
71
+
72
+ — *end example*]
73
+ - Otherwise, the terminal name of the *declarator-id* is not looked up.
74
+ If it is a qualified name, the *declarator* shall correspond to one or
75
+ more declarations nominable in S; all the declarations shall have the
76
+ same target scope and the target scope of the *declarator* is that
77
+ scope.
78
+ \[*Example 2*:
79
+ ``` cpp
80
+ namespace Q {
81
+ namespace V {
82
+ void f();
83
+ }
84
+ void V::f() { ... } // OK
85
+ void V::g() { ... } // error: g() is not yet a member of V
86
+ namespace V {
87
+ void g();
88
+ }
89
+ }
90
+
91
+ namespace R {
92
+ void Q::V::g() { ... } // error: R doesn't enclose Q
93
+ }
94
+ ```
95
+
96
+ — *end example*]
97
+ - If the declaration inhabits a block scope S and declares a function
98
+ [[dcl.fct]] or uses the `extern` specifier, the declaration shall not
99
+ be attached to a named module [[module.unit]]; its target scope is the
100
+ innermost enclosing namespace scope, but the name is bound in S.
101
+ \[*Example 3*:
102
+ ``` cpp
103
+ namespace X {
104
+ void p() {
105
+ q(); // error: q not yet declared
106
+ extern void q(); // q is a member of namespace X
107
+ extern void r(); // r is a member of namespace X
108
+ }
109
+
110
+ void middle() {
111
+ q(); // error: q not found
112
+ }
113
+
114
+ void q() { ... } // definition of X::q
115
+ }
116
+
117
+ void q() { ... } // some other, unrelated q
118
+ void X::r() { ... } // error: r cannot be declared by qualified-id
119
+ ```
120
+
121
+ — *end example*]
122
+
123
  A `static`, `thread_local`, `extern`, `mutable`, `friend`, `inline`,
124
+ `virtual`, `constexpr`, `consteval`, `constinit`, or `typedef` specifier
125
+ or an *explicit-specifier* applies directly to each *declarator-id* in a
126
+ declaration; the type specified for each *declarator-id* depends on both
127
+ the *decl-specifier-seq* and its *declarator*.
 
128
 
129
+ Thus, (for each *declarator*) a declaration has the form
130
 
131
  ``` cpp
132
  T D
133
  ```
134
 
 
143
  T D
144
  ```
145
 
146
  the *decl-specifier-seq* `T` determines the type `T`.
147
 
148
+ [*Example 4*:
149
 
150
  In the declaration
151
 
152
  ``` cpp
153
  int unsigned i;
 
157
  [[dcl.type.simple]].
158
 
159
  — *end example*]
160
 
161
  In a declaration *attribute-specifier-seq*ₒₚₜ `T` `D` where `D` is an
162
+ unadorned name, the type of the declared entity is “`T`”.
163
 
164
  In a declaration `T` `D` where `D` has the form
165
 
166
  ``` bnf
167
  '(' 'D1' ')'
 
183
 
184
  ``` bnf
185
  '*' attribute-specifier-seqₒₚₜ cv-qualifier-seqₒₚₜ 'D1'
186
  ```
187
 
188
+ and the type of the contained *declarator-id* in the declaration `T`
189
+ `D1` is “*derived-declarator-type-list* `T`”, the type of the
190
+ *declarator-id* in `D` is “*derived-declarator-type-list*
191
+ *cv-qualifier-seq* pointer to `T`”. The *cv-qualifier*s apply to the
192
+ pointer and not to the object pointed to. Similarly, the optional
193
+ *attribute-specifier-seq* [[dcl.attr.grammar]] appertains to the pointer
194
+ and not to the object pointed to.
195
 
196
  [*Example 1*:
197
 
198
  The declarations
199
 
 
257
  ``` bnf
258
  '&' attribute-specifier-seqₒₚₜ 'D1'
259
  '&&' attribute-specifier-seqₒₚₜ 'D1'
260
  ```
261
 
262
+ and the type of the contained *declarator-id* in the declaration `T`
263
+ `D1` is “*derived-declarator-type-list* `T`”, the type of the
264
+ *declarator-id* in `D` is “*derived-declarator-type-list* reference to
265
+ `T`”. The optional *attribute-specifier-seq* appertains to the reference
266
+ type. Cv-qualified references are ill-formed except when the
267
+ cv-qualifiers are introduced through the use of a *typedef-name*
268
+ [[dcl.typedef]], [[temp.param]] or *decltype-specifier*
269
+ [[dcl.type.decltype]], in which case the cv-qualifiers are ignored.
270
 
271
  [*Example 1*:
272
 
273
  ``` cpp
274
  typedef int& A;
 
357
  would be to bind it to the “object” obtained by indirection through a
358
  null pointer, which causes undefined behavior. As described in 
359
  [[class.bit]], a reference cannot be bound directly to a
360
  bit-field. — *end note*]
361
 
362
+ If a *typedef-name* [[dcl.typedef]], [[temp.param]] or a
363
+ *decltype-specifier* [[dcl.type.decltype]] denotes a type `TR` that is a
364
  reference to a type `T`, an attempt to create the type “lvalue reference
365
  to cv `TR`” creates the type “lvalue reference to `T`”, while an attempt
366
  to create the type “rvalue reference to cv `TR`” creates the type `TR`.
367
 
368
  [*Note 3*: This rule is known as reference collapsing. — *end note*]
 
391
  function type has *cv-qualifier*s or a *ref-qualifier*; see 
392
  [[dcl.fct]]. — *end note*]
393
 
394
  #### Pointers to members <a id="dcl.mptr">[[dcl.mptr]]</a>
395
 
396
+ The component names of a *ptr-operator* are those of its
397
+ *nested-name-specifier*, if any.
398
+
399
  In a declaration `T` `D` where `D` has the form
400
 
401
  ``` bnf
402
  nested-name-specifier '*' attribute-specifier-seqₒₚₜ cv-qualifier-seqₒₚₜ 'D1'
403
  ```
404
 
405
  and the *nested-name-specifier* denotes a class, and the type of the
406
+ contained *declarator-id* in the declaration `T` `D1` is
407
+ “*derived-declarator-type-list* `T`”, the type of the *declarator-id* in
408
  `D` is “*derived-declarator-type-list* *cv-qualifier-seq* pointer to
409
  member of class *nested-name-specifier* of type `T`”. The optional
410
  *attribute-specifier-seq* [[dcl.attr.grammar]] appertains to the
411
  pointer-to-member.
412
 
 
481
  A type of the form “array of `N` `U`” or “array of unknown bound of `U`”
482
  is an *array type*. The optional *attribute-specifier-seq* appertains to
483
  the array type.
484
 
485
  `U` is called the array *element type*; this type shall not be a
486
+ reference type, a function type, an array of unknown bound, or
487
+ cv `void`.
488
 
489
  [*Note 1*: An array can be constructed from one of the fundamental
490
  types (except `void`), from a pointer, from a pointer to member, from a
491
  class, from an enumeration type, or from an array of known
492
  bound. — *end note*]
 
517
  — *end example*]
518
 
519
  [*Note 2*: An “array of `N` *cv-qualifier-seq* `U`” has cv-qualified
520
  type; see  [[basic.type.qualifier]]. — *end note*]
521
 
522
+ An object of type “array of `N` `U`” consists of a contiguously
523
+ allocated non-empty set of `N` subobjects of type `U`, known as the
524
+ *elements* of the array, and numbered `0` to `N-1`.
525
 
526
  In addition to declarations in which an incomplete object type is
527
  allowed, an array bound may be omitted in some cases in the declaration
528
  of a function parameter [[dcl.fct]]. An array bound may also be omitted
529
  when an object (but not a non-static data member) of array type is
530
+ initialized and the declarator is followed by an initializer
531
+ [[dcl.init]], [[class.mem]], [[expr.type.conv]], [[expr.new]]. In these
532
  cases, the array bound is calculated from the number of initial elements
533
  (say, `N`) supplied [[dcl.init.aggr]], and the type of the array is
534
  “array of `N` `U`”.
535
 
536
+ Furthermore, if there is a reachable declaration of the entity that
537
+ inhabits the same scope in which the bound was specified, an omitted
538
+ array bound is taken to be the same as in that earlier declaration, and
539
+ similarly for the definition of a static data member of a class.
540
 
541
  [*Example 3*:
542
 
543
  ``` cpp
544
  extern int x[10];
545
  struct S {
546
  static int y[10];
547
  };
548
 
549
+ int x[]; // OK, bound is 10
550
+ int S::y[]; // OK, bound is 10
551
 
552
  void f() {
553
  extern int x[];
554
  int i = sizeof(x); // error: incomplete object type
555
  }
 
559
 
560
  [*Note 3*:
561
 
562
  When several “array of” specifications are adjacent, a multidimensional
563
  array type is created; only the first of the constant expressions that
564
+ specify the bounds of the arrays can be omitted.
565
 
566
  [*Example 4*:
567
 
568
  ``` cpp
569
  int x3d[3][5][7];
 
661
  parameter-declaration-list ',' parameter-declaration
662
  ```
663
 
664
  ``` bnf
665
  parameter-declaration:
666
+ attribute-specifier-seqₒₚₜ thisₒₚₜ decl-specifier-seq declarator
667
  attribute-specifier-seqₒₚₜ decl-specifier-seq declarator '=' initializer-clause
668
+ attribute-specifier-seqₒₚₜ thisₒₚₜ decl-specifier-seq abstract-declaratorₒₚₜ
669
  attribute-specifier-seqₒₚₜ decl-specifier-seq abstract-declaratorₒₚₜ '=' initializer-clause
670
  ```
671
 
672
  The optional *attribute-specifier-seq* in a *parameter-declaration*
673
  appertains to the parameter.
 
716
  accessing arguments passed using the ellipsis (see  [[expr.call]] and 
717
  [[support.runtime]]). — *end note*]
718
 
719
  The type of a function is determined using the following rules. The type
720
  of each parameter (including function parameter packs) is determined
721
+ from its own *parameter-declaration* [[dcl.decl]]. After determining the
722
+ type of each parameter, any parameter of type “array of `T`” or of
723
  function type `T` is adjusted to be “pointer to `T`”. After producing
724
  the list of parameter types, any top-level *cv-qualifier*s modifying a
725
  parameter type are deleted when forming the function type. The resulting
726
  list of transformed parameter types and the presence or absence of the
727
  ellipsis or a function parameter pack is the function’s
 
729
 
730
  [*Note 3*: This transformation does not affect the types of the
731
  parameters. For example, `int(*)(const int p, decltype(p)*)` and
732
  `int(*)(int, const int*)` are identical types. — *end note*]
733
 
734
+ [*Example 2*:
735
+
736
+ ``` cpp
737
+ void f(char*); // #1
738
+ void f(char[]) {} // defines #1
739
+ void f(const char*) {} // OK, another overload
740
+ void f(char *const) {} // error: redefines #1
741
+
742
+ void g(char(*)[2]); // #2
743
+ void g(char[3][2]) {} // defines #2
744
+ void g(char[3][3]) {} // OK, another overload
745
+
746
+ void h(int x(const int)); // #3
747
+ void h(int (*)(int)) {} // defines #3
748
+ ```
749
+
750
+ — *end example*]
751
+
752
+ An *explicit-object-parameter-declaration* is a *parameter-declaration*
753
+ with a `this` specifier. An explicit-object-parameter-declaration shall
754
+ appear only as the first *parameter-declaration* of a
755
+ *parameter-declaration-list* of either:
756
+
757
+ - a *member-declarator* that declares a member function [[class.mem]],
758
+ or
759
+ - a *lambda-declarator* [[expr.prim.lambda]].
760
+
761
+ A *member-declarator* with an explicit-object-parameter-declaration
762
+ shall not include a *ref-qualifier* or a *cv-qualifier-seq* and shall
763
+ not be declared `static` or `virtual`.
764
+
765
+ [*Example 3*:
766
+
767
+ ``` cpp
768
+ struct C {
769
+ void f(this C& self);
770
+ template <typename Self> void g(this Self&& self, int);
771
+
772
+ void h(this C) const; // error: const not allowed here
773
+ };
774
+
775
+ void test(C c) {
776
+ c.f(); // OK, calls C::f
777
+ c.g(42); // OK, calls C::g<C&>
778
+ std::move(c).g(42); // OK, calls C::g<C>
779
+ }
780
+ ```
781
+
782
+ — *end example*]
783
+
784
+ A function parameter declared with an
785
+ explicit-object-parameter-declaration is an *explicit object parameter*.
786
+ An explicit object parameter shall not be a function parameter pack
787
+ [[temp.variadic]]. An *explicit object member function* is a non-static
788
+ member function with an explicit object parameter. An
789
+ *implicit object member function* is a non-static member function
790
+ without an explicit object parameter.
791
+
792
+ The *object parameter* of a non-static member function is either the
793
+ explicit object parameter or the implicit object parameter
794
+ [[over.match.funcs]].
795
+
796
+ A *non-object parameter* is a function parameter that is not the
797
+ explicit object parameter. The *non-object-parameter-type-list* of a
798
+ member function is the parameter-type-list of that function with the
799
+ explicit object parameter, if any, omitted.
800
+
801
+ [*Note 4*: The non-object-parameter-type-list consists of the adjusted
802
+ types of all the non-object parameters. — *end note*]
803
+
804
  A function type with a *cv-qualifier-seq* or a *ref-qualifier*
805
+ (including a type named by *typedef-name*
806
+ [[dcl.typedef]], [[temp.param]]) shall appear only as:
807
 
808
  - the function type for a non-static member function,
809
  - the function type to which a pointer to member refers,
810
  - the top-level function type of a function typedef declaration or
811
  *alias-declaration*,
812
  - the *type-id* in the default argument of a *type-parameter*
813
  [[temp.param]], or
814
  - the *type-id* of a *template-argument* for a *type-parameter*
815
  [[temp.arg.type]].
816
 
817
+ [*Example 4*:
818
 
819
  ``` cpp
820
  typedef int FIC(int) const;
821
  FIC f; // error: does not declare a member function
822
  struct S {
 
829
 
830
  The effect of a *cv-qualifier-seq* in a function declarator is not the
831
  same as adding cv-qualification on top of the function type. In the
832
  latter case, the cv-qualifiers are ignored.
833
 
834
+ [*Note 5*: A function type that has a *cv-qualifier-seq* is not a
835
  cv-qualified type; there are no cv-qualified function
836
  types. — *end note*]
837
 
838
+ [*Example 5*:
839
 
840
  ``` cpp
841
  typedef void F();
842
  struct S {
843
+ const F f; // OK, equivalent to: void f();
844
  };
845
  ```
846
 
847
  — *end example*]
848
 
849
  The return type, the parameter-type-list, the *ref-qualifier*, the
850
  *cv-qualifier-seq*, and the exception specification, but not the default
851
  arguments [[dcl.fct.default]] or the trailing *requires-clause*
852
  [[dcl.decl]], are part of the function type.
853
 
854
+ [*Note 6*: Function types are checked during the assignments and
855
  initializations of pointers to functions, references to functions, and
856
  pointers to member functions. — *end note*]
857
 
858
+ [*Example 6*:
859
 
860
  The declaration
861
 
862
  ``` cpp
863
  int fseek(FILE*, long, int);
 
866
  declares a function taking three arguments of the specified types, and
867
  returning `int` [[dcl.type]].
868
 
869
  — *end example*]
870
 
871
+ [*Note 7*: A single name can be used for several different functions in
872
+ a single scope; this is function overloading [[over]]. *end note*]
 
 
873
 
874
+ The return type shall be a non-array object type, a reference type, or
875
+ cv `void`.
876
+
877
+ [*Note 8*: An array of placeholder type is considered an array
878
+ type. — *end note*]
879
 
880
  A volatile-qualified return type is deprecated; see 
881
  [[depr.volatile.type]].
882
 
883
  Types shall not be defined in return or parameter types.
884
 
885
  A typedef of function type may be used to declare a function but shall
886
  not be used to define a function [[dcl.fct.def]].
887
 
888
+ [*Example 7*:
889
 
890
  ``` cpp
891
  typedef void F();
892
+ F fv; // OK, equivalent to void fv();
893
  F fv { } // error
894
+ void fv() { } // OK, definition of fv
895
  ```
896
 
897
  — *end example*]
898
 
899
  An identifier can optionally be provided as a parameter name; if present
900
  in a function definition [[dcl.fct.def]], it names a parameter.
901
 
902
+ [*Note 9*: In particular, parameter names are also optional in function
903
  definitions and names used for a parameter in different declarations and
904
+ the definition of a function need not be the same. *end note*]
 
 
 
905
 
906
+ [*Example 8*:
907
 
908
  The declaration
909
 
910
  ``` cpp
911
  int i,
 
931
  to indicate that indirection through a pointer to a function yields a
932
  function, which is then called.
933
 
934
  — *end example*]
935
 
936
+ [*Note 10*:
937
 
938
  Typedefs and *trailing-return-type*s are sometimes convenient when the
939
  return type of a function is complex. For example, the function `fpif`
940
+ above can be declared
941
 
942
  ``` cpp
943
  typedef int IFUNC(int);
944
  IFUNC* fpif(int);
945
  ```
 
966
  — *end note*]
967
 
968
  A *non-template function* is a function that is not a function template
969
  specialization.
970
 
971
+ [*Note 11*: A function template is not a function. — *end note*]
972
 
973
  An *abbreviated function template* is a function declaration that has
974
  one or more generic parameter type placeholders [[dcl.spec.auto]]. An
975
  abbreviated function template is equivalent to a function template
976
  [[temp.fct]] whose *template-parameter-list* includes one invented type
 
979
  *placeholder-type-specifier* of the form `auto`, the invented parameter
980
  is an unconstrained *type-parameter*. For a *placeholder-type-specifier*
981
  of the form *type-constraint* `auto`, the invented parameter is a
982
  *type-parameter* with that *type-constraint*. The invented type
983
  *template-parameter* is a template parameter pack if the corresponding
984
+ *parameter-declaration* declares a function parameter pack. If the
985
+ placeholder contains `decltype(auto)`, the program is ill-formed. The
986
+ adjusted function parameters of an abbreviated function template are
987
  derived from the *parameter-declaration-clause* by replacing each
988
  occurrence of a placeholder with the name of the corresponding invented
989
  *template-parameter*.
990
 
991
+ [*Example 9*:
992
 
993
  ``` cpp
994
  template<typename T> concept C1 = /* ... */;
995
  template<typename T> concept C2 = /* ... */;
996
  template<typename... Ts> concept C3 = /* ... */;
 
999
  void g2(C1 auto&...);
1000
  void g3(C3 auto...);
1001
  void g4(C3 auto);
1002
  ```
1003
 
1004
+ The declarations above are functionally equivalent (but not equivalent)
1005
+ to their respective declarations below:
1006
 
1007
  ``` cpp
1008
  template<C1 T, C2 U> void g1(const T*, U&);
1009
  template<C1... Ts> void g2(Ts&...);
1010
  template<C3... Ts> void g3(Ts...);
 
1019
  ```
1020
 
1021
  — *end example*]
1022
 
1023
  An abbreviated function template can have a *template-head*. The
1024
+ invented *template-parameter*s are appended to the
1025
  *template-parameter-list* after the explicitly declared
1026
+ *template-parameter*s.
1027
 
1028
+ [*Example 10*:
1029
 
1030
  ``` cpp
1031
  template<typename> concept C = /* ... */;
1032
 
1033
  template <typename T, C U>
 
1057
  function parameter pack [[temp.variadic]]. Otherwise, the
1058
  *parameter-declaration* is part of a *template-parameter-list* and
1059
  declares a template parameter pack; see  [[temp.param]]. A function
1060
  parameter pack is a pack expansion [[temp.variadic]].
1061
 
1062
+ [*Example 11*:
1063
 
1064
  ``` cpp
1065
  template<typename... T> void f(T (* ...t)(int, int));
1066
 
1067
  int add(int, int);
 
1117
  template parameter pack or a function parameter pack. If it is specified
1118
  in a *parameter-declaration-clause*, it shall not occur within a
1119
  *declarator* or *abstract-declarator* of a *parameter-declaration*.[^4]
1120
 
1121
  For non-template functions, default arguments can be added in later
1122
+ declarations of a function that inhabit the same scope. Declarations
1123
+ that inhabit different scopes have completely distinct sets of default
1124
+ arguments. That is, declarations in inner scopes do not acquire default
1125
+ arguments from declarations in outer scopes, and vice versa. In a given
1126
+ function declaration, each parameter subsequent to a parameter with a
1127
+ default argument shall have a default argument supplied in this or a
1128
+ previous declaration, unless the parameter was expanded from a parameter
1129
+ pack, or shall be a function parameter pack.
1130
 
1131
  [*Note 2*: A default argument cannot be redefined by a later
1132
  declaration (not even to the same value)
1133
  [[basic.def.odr]]. — *end note*]
1134
 
 
1162
  — *end example*]
1163
 
1164
  For a given inline function defined in different translation units, the
1165
  accumulated sets of default arguments at the end of the translation
1166
  units shall be the same; no diagnostic is required. If a friend
1167
+ declaration D specifies a default argument expression, that declaration
1168
+ shall be a definition and there shall be no other declaration of the
1169
+ function or function template which is reachable from D or from which D
1170
+ is reachable.
1171
 
1172
  The default argument has the same semantic constraints as the
1173
  initializer in a declaration of a variable of the parameter type, using
1174
  the copy-initialization semantics [[dcl.init]]. The names in the default
1175
+ argument are looked up, and the semantic constraints are checked, at the
1176
+ point where the default argument appears, except that an immediate
1177
+ invocation [[expr.const]] that is a potentially-evaluated subexpression
1178
+ [[intro.execution]] of the *initializer-clause* in a
1179
+ *parameter-declaration* is neither evaluated nor checked for whether it
1180
+ is a constant expression at that point. Name lookup and checking of
1181
+ semantic constraints for default arguments of templated functions are
1182
+ performed as described in  [[temp.inst]].
1183
 
1184
  [*Example 3*:
1185
 
1186
  In the following code, `g` will be called with the value `f(2)`:
1187
 
 
1199
  }
1200
  ```
1201
 
1202
  — *end example*]
1203
 
1204
+ [*Note 3*: A default argument is a complete-class context
1205
+ [[class.mem]]. Access checking applies to names in default arguments as
1206
+ described in [[class.access]]. *end note*]
 
1207
 
1208
  Except for member functions of class templates, the default arguments in
1209
  a member function definition that appears outside of the class
1210
  definition are added to the set of default arguments provided by the
1211
  member function declaration in the class definition; the program is
 
1222
  void f(int i = 3);
1223
  void g(int i, int j = 99);
1224
  };
1225
 
1226
  void C::f(int i = 3) {} // error: default argument already specified in class scope
1227
+ void C::g(int i = 88, int j) {} // in this translation unit, C::g can be called with no arguments
1228
  ```
1229
 
1230
  — *end example*]
1231
 
1232
+ [*Note 4*: A local variable cannot be odr-used [[term.odr.use]] in a
1233
  default argument. — *end note*]
1234
 
1235
  [*Example 5*:
1236
 
1237
  ``` cpp
 
1245
 
1246
  — *end example*]
1247
 
1248
  [*Note 5*:
1249
 
1250
+ The keyword `this` cannot appear in a default argument of a member
1251
  function; see  [[expr.prim.this]].
1252
 
1253
  [*Example 6*:
1254
 
1255
  ``` cpp
 
1262
 
1263
  — *end note*]
1264
 
1265
  A default argument is evaluated each time the function is called with no
1266
  argument for the corresponding parameter. A parameter shall not appear
1267
+ as a potentially-evaluated expression in a default argument.
1268
+
1269
+ [*Note 6*: Parameters of a function declared before a default argument
1270
+ are in scope and can hide namespace and class member
1271
+ names. — *end note*]
1272
 
1273
  [*Example 7*:
1274
 
1275
  ``` cpp
1276
  int a;
1277
  int f(int a, int b = a); // error: parameter a used as default argument
1278
  typedef int I;
1279
  int g(float I, int b = I(2)); // error: parameter I found
1280
+ int h(int a, int b = sizeof(a)); // OK, unevaluated operand[term.unevaluated.operand]
1281
  ```
1282
 
1283
  — *end example*]
1284
 
1285
  A non-static member shall not appear in a default argument unless it
 
1325
  int (*p2)() = &f; // error: type mismatch
1326
  ```
1327
 
1328
  — *end example*]
1329
 
1330
+ When an overload set contains a declaration of a function that inhabits
1331
+ a scope S, any default argument associated with any reachable
1332
+ declaration that inhabits S is available to the call.
1333
+
1334
+ [*Note 7*: The candidate might have been found through a
1335
+ *using-declarator* from which the declaration that provides the default
1336
+ argument is not reachable. — *end note*]
1337
 
1338
  A virtual function call [[class.virtual]] uses the default arguments in
1339
  the declaration of the virtual function determined by the static type of
1340
  the pointer or reference denoting the object. An overriding function in
1341
  a derived class does not acquire default arguments from the function it