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]]
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 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
|
| 40 |
-
that
|
| 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
|
| 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
|
| 133 |
-
declaration of the member function within the
|
| 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
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
[[expr.
|
|
|
|
|
|
|
|
|
|
| 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);
|
|
|
|
|
|
|
| 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
|
| 248 |
-
|
| 249 |
-
declaration
|
|
|
|
| 250 |
|
| 251 |
-
[*Note
|
| 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
|