From Jason Turner

[dcl.fct.default]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpabsxgs0l/{from.md → to.md} +39 -33
tmp/tmpabsxgs0l/{from.md → to.md} RENAMED
@@ -34,18 +34,18 @@ latter case, the *initializer-clause* shall be an
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
 
@@ -79,22 +79,26 @@ C<int> c; // OK, instantiates declaration void C::f(int n
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)`:
100
 
@@ -112,14 +116,13 @@ void h() {
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
@@ -136,16 +139,16 @@ class C {
136
  void f(int i = 3);
137
  void g(int i, int j = 99);
138
  };
139
 
140
  void C::f(int i = 3) {} // error: default argument already specified in class scope
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
@@ -159,11 +162,11 @@ void f() {
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*:
168
 
169
  ``` cpp
@@ -176,22 +179,24 @@ class A {
176
 
177
  — *end note*]
178
 
179
  A default argument is evaluated each time the function is called with no
180
  argument for the corresponding parameter. A parameter shall not appear
181
- as a potentially-evaluated expression in a default argument. Parameters
182
- of a function declared before a default argument are in scope and can
183
- hide namespace and class member names.
 
 
184
 
185
  [*Example 7*:
186
 
187
  ``` cpp
188
  int a;
189
  int f(int a, int b = a); // error: parameter a used as default argument
190
  typedef int I;
191
  int g(float I, int b = I(2)); // error: parameter I found
192
- int h(int a, int b = sizeof(a)); // OK, unevaluated operand
193
  ```
194
 
195
  — *end example*]
196
 
197
  A non-static member shall not appear in a default argument unless it
@@ -237,16 +242,17 @@ int (*p1)(int) = &f;
237
  int (*p2)() = &f; // error: type mismatch
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
 
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
46
+ pack, or 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
 
 
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 D specifies a default argument expression, that declaration
85
+ shall be a definition and there shall be no other declaration of the
86
+ function or function template which is reachable from D or from which D
87
+ is reachable.
88
 
89
  The default argument has the same semantic constraints as the
90
  initializer in a declaration of a variable of the parameter type, using
91
  the copy-initialization semantics [[dcl.init]]. The names in the default
92
+ argument are looked up, and the semantic constraints are checked, at the
93
+ point where the default argument appears, except that an immediate
94
+ invocation [[expr.const]] that is a potentially-evaluated subexpression
95
+ [[intro.execution]] of the *initializer-clause* in a
96
+ *parameter-declaration* is neither evaluated nor checked for whether it
97
+ is a constant expression at that point. Name lookup and checking of
98
+ semantic constraints for default arguments of templated functions are
99
+ performed as described in  [[temp.inst]].
100
 
101
  [*Example 3*:
102
 
103
  In the following code, `g` will be called with the value `f(2)`:
104
 
 
116
  }
117
  ```
118
 
119
  — *end example*]
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
 
139
  void f(int i = 3);
140
  void g(int i, int j = 99);
141
  };
142
 
143
  void C::f(int i = 3) {} // error: default argument already specified in class scope
144
+ void C::g(int i = 88, int j) {} // in this translation unit, C::g can be called with no arguments
145
  ```
146
 
147
  — *end example*]
148
 
149
+ [*Note 4*: A local variable cannot be odr-used [[term.odr.use]] in a
150
  default argument. — *end note*]
151
 
152
  [*Example 5*:
153
 
154
  ``` cpp
 
162
 
163
  — *end example*]
164
 
165
  [*Note 5*:
166
 
167
+ The keyword `this` cannot appear in a default argument of a member
168
  function; see  [[expr.prim.this]].
169
 
170
  [*Example 6*:
171
 
172
  ``` cpp
 
179
 
180
  — *end note*]
181
 
182
  A default argument is evaluated each time the function is called with no
183
  argument for the corresponding parameter. A parameter shall not appear
184
+ as a potentially-evaluated expression in a default argument.
185
+
186
+ [*Note 6*: Parameters of a function declared before a default argument
187
+ are in scope and can hide namespace and class member
188
+ names. — *end note*]
189
 
190
  [*Example 7*:
191
 
192
  ``` cpp
193
  int a;
194
  int f(int a, int b = a); // error: parameter a used as default argument
195
  typedef int I;
196
  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
 
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
257
  the pointer or reference denoting the object. An overriding function in
258
  a derived class does not acquire default arguments from the function it