From Jason Turner

[dcl.fct.default]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpwerxdl2x/{from.md → to.md} +49 -40
tmp/tmpwerxdl2x/{from.md → to.md} RENAMED
@@ -1,10 +1,12 @@
1
- ### Default arguments <a id="dcl.fct.default">[[dcl.fct.default]]</a>
2
 
3
  If an *initializer-clause* is specified in a *parameter-declaration*
4
- this *initializer-clause* is used as a default argument. Default
5
- arguments will be used in calls where trailing arguments are missing.
 
 
6
 
7
  [*Example 1*:
8
 
9
  The declaration
10
 
@@ -24,27 +26,30 @@ respectively.
24
 
25
  — *end example*]
26
 
27
  A default argument shall be specified only in the
28
  *parameter-declaration-clause* of a function declaration or
29
- *lambda-declarator* or in a *template-parameter* ([[temp.param]]); in
30
- the latter case, the *initializer-clause* shall be an
31
  *assignment-expression*. A default argument shall not be specified for a
32
- parameter pack. If it is specified in a *parameter-declaration-clause*,
33
- it shall not occur within a *declarator* or *abstract-declarator* of a
34
- *parameter-declaration*.[^10]
35
 
36
  For non-template functions, default arguments can be added in later
37
  declarations of a function in the same scope. Declarations in different
38
  scopes have completely distinct sets of default arguments. That is,
39
  declarations in inner scopes do not acquire default arguments from
40
  declarations in outer scopes, and vice versa. In a given function
41
  declaration, each parameter subsequent to a parameter with a default
42
  argument shall have a default argument supplied in this or a previous
43
- declaration or shall be a function parameter pack. A default argument
44
- shall not be redefined by a later declaration (not even to the same
45
- value).
 
 
 
46
 
47
  [*Example 2*:
48
 
49
  ``` cpp
50
  void g(int = 0, ...); // OK, ellipsis is not a parameter so it can follow
@@ -63,28 +68,32 @@ void m() {
63
  void f(int, int = 5); // error: cannot redefine, even to same value
64
  }
65
  void n() {
66
  f(6); // OK, calls f(6, 7)
67
  }
 
 
 
 
68
  ```
69
 
70
  — *end example*]
71
 
72
  For a given inline function defined in different translation units, the
73
  accumulated sets of default arguments at the end of the translation
74
- units shall be the same; see  [[basic.def.odr]]. If a friend declaration
75
- specifies a default argument expression, that declaration shall be a
76
- definition and shall be the only declaration of the function or function
77
- template in the translation unit.
78
 
79
  The default argument has the same semantic constraints as the
80
  initializer in a declaration of a variable of the parameter type, using
81
- the copy-initialization semantics ([[dcl.init]]). The names in the
82
- default argument are bound, and the semantic constraints are checked, at
83
- the point where the default argument appears. Name lookup and checking
84
- of semantic constraints for default arguments in function templates and
85
- in member functions of class templates are performed as described in 
86
  [[temp.inst]].
87
 
88
  [*Example 3*:
89
 
90
  In the following code, `g` will be called with the value `f(2)`:
@@ -103,24 +112,24 @@ void h() {
103
  }
104
  ```
105
 
106
  — *end example*]
107
 
108
- [*Note 1*: In member function declarations, names in default arguments
109
  are looked up as described in  [[basic.lookup.unqual]]. Access checking
110
- applies to names in default arguments as described in Clause 
111
  [[class.access]]. — *end note*]
112
 
113
  Except for member functions of class templates, the default arguments in
114
  a member function definition that appears outside of the class
115
  definition are added to the set of default arguments provided by the
116
  member function declaration in the class definition; the program is
117
- ill-formed if a default constructor ([[class.ctor]]), copy or move
118
- constructor, or copy or move assignment operator ([[class.copy]]) is so
119
- declared. Default arguments for a member function of a class template
120
- shall be specified on the initial declaration of the member function
121
- within the class template.
122
 
123
  [*Example 4*:
124
 
125
  ``` cpp
126
  class C {
@@ -132,12 +141,12 @@ void C::f(int i = 3) {} // error: default argument already specified in
132
  void C::g(int i = 88, int j) {} // in this translation unit, C::g can be called with no argument
133
  ```
134
 
135
  — *end example*]
136
 
137
- A local variable shall not appear as a potentially-evaluated expression
138
- in a default argument.
139
 
140
  [*Example 5*:
141
 
142
  ``` cpp
143
  void f() {
@@ -148,11 +157,11 @@ void f() {
148
  }
149
  ```
150
 
151
  — *end example*]
152
 
153
- [*Note 2*:
154
 
155
  The keyword `this` may not appear in a default argument of a member
156
  function; see  [[expr.prim.this]].
157
 
158
  [*Example 6*:
@@ -184,13 +193,13 @@ int h(int a, int b = sizeof(a)); // OK, unevaluated operand
184
  ```
185
 
186
  — *end example*]
187
 
188
  A non-static member shall not appear in a default argument unless it
189
- appears as the *id-expression* of a class member access expression (
190
- [[expr.ref]]) or unless it is used to form a pointer to member (
191
- [[expr.unary.op]]).
192
 
193
  [*Example 8*:
194
 
195
  The declaration of `X::mem1()` in the following example is ill-formed
196
  because no object is supplied for the non-static member `X::a` used as
@@ -206,11 +215,11 @@ class X {
206
  };
207
  ```
208
 
209
  The declaration of `X::mem2()` is meaningful, however, since no object
210
  is needed to access the static member `X::b`. Classes, objects, and
211
- members are described in Clause  [[class]].
212
 
213
  — *end example*]
214
 
215
  A default argument is not part of the type of a function.
216
 
@@ -229,21 +238,21 @@ int (*p2)() = &f; // error: type mismatch
229
  ```
230
 
231
  — *end example*]
232
 
233
  When a declaration of a function is introduced by way of a
234
- *using-declaration* ([[namespace.udecl]]), any default argument
235
  information associated with the declaration is made known as well. If
236
  the function is redeclared thereafter in the namespace with additional
237
  default arguments, the additional arguments are also known at any point
238
  following the redeclaration where the *using-declaration* is in scope.
239
 
240
- A virtual function call ([[class.virtual]]) uses the default arguments
241
- in the declaration of the virtual function determined by the static type
242
- of the pointer or reference denoting the object. An overriding function
243
- in a derived class does not acquire default arguments from the function
244
- it overrides.
245
 
246
  [*Example 10*:
247
 
248
  ``` cpp
249
  struct A {
 
1
+ #### Default arguments <a id="dcl.fct.default">[[dcl.fct.default]]</a>
2
 
3
  If an *initializer-clause* is specified in a *parameter-declaration*
4
+ this *initializer-clause* is used as a default argument.
5
+
6
+ [*Note 1*: Default arguments will be used in calls where trailing
7
+ arguments are missing [[expr.call]]. — *end note*]
8
 
9
  [*Example 1*:
10
 
11
  The declaration
12
 
 
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 in the same scope. Declarations in different
40
  scopes have completely distinct sets of default arguments. That is,
41
  declarations in inner scopes do not acquire default arguments from
42
  declarations in outer scopes, and vice versa. In a given function
43
  declaration, each parameter subsequent to a parameter with a default
44
  argument shall have a default argument supplied in this or a previous
45
+ declaration, unless the parameter was expanded from a parameter pack, or
46
+ shall be a function parameter pack.
47
+
48
+ [*Note 2*: A default argument cannot be redefined by a later
49
+ declaration (not even to the same value)
50
+ [[basic.def.odr]]. — *end note*]
51
 
52
  [*Example 2*:
53
 
54
  ``` cpp
55
  void g(int = 0, ...); // OK, ellipsis is not a parameter so it can follow
 
68
  void f(int, int = 5); // error: cannot redefine, even to same value
69
  }
70
  void n() {
71
  f(6); // OK, calls f(6, 7)
72
  }
73
+ template<class ... T> struct C {
74
+ void f(int n = 0, T...);
75
+ };
76
+ C<int> c; // OK, instantiates declaration void C::f(int n = 0, int)
77
  ```
78
 
79
  — *end example*]
80
 
81
  For a given inline function defined in different translation units, the
82
  accumulated sets of default arguments at the end of the translation
83
+ units shall be the same; no diagnostic is required. If a friend
84
+ declaration specifies a default argument expression, that declaration
85
+ shall be a definition and shall be the only declaration of the function
86
+ or function template in the translation unit.
87
 
88
  The default argument has the same semantic constraints as the
89
  initializer in a declaration of a variable of the parameter type, using
90
+ the copy-initialization semantics [[dcl.init]]. The names in the default
91
+ argument are bound, and the semantic constraints are checked, at the
92
+ point where the default argument appears. Name lookup and checking of
93
+ semantic constraints for default arguments in function templates and in
94
+ member functions of class templates are performed as described in 
95
  [[temp.inst]].
96
 
97
  [*Example 3*:
98
 
99
  In the following code, `g` will be called with the value `f(2)`:
 
112
  }
113
  ```
114
 
115
  — *end example*]
116
 
117
+ [*Note 3*: In member function declarations, names in default arguments
118
  are looked up as described in  [[basic.lookup.unqual]]. Access checking
119
+ applies to names in default arguments as described in
120
  [[class.access]]. — *end note*]
121
 
122
  Except for member functions of class templates, the default arguments in
123
  a member function definition that appears outside of the class
124
  definition are added to the set of default arguments provided by the
125
  member function declaration in the class definition; the program is
126
+ ill-formed if a default constructor [[class.default.ctor]], copy or move
127
+ constructor [[class.copy.ctor]], or copy or move assignment operator
128
+ [[class.copy.assign]] is so declared. Default arguments for a member
129
+ function of a class template shall be specified on the initial
130
+ declaration of the member function within the class template.
131
 
132
  [*Example 4*:
133
 
134
  ``` cpp
135
  class C {
 
141
  void C::g(int i = 88, int j) {} // in this translation unit, C::g can be called with no argument
142
  ```
143
 
144
  — *end example*]
145
 
146
+ [*Note 4*: A local variable cannot be odr-used [[basic.def.odr]] in a
147
+ default argument. — *end note*]
148
 
149
  [*Example 5*:
150
 
151
  ``` cpp
152
  void f() {
 
157
  }
158
  ```
159
 
160
  — *end example*]
161
 
162
+ [*Note 5*:
163
 
164
  The keyword `this` may not appear in a default argument of a member
165
  function; see  [[expr.prim.this]].
166
 
167
  [*Example 6*:
 
193
  ```
194
 
195
  — *end example*]
196
 
197
  A non-static member shall not appear in a default argument unless it
198
+ appears as the *id-expression* of a class member access expression
199
+ [[expr.ref]] or unless it is used to form a pointer to member
200
+ [[expr.unary.op]].
201
 
202
  [*Example 8*:
203
 
204
  The declaration of `X::mem1()` in the following example is ill-formed
205
  because no object is supplied for the non-static member `X::a` used as
 
215
  };
216
  ```
217
 
218
  The declaration of `X::mem2()` is meaningful, however, since no object
219
  is needed to access the static member `X::b`. Classes, objects, and
220
+ members are described in [[class]].
221
 
222
  — *end example*]
223
 
224
  A default argument is not part of the type of a function.
225
 
 
238
  ```
239
 
240
  — *end example*]
241
 
242
  When a declaration of a function is introduced by way of a
243
+ *using-declaration* [[namespace.udecl]], any default argument
244
  information associated with the declaration is made known as well. If
245
  the function is redeclared thereafter in the namespace with additional
246
  default arguments, the additional arguments are also known at any point
247
  following the redeclaration where the *using-declaration* is in scope.
248
 
249
+ A virtual function call [[class.virtual]] uses the default arguments in
250
+ the declaration of the virtual function determined by the static type of
251
+ the pointer or reference denoting the object. An overriding function in
252
+ a derived class does not acquire default arguments from the function it
253
+ overrides.
254
 
255
  [*Example 10*:
256
 
257
  ``` cpp
258
  struct A {