From Jason Turner

[dcl.fct.default]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpr93t4b0i/{from.md → to.md} +26 -21
tmp/tmpr93t4b0i/{from.md → to.md} RENAMED
@@ -26,20 +26,19 @@ respectively.
26
 
27
  — *end example*]
28
 
29
  A default argument shall be specified only in the
30
  *parameter-declaration-clause* of a function declaration or
31
- *lambda-declarator* or in a *template-parameter* [[temp.param]]; in the
32
- latter case, the *initializer-clause* shall be an
33
- *assignment-expression*. A default argument shall not be specified for a
34
- template parameter pack or a function parameter pack. If it is specified
35
- in a *parameter-declaration-clause*, it shall not occur within a
36
- *declarator* or *abstract-declarator* of a *parameter-declaration*.[^4]
37
 
38
  For non-template functions, default arguments can be added in later
39
- declarations of a function that inhabit the same scope. Declarations
40
- that inhabit different scopes have completely distinct sets of default
41
  arguments. That is, declarations in inner scopes do not acquire default
42
  arguments from declarations in outer scopes, and vice versa. In a given
43
  function declaration, each parameter subsequent to a parameter with a
44
  default argument shall have a default argument supplied in this or a
45
  previous declaration, unless the parameter was expanded from a parameter
@@ -120,19 +119,19 @@ void h() {
120
 
121
  [*Note 3*: A default argument is a complete-class context
122
  [[class.mem]]. Access checking applies to names in default arguments as
123
  described in [[class.access]]. — *end note*]
124
 
125
- Except for member functions of class templates, the default arguments in
126
- a member function definition that appears outside of the class
127
  definition are added to the set of default arguments provided by the
128
  member function declaration in the class definition; the program is
129
  ill-formed if a default constructor [[class.default.ctor]], copy or move
130
  constructor [[class.copy.ctor]], or copy or move assignment operator
131
  [[class.copy.assign]] is so declared. Default arguments for a member
132
- function of a class template shall be specified on the initial
133
- declaration of the member function within the class template.
134
 
135
  [*Example 4*:
136
 
137
  ``` cpp
138
  class C {
@@ -197,14 +196,17 @@ int g(float I, int b = I(2)); // error: parameter I found
197
  int h(int a, int b = sizeof(a)); // OK, unevaluated operand[term.unevaluated.operand]
198
  ```
199
 
200
  — *end example*]
201
 
202
- A non-static member shall not appear in a default argument unless it
203
- appears as the *id-expression* of a class member access expression
204
- [[expr.ref]] or unless it is used to form a pointer to member
205
- [[expr.unary.op]].
 
 
 
206
 
207
  [*Example 8*:
208
 
209
  The declaration of `X::mem1()` in the following example is ill-formed
210
  because no object is supplied for the non-static member `X::a` used as
@@ -213,11 +215,13 @@ an initializer.
213
  ``` cpp
214
  int b;
215
  class X {
216
  int a;
217
  int mem1(int i = a); // error: non-static member a used as default argument
218
- int mem2(int i = b); // OK; use X::b
 
 
219
  static int b;
220
  };
221
  ```
222
 
223
  The declaration of `X::mem2()` is meaningful, however, since no object
@@ -242,15 +246,16 @@ int (*p1)(int) = &f;
242
  int (*p2)() = &f; // error: type mismatch
243
  ```
244
 
245
  — *end example*]
246
 
247
- When an overload set contains a declaration of a function that inhabits
248
- a scope S, any default argument associated with any reachable
249
- declaration that inhabits S is available to the call.
 
250
 
251
- [*Note 7*: The candidate might have been found through a
252
  *using-declarator* from which the declaration that provides the default
253
  argument is not reachable. — *end note*]
254
 
255
  A virtual function call [[class.virtual]] uses the default arguments in
256
  the declaration of the virtual function determined by the static type of
 
26
 
27
  — *end example*]
28
 
29
  A default argument shall be specified only in the
30
  *parameter-declaration-clause* of a function declaration or
31
+ *lambda-declarator* or in a *template-parameter* [[temp.param]]. A
32
+ default argument shall not be specified for a template parameter pack or
33
+ a function parameter pack. If it is specified in a
34
+ *parameter-declaration-clause*, it shall not occur within a *declarator*
35
+ or *abstract-declarator* of a *parameter-declaration*.[^4]
 
36
 
37
  For non-template functions, default arguments can be added in later
38
+ declarations of a function that have the same host scope. Declarations
39
+ that have different host scopes have completely distinct sets of default
40
  arguments. That is, declarations in inner scopes do not acquire default
41
  arguments from declarations in outer scopes, and vice versa. In a given
42
  function declaration, each parameter subsequent to a parameter with a
43
  default argument shall have a default argument supplied in this or a
44
  previous declaration, unless the parameter was expanded from a parameter
 
119
 
120
  [*Note 3*: A default argument is a complete-class context
121
  [[class.mem]]. Access checking applies to names in default arguments as
122
  described in [[class.access]]. — *end note*]
123
 
124
+ Except for member functions of templated classes, the default arguments
125
+ in a member function definition that appears outside of the class
126
  definition are added to the set of default arguments provided by the
127
  member function declaration in the class definition; the program is
128
  ill-formed if a default constructor [[class.default.ctor]], copy or move
129
  constructor [[class.copy.ctor]], or copy or move assignment operator
130
  [[class.copy.assign]] is so declared. Default arguments for a member
131
+ function of a templated class shall be specified on the initial
132
+ declaration of the member function within the templated class.
133
 
134
  [*Example 4*:
135
 
136
  ``` cpp
137
  class C {
 
196
  int h(int a, int b = sizeof(a)); // OK, unevaluated operand[term.unevaluated.operand]
197
  ```
198
 
199
  — *end example*]
200
 
201
+ A non-static member shall not be designated in a default argument unless
202
+
203
+ - it is designated by the *id-expression* or *splice-expression* of a
204
+ class member access expression [[expr.ref]],
205
+ - it is designated by an expression used to form a pointer to member
206
+ [[expr.unary.op]], or
207
+ - it appears as the operand of a *reflect-expression* [[expr.reflect]].
208
 
209
  [*Example 8*:
210
 
211
  The declaration of `X::mem1()` in the following example is ill-formed
212
  because no object is supplied for the non-static member `X::a` used as
 
215
  ``` cpp
216
  int b;
217
  class X {
218
  int a;
219
  int mem1(int i = a); // error: non-static member a used as default argument
220
+ int mem2(int i = b); // OK, use X::b
221
+ consteval void mem3(std::meta::info r = ^^a) {} // OK
222
+ int mem4(int i = [:^^a:]); // error: non-static member a designated in default argument
223
  static int b;
224
  };
225
  ```
226
 
227
  The declaration of `X::mem2()` is meaningful, however, since no object
 
246
  int (*p2)() = &f; // error: type mismatch
247
  ```
248
 
249
  — *end example*]
250
 
251
+ [*Note 7*: When an overload set contains a declaration of a function
252
+ whose host scope is S, any default argument associated with any
253
+ reachable declaration whose host scope is S is available to the call
254
+ [[over.match.viable]]. — *end note*]
255
 
256
+ [*Note 8*: The candidate might have been found through a
257
  *using-declarator* from which the declaration that provides the default
258
  argument is not reachable. — *end note*]
259
 
260
  A virtual function call [[class.virtual]] uses the default arguments in
261
  the declaration of the virtual function determined by the static type of