From Jason Turner

[dcl.fct]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmph_v8ldyn/{from.md → to.md} +117 -64
tmp/tmph_v8ldyn/{from.md → to.md} RENAMED
@@ -2,39 +2,45 @@
2
 
3
  In a declaration `T` `D` where `D` has the form
4
 
5
  ``` bnf
6
  'D1 (' parameter-declaration-clause ')' cv-qualifier-seqₒₚₜ
7
- ref-qualifierₒₚₜ exception-specificationₒₚₜ attribute-specifier-seqₒₚₜ
8
  ```
9
 
10
  and the type of the contained *declarator-id* in the declaration `T`
11
  `D1` is “*derived-declarator-type-list* `T`”, the type of the
12
- *declarator-id* in `D` is “ function of ( ) returning `T`”. The optional
13
- *attribute-specifier-seq* appertains to the function type.
 
 
 
 
14
 
15
  In a declaration `T` `D` where `D` has the form
16
 
17
  ``` bnf
18
  'D1 (' parameter-declaration-clause ')' cv-qualifier-seqₒₚₜ
19
- ref-qualifierₒₚₜ exception-specificationₒₚₜ attribute-specifier-seqₒₚₜ trailing-return-type
20
  ```
21
 
22
  and the type of the contained *declarator-id* in the declaration `T`
23
  `D1` is “*derived-declarator-type-list* `T`”, `T` shall be the single
24
  *type-specifier* `auto`. The type of the *declarator-id* in `D` is
25
- “*derived-declarator-type-list* function of
26
- (*parameter-declaration-clause*) *cv-qualifier-seq*
27
- *ref-qualifier*returning *trailing-return-type*. The optional
 
 
28
  *attribute-specifier-seq* appertains to the function type.
29
 
30
- A type of either form is a *function type*.[^9]
31
 
32
  ``` bnf
33
  parameter-declaration-clause:
34
- parameter-declaration-listₒₚₜ ...ₒₚₜ
35
- parameter-declaration-list ',' ...
36
  ```
37
 
38
  ``` bnf
39
  parameter-declaration-list:
40
  parameter-declaration
@@ -51,23 +57,30 @@ parameter-declaration:
51
 
52
  The optional *attribute-specifier-seq* in a *parameter-declaration*
53
  appertains to the parameter.
54
 
55
  The *parameter-declaration-clause* determines the arguments that can be
56
- specified, and their processing, when the function is called. the
57
- *parameter-declaration-clause* is used to convert the arguments
58
- specified on the function call; see  [[expr.call]]. If the
59
- *parameter-declaration-clause* is empty, the function takes no
 
 
 
60
  arguments. A parameter list consisting of a single unnamed parameter of
61
  non-dependent type `void` is equivalent to an empty parameter list.
62
  Except for this special case, a parameter shall not have type *cv*
63
  `void`. If the *parameter-declaration-clause* terminates with an
64
  ellipsis or a function parameter pack ([[temp.variadic]]), the number
65
  of arguments shall be equal to or greater than the number of parameters
66
  that do not have a default argument and are not function parameter
67
- packs. Where syntactically correct and where “” is not part of an
68
- *abstract-declarator*, “” is synonymous with “”. the declaration
 
 
 
 
69
 
70
  ``` cpp
71
  int printf(const char*, ...);
72
  ```
73
 
@@ -78,31 +91,35 @@ arguments.
78
  printf("hello world");
79
  printf("a=%d b=%d", a, b);
80
  ```
81
 
82
  However, the first argument must be of a type that can be converted to a
83
- `const` `char*` The standard header `<cstdarg>` contains a mechanism for
 
 
 
 
84
  accessing arguments passed using the ellipsis (see  [[expr.call]] and 
85
- [[support.runtime]]).
86
 
87
  A single name can be used for several different functions in a single
88
  scope; this is function overloading (Clause  [[over]]). All declarations
89
  for a function shall agree exactly in both the return type and the
90
  parameter-type-list. The type of a function is determined using the
91
  following rules. The type of each parameter (including function
92
  parameter packs) is determined from its own *decl-specifier-seq* and
93
  *declarator*. After determining the type of each parameter, any
94
- parameter of type “array of `T`” or function returning `T` is adjusted
95
- to be “pointer to `T`” or “pointer to function returning `T`,
96
- respectively. After producing the list of parameter types, any top-level
97
- *cv-qualifier*s modifying a parameter type are deleted when forming the
98
- function type. The resulting list of transformed parameter types and the
99
- presence or absence of the ellipsis or a function parameter pack is the
100
- function’s *parameter-type-list*. This transformation does not affect
101
- the types of the parameters. For example,
102
- `int(*)(const int p, decltype(p)*)` and `int(*)(int, const int*)` are
103
- identical types.
104
 
105
  A function type with a *cv-qualifier-seq* or a *ref-qualifier*
106
  (including a type named by *typedef-name* ([[dcl.typedef]],
107
  [[temp.param]])) shall appear only as:
108
 
@@ -113,82 +130,101 @@ A function type with a *cv-qualifier-seq* or a *ref-qualifier*
113
  - the *type-id* in the default argument of a *type-parameter* (
114
  [[temp.param]]), or
115
  - the *type-id* of a *template-argument* for a *type-parameter* (
116
  [[temp.arg.type]]).
117
 
 
 
118
  ``` cpp
119
  typedef int FIC(int) const;
120
  FIC f; // ill-formed: does not declare a member function
121
  struct S {
122
  FIC f; // OK
123
  };
124
  FIC S::*pm = &S::f; // OK
125
  ```
126
 
 
 
127
  The effect of a *cv-qualifier-seq* in a function declarator is not the
128
  same as adding cv-qualification on top of the function type. In the
129
- latter case, the cv-qualifiers are ignored. a function type that has a
130
- *cv-qualifier-seq* is not a cv-qualified type; there are no cv-qualified
131
- function types.
 
 
 
 
132
 
133
  ``` cpp
134
  typedef void F();
135
  struct S {
136
  const F f; // OK: equivalent to: void f();
137
  };
138
  ```
139
 
140
- The return type, the parameter-type-list, the *ref-qualifier*, and the
141
- *cv-qualifier-seq*, but not the default arguments ([[dcl.fct.default]])
142
- or the exception specification ([[except.spec]]), are part of the
143
- function type. Function types are checked during the assignments and
 
 
 
144
  initializations of pointers to functions, references to functions, and
145
- pointers to member functions.
146
 
147
- the declaration
 
 
148
 
149
  ``` cpp
150
  int fseek(FILE*, long, int);
151
  ```
152
 
153
  declares a function taking three arguments of the specified types, and
154
  returning `int` ([[dcl.type]]).
155
 
156
- If the type of a parameter includes a type of the form “pointer to array
157
- of unknown bound of `T`” or “reference to array of unknown bound of
158
- `T`,” the program is ill-formed.[^10] Functions shall not have a return
159
- type of type array or function, although they may have a return type of
160
- type pointer or reference to such things. There shall be no arrays of
161
- functions, although there can be arrays of pointers to functions.
162
 
163
  Types shall not be defined in return or parameter types. The type of a
164
  parameter or the return type for a function definition shall not be an
165
- incomplete class type (possibly cv-qualified) unless the function is
166
- deleted ([[dcl.fct.def.delete]]) or the definition is nested within the
167
- *member-specification* for that class (including definitions in nested
168
- classes defined within the class).
169
 
170
  A typedef of function type may be used to declare a function but shall
171
  not be used to define a function ([[dcl.fct.def]]).
172
 
 
 
173
  ``` cpp
174
  typedef void F();
175
  F fv; // OK: equivalent to void fv();
176
  F fv { } // ill-formed
177
  void fv() { } // OK: definition of fv
178
  ```
179
 
 
 
180
  An identifier can optionally be provided as a parameter name; if present
181
- in a function definition ([[dcl.fct.def]]), it names a parameter. In
182
- particular, parameter names are also optional in function definitions
183
- and names used for a parameter in different declarations and the
184
- definition of a function need not be the same. If a parameter name is
185
- present in a function declaration that is not a definition, it cannot be
186
- used outside of its function declarator because that is the extent of
187
- its potential scope ([[basic.scope.proto]]).
188
 
189
- the declaration
 
 
 
 
 
 
 
 
 
190
 
191
  ``` cpp
192
  int i,
193
  *pi,
194
  f(),
@@ -208,13 +244,19 @@ The binding of `*fpi(int)` is `*(fpi(int))`, so the declaration
208
  suggests, and the same construction in an expression requires, the
209
  calling of a function `fpi`, and then using indirection through the
210
  (pointer) result to yield an integer. In the declarator
211
  `(*pif)(const char*, const char*)`, the extra parentheses are necessary
212
  to indicate that indirection through a pointer to a function yields a
213
- function, which is then called. Typedefs and *trailing-return-type*s are
214
- sometimes convenient when the return type of a function is complex. For
215
- example, the function `fpif` above could have been declared
 
 
 
 
 
 
216
 
217
  ``` cpp
218
  typedef int IFUNC(int);
219
  IFUNC* fpif(int);
220
  ```
@@ -236,21 +278,30 @@ rather than
236
 
237
  ``` cpp
238
  template <class T, class U> decltype((*(T*)0) + (*(U*)0)) add(T t, U u);
239
  ```
240
 
 
 
241
  A *non-template function* is a function that is not a function template
242
- specialization. A function template is not a function.
 
 
243
 
244
  A *declarator-id* or *abstract-declarator* containing an ellipsis shall
245
  only be used in a *parameter-declaration*. Such a
246
  *parameter-declaration* is a parameter pack ([[temp.variadic]]). When
247
  it is part of a *parameter-declaration-clause*, the parameter pack is a
248
- function parameter pack ([[temp.variadic]]). Otherwise, the
249
- *parameter-declaration* is part of a *template-parameter-list* and the
250
- parameter pack is a template parameter pack; see  [[temp.param]]. A
251
- function parameter pack is a pack expansion ([[temp.variadic]]).
 
 
 
 
 
252
 
253
  ``` cpp
254
  template<typename... T> void f(T (* ...t)(int, int));
255
 
256
  int add(int, int);
@@ -259,12 +310,14 @@ float subtract(int, int);
259
  void g() {
260
  f(add, subtract);
261
  }
262
  ```
263
 
 
 
264
  There is a syntactic ambiguity when an ellipsis occurs at the end of a
265
  *parameter-declaration-clause* without a preceding comma. In this case,
266
  the ellipsis is parsed as part of the *abstract-declarator* if the type
267
  of the parameter either names a template parameter pack that has not
268
  been expanded or contains `auto`; otherwise, it is parsed as part of the
269
- *parameter-declaration-clause*.[^11]
270
 
 
2
 
3
  In a declaration `T` `D` where `D` has the form
4
 
5
  ``` bnf
6
  'D1 (' parameter-declaration-clause ')' cv-qualifier-seqₒₚₜ
7
+ ref-qualifierₒₚₜ noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ
8
  ```
9
 
10
  and the type of the contained *declarator-id* in the declaration `T`
11
  `D1` is “*derived-declarator-type-list* `T`”, the type of the
12
+ *declarator-id* in `D` is “*derived-declarator-type-list* `noexcept`
13
+ function of (*parameter-declaration-clause*) *cv-qualifier-seq*ₒₚₜ
14
+ *ref-qualifier*ₒₚₜ returning `T`”, where the optional `noexcept` is
15
+ present if and only if the exception specification ([[except.spec]]) is
16
+ non-throwing. The optional *attribute-specifier-seq* appertains to the
17
+ function type.
18
 
19
  In a declaration `T` `D` where `D` has the form
20
 
21
  ``` bnf
22
  'D1 (' parameter-declaration-clause ')' cv-qualifier-seqₒₚₜ
23
+ ref-qualifierₒₚₜ noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ trailing-return-type
24
  ```
25
 
26
  and the type of the contained *declarator-id* in the declaration `T`
27
  `D1` is “*derived-declarator-type-list* `T`”, `T` shall be the single
28
  *type-specifier* `auto`. The type of the *declarator-id* in `D` is
29
+ “*derived-declarator-type-list* `noexcept` function of
30
+ (*parameter-declaration-clause*) *cv-qualifier-seq**ref-qualifier*
31
+ returning `U`, where `U` is the type specified by the
32
+ *trailing-return-type*, and where the optional `noexcept` is present if
33
+ and only if the exception specification is non-throwing. The optional
34
  *attribute-specifier-seq* appertains to the function type.
35
 
36
+ A type of either form is a *function type*.[^8]
37
 
38
  ``` bnf
39
  parameter-declaration-clause:
40
+ parameter-declaration-listₒₚₜ '...'ₒₚₜ
41
+ parameter-declaration-list ', ...'
42
  ```
43
 
44
  ``` bnf
45
  parameter-declaration-list:
46
  parameter-declaration
 
57
 
58
  The optional *attribute-specifier-seq* in a *parameter-declaration*
59
  appertains to the parameter.
60
 
61
  The *parameter-declaration-clause* determines the arguments that can be
62
+ specified, and their processing, when the function is called.
63
+
64
+ [*Note 1*: The *parameter-declaration-clause* is used to convert the
65
+ arguments specified on the function call; see 
66
+ [[expr.call]]. — *end note*]
67
+
68
+ If the *parameter-declaration-clause* is empty, the function takes no
69
  arguments. A parameter list consisting of a single unnamed parameter of
70
  non-dependent type `void` is equivalent to an empty parameter list.
71
  Except for this special case, a parameter shall not have type *cv*
72
  `void`. If the *parameter-declaration-clause* terminates with an
73
  ellipsis or a function parameter pack ([[temp.variadic]]), the number
74
  of arguments shall be equal to or greater than the number of parameters
75
  that do not have a default argument and are not function parameter
76
+ packs. Where syntactically correct and where “`...`” is not part of an
77
+ *abstract-declarator*, “`, ...`” is synonymous with “`...`”.
78
+
79
+ [*Example 1*:
80
+
81
+ The declaration
82
 
83
  ``` cpp
84
  int printf(const char*, ...);
85
  ```
86
 
 
91
  printf("hello world");
92
  printf("a=%d b=%d", a, b);
93
  ```
94
 
95
  However, the first argument must be of a type that can be converted to a
96
+ `const` `char*`
97
+
98
+ — *end example*]
99
+
100
+ [*Note 2*: The standard header `<cstdarg>` contains a mechanism for
101
  accessing arguments passed using the ellipsis (see  [[expr.call]] and 
102
+ [[support.runtime]]). — *end note*]
103
 
104
  A single name can be used for several different functions in a single
105
  scope; this is function overloading (Clause  [[over]]). All declarations
106
  for a function shall agree exactly in both the return type and the
107
  parameter-type-list. The type of a function is determined using the
108
  following rules. The type of each parameter (including function
109
  parameter packs) is determined from its own *decl-specifier-seq* and
110
  *declarator*. After determining the type of each parameter, any
111
+ parameter of type “array of `T`” or of function type `T` is adjusted to
112
+ be “pointer to `T`”. After producing the list of parameter types, any
113
+ top-level *cv-qualifier*s modifying a parameter type are deleted when
114
+ forming the function type. The resulting list of transformed parameter
115
+ types and the presence or absence of the ellipsis or a function
116
+ parameter pack is the function’s *parameter-type-list*.
117
+
118
+ [*Note 3*: This transformation does not affect the types of the
119
+ parameters. For example, `int(*)(const int p, decltype(p)*)` and
120
+ `int(*)(int, const int*)` are identical types. — *end note*]
121
 
122
  A function type with a *cv-qualifier-seq* or a *ref-qualifier*
123
  (including a type named by *typedef-name* ([[dcl.typedef]],
124
  [[temp.param]])) shall appear only as:
125
 
 
130
  - the *type-id* in the default argument of a *type-parameter* (
131
  [[temp.param]]), or
132
  - the *type-id* of a *template-argument* for a *type-parameter* (
133
  [[temp.arg.type]]).
134
 
135
+ [*Example 2*:
136
+
137
  ``` cpp
138
  typedef int FIC(int) const;
139
  FIC f; // ill-formed: does not declare a member function
140
  struct S {
141
  FIC f; // OK
142
  };
143
  FIC S::*pm = &S::f; // OK
144
  ```
145
 
146
+ — *end example*]
147
+
148
  The effect of a *cv-qualifier-seq* in a function declarator is not the
149
  same as adding cv-qualification on top of the function type. In the
150
+ latter case, the cv-qualifiers are ignored.
151
+
152
+ [*Note 4*: A function type that has a *cv-qualifier-seq* is not a
153
+ cv-qualified type; there are no cv-qualified function
154
+ types. — *end note*]
155
+
156
+ [*Example 3*:
157
 
158
  ``` cpp
159
  typedef void F();
160
  struct S {
161
  const F f; // OK: equivalent to: void f();
162
  };
163
  ```
164
 
165
+ *end example*]
166
+
167
+ The return type, the parameter-type-list, the *ref-qualifier*, the
168
+ *cv-qualifier-seq*, and the exception specification, but not the default
169
+ arguments ([[dcl.fct.default]]), are part of the function type.
170
+
171
+ [*Note 5*: Function types are checked during the assignments and
172
  initializations of pointers to functions, references to functions, and
173
+ pointers to member functions. — *end note*]
174
 
175
+ [*Example 4*:
176
+
177
+ The declaration
178
 
179
  ``` cpp
180
  int fseek(FILE*, long, int);
181
  ```
182
 
183
  declares a function taking three arguments of the specified types, and
184
  returning `int` ([[dcl.type]]).
185
 
186
+ *end example*]
187
+
188
+ Functions shall not have a return type of type array or function,
189
+ although they may have a return type of type pointer or reference to
190
+ such things. There shall be no arrays of functions, although there can
191
+ be arrays of pointers to functions.
192
 
193
  Types shall not be defined in return or parameter types. The type of a
194
  parameter or the return type for a function definition shall not be an
195
+ incomplete (possibly cv-qualified) class type in the context of the
196
+ function definition unless the function is deleted (
197
+ [[dcl.fct.def.delete]]).
 
198
 
199
  A typedef of function type may be used to declare a function but shall
200
  not be used to define a function ([[dcl.fct.def]]).
201
 
202
+ [*Example 5*:
203
+
204
  ``` cpp
205
  typedef void F();
206
  F fv; // OK: equivalent to void fv();
207
  F fv { } // ill-formed
208
  void fv() { } // OK: definition of fv
209
  ```
210
 
211
+ — *end example*]
212
+
213
  An identifier can optionally be provided as a parameter name; if present
214
+ in a function definition ([[dcl.fct.def]]), it names a parameter.
 
 
 
 
 
 
215
 
216
+ [*Note 6*: In particular, parameter names are also optional in function
217
+ definitions and names used for a parameter in different declarations and
218
+ the definition of a function need not be the same. If a parameter name
219
+ is present in a function declaration that is not a definition, it cannot
220
+ be used outside of its function declarator because that is the extent of
221
+ its potential scope ([[basic.scope.proto]]). — *end note*]
222
+
223
+ [*Example 6*:
224
+
225
+ The declaration
226
 
227
  ``` cpp
228
  int i,
229
  *pi,
230
  f(),
 
244
  suggests, and the same construction in an expression requires, the
245
  calling of a function `fpi`, and then using indirection through the
246
  (pointer) result to yield an integer. In the declarator
247
  `(*pif)(const char*, const char*)`, the extra parentheses are necessary
248
  to indicate that indirection through a pointer to a function yields a
249
+ function, which is then called.
250
+
251
+ *end example*]
252
+
253
+ [*Note 7*:
254
+
255
+ Typedefs and *trailing-return-type*s are sometimes convenient when the
256
+ return type of a function is complex. For example, the function `fpif`
257
+ above could have been declared
258
 
259
  ``` cpp
260
  typedef int IFUNC(int);
261
  IFUNC* fpif(int);
262
  ```
 
278
 
279
  ``` cpp
280
  template <class T, class U> decltype((*(T*)0) + (*(U*)0)) add(T t, U u);
281
  ```
282
 
283
+ — *end note*]
284
+
285
  A *non-template function* is a function that is not a function template
286
+ specialization.
287
+
288
+ [*Note 8*: A function template is not a function. — *end note*]
289
 
290
  A *declarator-id* or *abstract-declarator* containing an ellipsis shall
291
  only be used in a *parameter-declaration*. Such a
292
  *parameter-declaration* is a parameter pack ([[temp.variadic]]). When
293
  it is part of a *parameter-declaration-clause*, the parameter pack is a
294
+ function parameter pack ([[temp.variadic]]).
295
+
296
+ [*Note 9*: Otherwise, the *parameter-declaration* is part of a
297
+ *template-parameter-list* and the parameter pack is a template parameter
298
+ pack; see  [[temp.param]]. — *end note*]
299
+
300
+ A function parameter pack is a pack expansion ([[temp.variadic]]).
301
+
302
+ [*Example 7*:
303
 
304
  ``` cpp
305
  template<typename... T> void f(T (* ...t)(int, int));
306
 
307
  int add(int, int);
 
310
  void g() {
311
  f(add, subtract);
312
  }
313
  ```
314
 
315
+ — *end example*]
316
+
317
  There is a syntactic ambiguity when an ellipsis occurs at the end of a
318
  *parameter-declaration-clause* without a preceding comma. In this case,
319
  the ellipsis is parsed as part of the *abstract-declarator* if the type
320
  of the parameter either names a template parameter pack that has not
321
  been expanded or contains `auto`; otherwise, it is parsed as part of the
322
+ *parameter-declaration-clause*.[^9]
323