From Jason Turner

[dcl.fct.default]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpiglpc925/{from.md → to.md} +22 -20
tmp/tmpiglpc925/{from.md → to.md} RENAMED
@@ -24,11 +24,11 @@ A default argument shall be specified only in the
24
  *parameter-declaration-clause* of a function declaration or in a
25
  *template-parameter* ([[temp.param]]); in the latter case, the
26
  *initializer-clause* shall be an *assignment-expression*. A default
27
  argument shall not be specified for a parameter pack. If it is specified
28
  in a *parameter-declaration-clause*, it shall not occur within a
29
- *declarator* or *abstract-declarator* of a *parameter-declaration*.[^13]
30
 
31
  For non-template functions, default arguments can be added in later
32
  declarations of a function in the same scope. Declarations in different
33
  scopes have completely distinct sets of default arguments. That is,
34
  declarations in inner scopes do not acquire default arguments from
@@ -67,20 +67,19 @@ accumulated sets of default arguments at the end of the translation
67
  units shall be the same; see  [[basic.def.odr]]. If a friend declaration
68
  specifies a default argument expression, that declaration shall be a
69
  definition and shall be the only declaration of the function or function
70
  template in the translation unit.
71
 
72
- A default argument is implicitly converted (Clause  [[conv]]) to the
73
- parameter type. The default argument has the same semantic constraints
74
- as the initializer in a declaration of a variable of the parameter type,
75
- using the copy-initialization semantics ([[dcl.init]]). The names in
76
- the default argument are bound, and the semantic constraints are
77
- checked, at the point where the default argument appears. Name lookup
78
- and checking of semantic constraints for default arguments in function
79
- templates and in member functions of class templates are performed as
80
- described in  [[temp.inst]]. in the following code, `g` will be called
81
- with the value `f(2)`:
82
 
83
  ``` cpp
84
  int a = 1;
85
  int f(int);
86
  int g(int x = f(a)); // default argument: f(::a)
@@ -99,13 +98,16 @@ up as described in  [[basic.lookup.unqual]]. Access checking applies to
99
  names in default arguments as described in Clause  [[class.access]].
100
 
101
  Except for member functions of class templates, the default arguments in
102
  a member function definition that appears outside of the class
103
  definition are added to the set of default arguments provided by the
104
- member function declaration in the class definition. Default arguments
105
- for a member function of a class template shall be specified on the
106
- initial declaration of the member function within the class template.
 
 
 
107
 
108
  ``` cpp
109
  class C {
110
  void f(int i = 3);
111
  void g(int i, int j = 99);
@@ -134,16 +136,16 @@ function.
134
  class A {
135
  void f(A* p = this) { } // error
136
  };
137
  ```
138
 
139
- Default arguments are evaluated each time the function is called. The
140
- order of evaluation of function arguments is unspecified. Consequently,
141
- parameters of a function shall not be used in a default argument, even
142
- if they are not evaluated. Parameters of a function declared before a
143
- default argument are in scope and can hide namespace and class member
144
- names.
145
 
146
  ``` cpp
147
  int a;
148
  int f(int a, int b = a); // error: parameter a
149
  // used as default argument
 
24
  *parameter-declaration-clause* of a function declaration or in a
25
  *template-parameter* ([[temp.param]]); in the latter case, the
26
  *initializer-clause* shall be an *assignment-expression*. A default
27
  argument shall not be specified for a parameter pack. If it is specified
28
  in a *parameter-declaration-clause*, it shall not occur within a
29
+ *declarator* or *abstract-declarator* of a *parameter-declaration*.[^12]
30
 
31
  For non-template functions, default arguments can be added in later
32
  declarations of a function in the same scope. Declarations in different
33
  scopes have completely distinct sets of default arguments. That is,
34
  declarations in inner scopes do not acquire default arguments from
 
67
  units shall be the same; see  [[basic.def.odr]]. If a friend declaration
68
  specifies a default argument expression, that declaration shall be a
69
  definition and shall be the only declaration of the function or function
70
  template in the translation unit.
71
 
72
+ The default argument has the same semantic constraints as the
73
+ initializer in a declaration of a variable of the parameter type, using
74
+ the copy-initialization semantics ([[dcl.init]]). The names in the
75
+ default argument are bound, and the semantic constraints are checked, at
76
+ the point where the default argument appears. Name lookup and checking
77
+ of semantic constraints for default arguments in function templates and
78
+ in member functions of class templates are performed as described in 
79
+ [[temp.inst]]. in the following code, `g` will be called with the value
80
+ `f(2)`:
 
81
 
82
  ``` cpp
83
  int a = 1;
84
  int f(int);
85
  int g(int x = f(a)); // default argument: f(::a)
 
98
  names in default arguments as described in Clause  [[class.access]].
99
 
100
  Except for member functions of class templates, the default arguments in
101
  a member function definition that appears outside of the class
102
  definition are added to the set of default arguments provided by the
103
+ member function declaration in the class definition; the program is
104
+ ill-formed if a default constructor ([[class.ctor]]), copy or move
105
+ constructor, or copy or move assignment operator ([[class.copy]]) is so
106
+ declared. Default arguments for a member function of a class template
107
+ shall be specified on the initial declaration of the member function
108
+ within the class template.
109
 
110
  ``` cpp
111
  class C {
112
  void f(int i = 3);
113
  void g(int i, int j = 99);
 
136
  class A {
137
  void f(A* p = this) { } // error
138
  };
139
  ```
140
 
141
+ A default argument is evaluated each time the function is called with no
142
+ argument for the corresponding parameter. The order of evaluation of
143
+ function arguments is unspecified. Consequently, parameters of a
144
+ function shall not be used in a default argument, even if they are not
145
+ evaluated. Parameters of a function declared before a default argument
146
+ are in scope and can hide namespace and class member names.
147
 
148
  ``` cpp
149
  int a;
150
  int f(int a, int b = a); // error: parameter a
151
  // used as default argument