- tmp/tmpxl00m0tu/{from.md → to.md} +113 -112
tmp/tmpxl00m0tu/{from.md → to.md}
RENAMED
|
@@ -2,32 +2,26 @@
|
|
| 2 |
|
| 3 |
A list of declarators appears after an optional (Clause [[dcl.dcl]])
|
| 4 |
*decl-specifier-seq* ([[dcl.spec]]). Each declarator contains exactly
|
| 5 |
one *declarator-id*; it names the identifier that is declared. An
|
| 6 |
*unqualified-id* occurring in a *declarator-id* shall be a simple
|
| 7 |
-
*identifier* except for the declaration of some special functions
|
| 8 |
-
[[class.conv]], [[class.dtor]], [[over.oper]]) and for
|
| 9 |
-
of template specializations or partial specializations
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
*declarator-id*
|
| 18 |
-
|
| 19 |
-
qualifier
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
nominated by the *nested-name-specifier* of the *declarator-id*. The
|
| 24 |
-
*nested-name-specifier* of a qualified *declarator-id* shall not begin
|
| 25 |
-
with a *decltype-specifier*. If the qualifier is the global `::` scope
|
| 26 |
-
resolution operator, the *declarator-id* refers to a name declared in
|
| 27 |
-
the global namespace scope. The optional *attribute-specifier-seq*
|
| 28 |
-
following a *declarator-id* appertains to the entity that is declared.
|
| 29 |
|
| 30 |
A `static`, `thread_local`, `extern`, `register`, `mutable`, `friend`,
|
| 31 |
`inline`, `virtual`, or `typedef` specifier applies directly to each
|
| 32 |
*declarator-id* in an *init-declarator-list*; the type specified for
|
| 33 |
each *declarator-id* depends on both the *decl-specifier-seq* and its
|
|
@@ -139,13 +133,15 @@ cv-unqualified pointer later, for example:
|
|
| 139 |
*p = 5; // clobber ci
|
| 140 |
```
|
| 141 |
|
| 142 |
See also [[expr.ass]] and [[dcl.init]].
|
| 143 |
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
|
|
|
|
|
|
| 147 |
|
| 148 |
### References <a id="dcl.ref">[[dcl.ref]]</a>
|
| 149 |
|
| 150 |
In a declaration `T` `D` where `D` has either of the forms
|
| 151 |
|
|
@@ -156,13 +152,13 @@ In a declaration `T` `D` where `D` has either of the forms
|
|
| 156 |
|
| 157 |
and the type of the identifier in the declaration `T` `D1` is “ `T`,”
|
| 158 |
then the type of the identifier of `D` is “ reference to `T`.” The
|
| 159 |
optional *attribute-specifier-seq* appertains to the reference type.
|
| 160 |
Cv-qualified references are ill-formed except when the cv-qualifiers are
|
| 161 |
-
introduced through the use of a typedef
|
| 162 |
-
|
| 163 |
-
are ignored.
|
| 164 |
|
| 165 |
``` cpp
|
| 166 |
typedef int& A;
|
| 167 |
const A aref = 3; // ill-formed; lvalue reference to non-const initialized with rvalue
|
| 168 |
```
|
|
@@ -232,20 +228,20 @@ contains an explicit `extern` specifier ([[dcl.stc]]), is a class
|
|
| 232 |
member ([[class.mem]]) declaration within a class definition, or is the
|
| 233 |
declaration of a parameter or a return type ([[dcl.fct]]); see
|
| 234 |
[[basic.def]]. A reference shall be initialized to refer to a valid
|
| 235 |
object or function. in particular, a null reference cannot exist in a
|
| 236 |
well-defined program, because the only way to create such a reference
|
| 237 |
-
would be to bind it to the “object” obtained by
|
| 238 |
-
pointer, which causes undefined behavior. As described in
|
| 239 |
[[class.bit]], a reference cannot be bound directly to a bit-field.
|
| 240 |
|
| 241 |
-
If a typedef ([[dcl.typedef]]
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
|
| 248 |
``` cpp
|
| 249 |
int i;
|
| 250 |
typedef int& LRI;
|
| 251 |
typedef int&& RRI;
|
|
@@ -259,10 +255,13 @@ RRI&& r5 = 5; // r5 has the type int&&
|
|
| 259 |
|
| 260 |
decltype(r2)& r6 = i; // r6 has the type int&
|
| 261 |
decltype(r2)&& r7 = i; // r7 has the type int&
|
| 262 |
```
|
| 263 |
|
|
|
|
|
|
|
|
|
|
| 264 |
### Pointers to members <a id="dcl.mptr">[[dcl.mptr]]</a>
|
| 265 |
|
| 266 |
In a declaration `T` `D` where `D` has the form
|
| 267 |
|
| 268 |
``` bnf
|
|
@@ -326,24 +325,25 @@ and the type of the identifier in the declaration `T` `D1` is
|
|
| 326 |
“*derived-declarator-type-list* `T`”, then the type of the identifier of
|
| 327 |
`D` is an array type; if the type of the identifier of `D` contains the
|
| 328 |
`auto` , the program is ill-formed. `T` is called the array *element
|
| 329 |
type*; this type shall not be a reference type, the (possibly
|
| 330 |
cv-qualified) type `void`, a function type or an abstract class type. If
|
| 331 |
-
the *constant-expression* ([[expr.const]]) is present, it shall be
|
| 332 |
-
|
| 333 |
-
The constant expression specifies the *bound* of
|
| 334 |
-
the array. If the value of the constant
|
| 335 |
-
`N` elements numbered `0` to `N-1`, and
|
| 336 |
-
`D` is “ array of `N` `T`”. An object of
|
| 337 |
-
contiguously allocated non-empty set of `N`
|
| 338 |
-
Except as noted below, if the constant
|
| 339 |
-
of the identifier of `D` is “ array of
|
| 340 |
-
incomplete object type. The type “ array of
|
| 341 |
-
from the type “ array of unknown bound of
|
| 342 |
-
Any type of the form “ array of `N` `T`” is
|
| 343 |
-
`T`”, and similarly for “array of unknown
|
| 344 |
-
*attribute-specifier-seq* appertains to the
|
|
|
|
| 345 |
|
| 346 |
``` cpp
|
| 347 |
typedef int A[5], AA[2][3];
|
| 348 |
typedef const A CA; // type is ``array of 5 const int''
|
| 349 |
typedef const AA CAA; // type is ``array of 2 array of 3 const int''
|
|
@@ -472,11 +472,11 @@ and the type of the contained *declarator-id* in the declaration `T`
|
|
| 472 |
“*derived-declarator-type-list* function of
|
| 473 |
(*parameter-declaration-clause*) *cv-qualifier-seq*
|
| 474 |
*ref-qualifier*returning *trailing-return-type*”. The optional
|
| 475 |
*attribute-specifier-seq* appertains to the function type.
|
| 476 |
|
| 477 |
-
A type of either form is a *function type*.[^
|
| 478 |
|
| 479 |
``` bnf
|
| 480 |
parameter-declaration-clause:
|
| 481 |
parameter-declaration-listₒₚₜ ...ₒₚₜ
|
| 482 |
parameter-declaration-list ',' ...
|
|
@@ -502,18 +502,18 @@ appertains to the parameter.
|
|
| 502 |
The *parameter-declaration-clause* determines the arguments that can be
|
| 503 |
specified, and their processing, when the function is called. the
|
| 504 |
*parameter-declaration-clause* is used to convert the arguments
|
| 505 |
specified on the function call; see [[expr.call]]. If the
|
| 506 |
*parameter-declaration-clause* is empty, the function takes no
|
| 507 |
-
arguments.
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
If the *parameter-declaration-clause* terminates with an
|
| 511 |
-
function parameter pack ([[temp.variadic]]), the number
|
| 512 |
-
shall be equal to or greater than the number of parameters
|
| 513 |
-
have a default argument and are not function parameter
|
| 514 |
-
syntactically correct and where “” is not part of an
|
| 515 |
*abstract-declarator*, “” is synonymous with “”. the declaration
|
| 516 |
|
| 517 |
``` cpp
|
| 518 |
int printf(const char*, ...);
|
| 519 |
```
|
|
@@ -547,20 +547,31 @@ presence or absence of the ellipsis or a function parameter pack is the
|
|
| 547 |
function’s *parameter-type-list*. This transformation does not affect
|
| 548 |
the types of the parameters. For example,
|
| 549 |
`int(*)(const int p, decltype(p)*)` and `int(*)(int, const int*)` are
|
| 550 |
identical types.
|
| 551 |
|
| 552 |
-
A *cv-qualifier-seq* or a *ref-qualifier*
|
|
|
|
|
|
|
| 553 |
|
| 554 |
- the function type for a non-static member function,
|
| 555 |
- the function type to which a pointer to member refers,
|
| 556 |
- the top-level function type of a function typedef declaration or
|
| 557 |
*alias-declaration*,
|
| 558 |
- the *type-id* in the default argument of a *type-parameter* (
|
| 559 |
[[temp.param]]), or
|
| 560 |
- the *type-id* of a *template-argument* for a *type-parameter* (
|
| 561 |
-
[[temp.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 562 |
|
| 563 |
The effect of a *cv-qualifier-seq* in a function declarator is not the
|
| 564 |
same as adding cv-qualification on top of the function type. In the
|
| 565 |
latter case, the cv-qualifiers are ignored. a function type that has a
|
| 566 |
*cv-qualifier-seq* is not a cv-qualified type; there are no cv-qualified
|
|
@@ -589,20 +600,21 @@ int fseek(FILE*, long, int);
|
|
| 589 |
declares a function taking three arguments of the specified types, and
|
| 590 |
returning `int` ([[dcl.type]]).
|
| 591 |
|
| 592 |
If the type of a parameter includes a type of the form “pointer to array
|
| 593 |
of unknown bound of `T`” or “reference to array of unknown bound of
|
| 594 |
-
`T`,” the program is ill-formed.[^
|
| 595 |
type of type array or function, although they may have a return type of
|
| 596 |
type pointer or reference to such things. There shall be no arrays of
|
| 597 |
functions, although there can be arrays of pointers to functions.
|
| 598 |
|
| 599 |
Types shall not be defined in return or parameter types. The type of a
|
| 600 |
parameter or the return type for a function definition shall not be an
|
| 601 |
-
incomplete class type (possibly cv-qualified) unless the function
|
| 602 |
-
definition is nested within the
|
| 603 |
-
(including definitions in nested
|
|
|
|
| 604 |
|
| 605 |
A typedef of function type may be used to declare a function but shall
|
| 606 |
not be used to define a function ([[dcl.fct.def]]).
|
| 607 |
|
| 608 |
``` cpp
|
|
@@ -610,34 +622,18 @@ typedef void F();
|
|
| 610 |
F fv; // OK: equivalent to void fv();
|
| 611 |
F fv { } // ill-formed
|
| 612 |
void fv() { } // OK: definition of fv
|
| 613 |
```
|
| 614 |
|
| 615 |
-
A typedef of a function type whose declarator includes a
|
| 616 |
-
*cv-qualifier-seq* shall be used only to declare the function type for a
|
| 617 |
-
non-static member function, to declare the function type to which a
|
| 618 |
-
pointer to member refers, or to declare the top-level function type of
|
| 619 |
-
another function typedef declaration.
|
| 620 |
-
|
| 621 |
-
``` cpp
|
| 622 |
-
typedef int FIC(int) const;
|
| 623 |
-
FIC f; // ill-formed: does not declare a member function
|
| 624 |
-
struct S {
|
| 625 |
-
FIC f; // OK
|
| 626 |
-
};
|
| 627 |
-
FIC S::*pm = &S::f; // OK
|
| 628 |
-
```
|
| 629 |
-
|
| 630 |
An identifier can optionally be provided as a parameter name; if present
|
| 631 |
-
in a function definition ([[dcl.fct.def]]), it names a parameter
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
[[basic.scope.proto]]).
|
| 639 |
|
| 640 |
the declaration
|
| 641 |
|
| 642 |
``` cpp
|
| 643 |
int i,
|
|
@@ -671,11 +667,11 @@ IFUNC* fpif(int);
|
|
| 671 |
```
|
| 672 |
|
| 673 |
or
|
| 674 |
|
| 675 |
``` cpp
|
| 676 |
-
auto fpif(int)->int(*)(int)
|
| 677 |
```
|
| 678 |
|
| 679 |
A *trailing-return-type* is most useful for a type that would be more
|
| 680 |
complicated to specify before the *declarator-id*:
|
| 681 |
|
|
@@ -687,10 +683,13 @@ rather than
|
|
| 687 |
|
| 688 |
``` cpp
|
| 689 |
template <class T, class U> decltype((*(T*)0) + (*(U*)0)) add(T t, U u);
|
| 690 |
```
|
| 691 |
|
|
|
|
|
|
|
|
|
|
| 692 |
A *declarator-id* or *abstract-declarator* containing an ellipsis shall
|
| 693 |
only be used in a *parameter-declaration*. Such a
|
| 694 |
*parameter-declaration* is a parameter pack ([[temp.variadic]]). When
|
| 695 |
it is part of a *parameter-declaration-clause*, the parameter pack is a
|
| 696 |
function parameter pack ([[temp.variadic]]). Otherwise, the
|
|
@@ -710,13 +709,13 @@ void g() {
|
|
| 710 |
```
|
| 711 |
|
| 712 |
There is a syntactic ambiguity when an ellipsis occurs at the end of a
|
| 713 |
*parameter-declaration-clause* without a preceding comma. In this case,
|
| 714 |
the ellipsis is parsed as part of the *abstract-declarator* if the type
|
| 715 |
-
of the parameter names a template parameter pack that has not
|
| 716 |
-
expanded; otherwise, it is parsed as part of the
|
| 717 |
-
*parameter-declaration-clause*.[^
|
| 718 |
|
| 719 |
### Default arguments <a id="dcl.fct.default">[[dcl.fct.default]]</a>
|
| 720 |
|
| 721 |
If an *initializer-clause* is specified in a *parameter-declaration*
|
| 722 |
this *initializer-clause* is used as a default argument. Default
|
|
@@ -742,11 +741,11 @@ A default argument shall be specified only in the
|
|
| 742 |
*parameter-declaration-clause* of a function declaration or in a
|
| 743 |
*template-parameter* ([[temp.param]]); in the latter case, the
|
| 744 |
*initializer-clause* shall be an *assignment-expression*. A default
|
| 745 |
argument shall not be specified for a parameter pack. If it is specified
|
| 746 |
in a *parameter-declaration-clause*, it shall not occur within a
|
| 747 |
-
*declarator* or *abstract-declarator* of a *parameter-declaration*.[^
|
| 748 |
|
| 749 |
For non-template functions, default arguments can be added in later
|
| 750 |
declarations of a function in the same scope. Declarations in different
|
| 751 |
scopes have completely distinct sets of default arguments. That is,
|
| 752 |
declarations in inner scopes do not acquire default arguments from
|
|
@@ -785,20 +784,19 @@ accumulated sets of default arguments at the end of the translation
|
|
| 785 |
units shall be the same; see [[basic.def.odr]]. If a friend declaration
|
| 786 |
specifies a default argument expression, that declaration shall be a
|
| 787 |
definition and shall be the only declaration of the function or function
|
| 788 |
template in the translation unit.
|
| 789 |
|
| 790 |
-
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
|
| 794 |
-
the
|
| 795 |
-
|
| 796 |
-
|
| 797 |
-
|
| 798 |
-
|
| 799 |
-
with the value `f(2)`:
|
| 800 |
|
| 801 |
``` cpp
|
| 802 |
int a = 1;
|
| 803 |
int f(int);
|
| 804 |
int g(int x = f(a)); // default argument: f(::a)
|
|
@@ -817,13 +815,16 @@ up as described in [[basic.lookup.unqual]]. Access checking applies to
|
|
| 817 |
names in default arguments as described in Clause [[class.access]].
|
| 818 |
|
| 819 |
Except for member functions of class templates, the default arguments in
|
| 820 |
a member function definition that appears outside of the class
|
| 821 |
definition are added to the set of default arguments provided by the
|
| 822 |
-
member function declaration in the class definition
|
| 823 |
-
|
| 824 |
-
|
|
|
|
|
|
|
|
|
|
| 825 |
|
| 826 |
``` cpp
|
| 827 |
class C {
|
| 828 |
void f(int i = 3);
|
| 829 |
void g(int i, int j = 99);
|
|
@@ -852,16 +853,16 @@ function.
|
|
| 852 |
class A {
|
| 853 |
void f(A* p = this) { } // error
|
| 854 |
};
|
| 855 |
```
|
| 856 |
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
names.
|
| 863 |
|
| 864 |
``` cpp
|
| 865 |
int a;
|
| 866 |
int f(int a, int b = a); // error: parameter a
|
| 867 |
// used as default argument
|
|
|
|
| 2 |
|
| 3 |
A list of declarators appears after an optional (Clause [[dcl.dcl]])
|
| 4 |
*decl-specifier-seq* ([[dcl.spec]]). Each declarator contains exactly
|
| 5 |
one *declarator-id*; it names the identifier that is declared. An
|
| 6 |
*unqualified-id* occurring in a *declarator-id* shall be a simple
|
| 7 |
+
*identifier* except for the declaration of some special functions (
|
| 8 |
+
[[class.ctor]], [[class.conv]], [[class.dtor]], [[over.oper]]) and for
|
| 9 |
+
the declaration of template specializations or partial specializations (
|
| 10 |
+
[[temp.spec]]). When the *declarator-id* is qualified, the declaration
|
| 11 |
+
shall refer to a previously declared member of the class or namespace to
|
| 12 |
+
which the qualifier refers (or, in the case of a namespace, of an
|
| 13 |
+
element of the inline namespace set of that namespace (
|
| 14 |
+
[[namespace.def]])) or to a specialization thereof; the member shall not
|
| 15 |
+
merely have been introduced by a *using-declaration* in the scope of the
|
| 16 |
+
class or namespace nominated by the *nested-name-specifier* of the
|
| 17 |
+
*declarator-id*. The *nested-name-specifier* of a qualified
|
| 18 |
+
*declarator-id* shall not begin with a *decltype-specifier*. If the
|
| 19 |
+
qualifier is the global `::` scope resolution operator, the
|
| 20 |
+
*declarator-id* refers to a name declared in the global namespace scope.
|
| 21 |
+
The optional *attribute-specifier-seq* following a *declarator-id*
|
| 22 |
+
appertains to the entity that is declared.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
A `static`, `thread_local`, `extern`, `register`, `mutable`, `friend`,
|
| 25 |
`inline`, `virtual`, or `typedef` specifier applies directly to each
|
| 26 |
*declarator-id* in an *init-declarator-list*; the type specified for
|
| 27 |
each *declarator-id* depends on both the *decl-specifier-seq* and its
|
|
|
|
| 133 |
*p = 5; // clobber ci
|
| 134 |
```
|
| 135 |
|
| 136 |
See also [[expr.ass]] and [[dcl.init]].
|
| 137 |
|
| 138 |
+
Forming a pointer to reference type is ill-formed; see [[dcl.ref]].
|
| 139 |
+
Forming a pointer to function type is ill-formed if the function type
|
| 140 |
+
has *cv-qualifier*s or a *ref-qualifier*; see [[dcl.fct]]. Since the
|
| 141 |
+
address of a bit-field ([[class.bit]]) cannot be taken, a pointer can
|
| 142 |
+
never point to a bit-field.
|
| 143 |
|
| 144 |
### References <a id="dcl.ref">[[dcl.ref]]</a>
|
| 145 |
|
| 146 |
In a declaration `T` `D` where `D` has either of the forms
|
| 147 |
|
|
|
|
| 152 |
|
| 153 |
and the type of the identifier in the declaration `T` `D1` is “ `T`,”
|
| 154 |
then the type of the identifier of `D` is “ reference to `T`.” The
|
| 155 |
optional *attribute-specifier-seq* appertains to the reference type.
|
| 156 |
Cv-qualified references are ill-formed except when the cv-qualifiers are
|
| 157 |
+
introduced through the use of a *typedef-name* ([[dcl.typedef]],
|
| 158 |
+
[[temp.param]]) or *decltype-specifier* ([[dcl.type.simple]]), in which
|
| 159 |
+
case the cv-qualifiers are ignored.
|
| 160 |
|
| 161 |
``` cpp
|
| 162 |
typedef int& A;
|
| 163 |
const A aref = 3; // ill-formed; lvalue reference to non-const initialized with rvalue
|
| 164 |
```
|
|
|
|
| 228 |
member ([[class.mem]]) declaration within a class definition, or is the
|
| 229 |
declaration of a parameter or a return type ([[dcl.fct]]); see
|
| 230 |
[[basic.def]]. A reference shall be initialized to refer to a valid
|
| 231 |
object or function. in particular, a null reference cannot exist in a
|
| 232 |
well-defined program, because the only way to create such a reference
|
| 233 |
+
would be to bind it to the “object” obtained by indirection through a
|
| 234 |
+
null pointer, which causes undefined behavior. As described in
|
| 235 |
[[class.bit]], a reference cannot be bound directly to a bit-field.
|
| 236 |
|
| 237 |
+
If a *typedef-name* ([[dcl.typedef]], [[temp.param]]) or a
|
| 238 |
+
*decltype-specifier* ([[dcl.type.simple]]) denotes a type `TR` that is
|
| 239 |
+
a reference to a type `T`, an attempt to create the type “lvalue
|
| 240 |
+
reference to cv `TR`” creates the type “lvalue reference to `T`”, while
|
| 241 |
+
an attempt to create the type “rvalue reference to cv `TR`” creates the
|
| 242 |
+
type `TR`.
|
| 243 |
|
| 244 |
``` cpp
|
| 245 |
int i;
|
| 246 |
typedef int& LRI;
|
| 247 |
typedef int&& RRI;
|
|
|
|
| 255 |
|
| 256 |
decltype(r2)& r6 = i; // r6 has the type int&
|
| 257 |
decltype(r2)&& r7 = i; // r7 has the type int&
|
| 258 |
```
|
| 259 |
|
| 260 |
+
Forming a reference to function type is ill-formed if the function type
|
| 261 |
+
has *cv-qualifier*s or a *ref-qualifier*; see [[dcl.fct]].
|
| 262 |
+
|
| 263 |
### Pointers to members <a id="dcl.mptr">[[dcl.mptr]]</a>
|
| 264 |
|
| 265 |
In a declaration `T` `D` where `D` has the form
|
| 266 |
|
| 267 |
``` bnf
|
|
|
|
| 325 |
“*derived-declarator-type-list* `T`”, then the type of the identifier of
|
| 326 |
`D` is an array type; if the type of the identifier of `D` contains the
|
| 327 |
`auto` , the program is ill-formed. `T` is called the array *element
|
| 328 |
type*; this type shall not be a reference type, the (possibly
|
| 329 |
cv-qualified) type `void`, a function type or an abstract class type. If
|
| 330 |
+
the *constant-expression* ([[expr.const]]) is present, it shall be a
|
| 331 |
+
converted constant expression of type `std::size_t` and its value shall
|
| 332 |
+
be greater than zero. The constant expression specifies the *bound* of
|
| 333 |
+
(number of elements in) the array. If the value of the constant
|
| 334 |
+
expression is `N`, the array has `N` elements numbered `0` to `N-1`, and
|
| 335 |
+
the type of the identifier of `D` is “ array of `N` `T`”. An object of
|
| 336 |
+
array type contains a contiguously allocated non-empty set of `N`
|
| 337 |
+
subobjects of type `T`. Except as noted below, if the constant
|
| 338 |
+
expression is omitted, the type of the identifier of `D` is “ array of
|
| 339 |
+
unknown bound of `T`”, an incomplete object type. The type “ array of
|
| 340 |
+
`N` `T`” is a different type from the type “ array of unknown bound of
|
| 341 |
+
`T`”, see [[basic.types]]. Any type of the form “ array of `N` `T`” is
|
| 342 |
+
adjusted to “array of `N` `T`”, and similarly for “array of unknown
|
| 343 |
+
bound of `T`”. The optional *attribute-specifier-seq* appertains to the
|
| 344 |
+
array.
|
| 345 |
|
| 346 |
``` cpp
|
| 347 |
typedef int A[5], AA[2][3];
|
| 348 |
typedef const A CA; // type is ``array of 5 const int''
|
| 349 |
typedef const AA CAA; // type is ``array of 2 array of 3 const int''
|
|
|
|
| 472 |
“*derived-declarator-type-list* function of
|
| 473 |
(*parameter-declaration-clause*) *cv-qualifier-seq*
|
| 474 |
*ref-qualifier*returning *trailing-return-type*”. The optional
|
| 475 |
*attribute-specifier-seq* appertains to the function type.
|
| 476 |
|
| 477 |
+
A type of either form is a *function type*.[^9]
|
| 478 |
|
| 479 |
``` bnf
|
| 480 |
parameter-declaration-clause:
|
| 481 |
parameter-declaration-listₒₚₜ ...ₒₚₜ
|
| 482 |
parameter-declaration-list ',' ...
|
|
|
|
| 502 |
The *parameter-declaration-clause* determines the arguments that can be
|
| 503 |
specified, and their processing, when the function is called. the
|
| 504 |
*parameter-declaration-clause* is used to convert the arguments
|
| 505 |
specified on the function call; see [[expr.call]]. If the
|
| 506 |
*parameter-declaration-clause* is empty, the function takes no
|
| 507 |
+
arguments. A parameter list consisting of a single unnamed parameter of
|
| 508 |
+
non-dependent type `void` is equivalent to an empty parameter list.
|
| 509 |
+
Except for this special case, a parameter shall not have type *cv*
|
| 510 |
+
`void`. If the *parameter-declaration-clause* terminates with an
|
| 511 |
+
ellipsis or a function parameter pack ([[temp.variadic]]), the number
|
| 512 |
+
of arguments shall be equal to or greater than the number of parameters
|
| 513 |
+
that do not have a default argument and are not function parameter
|
| 514 |
+
packs. Where syntactically correct and where “” is not part of an
|
| 515 |
*abstract-declarator*, “” is synonymous with “”. the declaration
|
| 516 |
|
| 517 |
``` cpp
|
| 518 |
int printf(const char*, ...);
|
| 519 |
```
|
|
|
|
| 547 |
function’s *parameter-type-list*. This transformation does not affect
|
| 548 |
the types of the parameters. For example,
|
| 549 |
`int(*)(const int p, decltype(p)*)` and `int(*)(int, const int*)` are
|
| 550 |
identical types.
|
| 551 |
|
| 552 |
+
A function type with a *cv-qualifier-seq* or a *ref-qualifier*
|
| 553 |
+
(including a type named by *typedef-name* ([[dcl.typedef]],
|
| 554 |
+
[[temp.param]])) shall appear only as:
|
| 555 |
|
| 556 |
- the function type for a non-static member function,
|
| 557 |
- the function type to which a pointer to member refers,
|
| 558 |
- the top-level function type of a function typedef declaration or
|
| 559 |
*alias-declaration*,
|
| 560 |
- the *type-id* in the default argument of a *type-parameter* (
|
| 561 |
[[temp.param]]), or
|
| 562 |
- the *type-id* of a *template-argument* for a *type-parameter* (
|
| 563 |
+
[[temp.arg.type]]).
|
| 564 |
+
|
| 565 |
+
``` cpp
|
| 566 |
+
typedef int FIC(int) const;
|
| 567 |
+
FIC f; // ill-formed: does not declare a member function
|
| 568 |
+
struct S {
|
| 569 |
+
FIC f; // OK
|
| 570 |
+
};
|
| 571 |
+
FIC S::*pm = &S::f; // OK
|
| 572 |
+
```
|
| 573 |
|
| 574 |
The effect of a *cv-qualifier-seq* in a function declarator is not the
|
| 575 |
same as adding cv-qualification on top of the function type. In the
|
| 576 |
latter case, the cv-qualifiers are ignored. a function type that has a
|
| 577 |
*cv-qualifier-seq* is not a cv-qualified type; there are no cv-qualified
|
|
|
|
| 600 |
declares a function taking three arguments of the specified types, and
|
| 601 |
returning `int` ([[dcl.type]]).
|
| 602 |
|
| 603 |
If the type of a parameter includes a type of the form “pointer to array
|
| 604 |
of unknown bound of `T`” or “reference to array of unknown bound of
|
| 605 |
+
`T`,” the program is ill-formed.[^10] Functions shall not have a return
|
| 606 |
type of type array or function, although they may have a return type of
|
| 607 |
type pointer or reference to such things. There shall be no arrays of
|
| 608 |
functions, although there can be arrays of pointers to functions.
|
| 609 |
|
| 610 |
Types shall not be defined in return or parameter types. The type of a
|
| 611 |
parameter or the return type for a function definition shall not be an
|
| 612 |
+
incomplete class type (possibly cv-qualified) unless the function is
|
| 613 |
+
deleted ([[dcl.fct.def.delete]]) or the definition is nested within the
|
| 614 |
+
*member-specification* for that class (including definitions in nested
|
| 615 |
+
classes defined within the class).
|
| 616 |
|
| 617 |
A typedef of function type may be used to declare a function but shall
|
| 618 |
not be used to define a function ([[dcl.fct.def]]).
|
| 619 |
|
| 620 |
``` cpp
|
|
|
|
| 622 |
F fv; // OK: equivalent to void fv();
|
| 623 |
F fv { } // ill-formed
|
| 624 |
void fv() { } // OK: definition of fv
|
| 625 |
```
|
| 626 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 627 |
An identifier can optionally be provided as a parameter name; if present
|
| 628 |
+
in a function definition ([[dcl.fct.def]]), it names a parameter. In
|
| 629 |
+
particular, parameter names are also optional in function definitions
|
| 630 |
+
and names used for a parameter in different declarations and the
|
| 631 |
+
definition of a function need not be the same. If a parameter name is
|
| 632 |
+
present in a function declaration that is not a definition, it cannot be
|
| 633 |
+
used outside of its function declarator because that is the extent of
|
| 634 |
+
its potential scope ([[basic.scope.proto]]).
|
|
|
|
| 635 |
|
| 636 |
the declaration
|
| 637 |
|
| 638 |
``` cpp
|
| 639 |
int i,
|
|
|
|
| 667 |
```
|
| 668 |
|
| 669 |
or
|
| 670 |
|
| 671 |
``` cpp
|
| 672 |
+
auto fpif(int)->int(*)(int);
|
| 673 |
```
|
| 674 |
|
| 675 |
A *trailing-return-type* is most useful for a type that would be more
|
| 676 |
complicated to specify before the *declarator-id*:
|
| 677 |
|
|
|
|
| 683 |
|
| 684 |
``` cpp
|
| 685 |
template <class T, class U> decltype((*(T*)0) + (*(U*)0)) add(T t, U u);
|
| 686 |
```
|
| 687 |
|
| 688 |
+
A *non-template function* is a function that is not a function template
|
| 689 |
+
specialization. A function template is not a function.
|
| 690 |
+
|
| 691 |
A *declarator-id* or *abstract-declarator* containing an ellipsis shall
|
| 692 |
only be used in a *parameter-declaration*. Such a
|
| 693 |
*parameter-declaration* is a parameter pack ([[temp.variadic]]). When
|
| 694 |
it is part of a *parameter-declaration-clause*, the parameter pack is a
|
| 695 |
function parameter pack ([[temp.variadic]]). Otherwise, the
|
|
|
|
| 709 |
```
|
| 710 |
|
| 711 |
There is a syntactic ambiguity when an ellipsis occurs at the end of a
|
| 712 |
*parameter-declaration-clause* without a preceding comma. In this case,
|
| 713 |
the ellipsis is parsed as part of the *abstract-declarator* if the type
|
| 714 |
+
of the parameter either names a template parameter pack that has not
|
| 715 |
+
been expanded or contains `auto`; otherwise, it is parsed as part of the
|
| 716 |
+
*parameter-declaration-clause*.[^11]
|
| 717 |
|
| 718 |
### Default arguments <a id="dcl.fct.default">[[dcl.fct.default]]</a>
|
| 719 |
|
| 720 |
If an *initializer-clause* is specified in a *parameter-declaration*
|
| 721 |
this *initializer-clause* is used as a default argument. Default
|
|
|
|
| 741 |
*parameter-declaration-clause* of a function declaration or in a
|
| 742 |
*template-parameter* ([[temp.param]]); in the latter case, the
|
| 743 |
*initializer-clause* shall be an *assignment-expression*. A default
|
| 744 |
argument shall not be specified for a parameter pack. If it is specified
|
| 745 |
in a *parameter-declaration-clause*, it shall not occur within a
|
| 746 |
+
*declarator* or *abstract-declarator* of a *parameter-declaration*.[^12]
|
| 747 |
|
| 748 |
For non-template functions, default arguments can be added in later
|
| 749 |
declarations of a function in the same scope. Declarations in different
|
| 750 |
scopes have completely distinct sets of default arguments. That is,
|
| 751 |
declarations in inner scopes do not acquire default arguments from
|
|
|
|
| 784 |
units shall be the same; see [[basic.def.odr]]. If a friend declaration
|
| 785 |
specifies a default argument expression, that declaration shall be a
|
| 786 |
definition and shall be the only declaration of the function or function
|
| 787 |
template in the translation unit.
|
| 788 |
|
| 789 |
+
The default argument has the same semantic constraints as the
|
| 790 |
+
initializer in a declaration of a variable of the parameter type, using
|
| 791 |
+
the copy-initialization semantics ([[dcl.init]]). The names in the
|
| 792 |
+
default argument are bound, and the semantic constraints are checked, at
|
| 793 |
+
the point where the default argument appears. Name lookup and checking
|
| 794 |
+
of semantic constraints for default arguments in function templates and
|
| 795 |
+
in member functions of class templates are performed as described in
|
| 796 |
+
[[temp.inst]]. in the following code, `g` will be called with the value
|
| 797 |
+
`f(2)`:
|
|
|
|
| 798 |
|
| 799 |
``` cpp
|
| 800 |
int a = 1;
|
| 801 |
int f(int);
|
| 802 |
int g(int x = f(a)); // default argument: f(::a)
|
|
|
|
| 815 |
names in default arguments as described in Clause [[class.access]].
|
| 816 |
|
| 817 |
Except for member functions of class templates, the default arguments in
|
| 818 |
a member function definition that appears outside of the class
|
| 819 |
definition are added to the set of default arguments provided by the
|
| 820 |
+
member function declaration in the class definition; the program is
|
| 821 |
+
ill-formed if a default constructor ([[class.ctor]]), copy or move
|
| 822 |
+
constructor, or copy or move assignment operator ([[class.copy]]) is so
|
| 823 |
+
declared. Default arguments for a member function of a class template
|
| 824 |
+
shall be specified on the initial declaration of the member function
|
| 825 |
+
within the class template.
|
| 826 |
|
| 827 |
``` cpp
|
| 828 |
class C {
|
| 829 |
void f(int i = 3);
|
| 830 |
void g(int i, int j = 99);
|
|
|
|
| 853 |
class A {
|
| 854 |
void f(A* p = this) { } // error
|
| 855 |
};
|
| 856 |
```
|
| 857 |
|
| 858 |
+
A default argument is evaluated each time the function is called with no
|
| 859 |
+
argument for the corresponding parameter. The order of evaluation of
|
| 860 |
+
function arguments is unspecified. Consequently, parameters of a
|
| 861 |
+
function shall not be used in a default argument, even if they are not
|
| 862 |
+
evaluated. Parameters of a function declared before a default argument
|
| 863 |
+
are in scope and can hide namespace and class member names.
|
| 864 |
|
| 865 |
``` cpp
|
| 866 |
int a;
|
| 867 |
int f(int a, int b = a); // error: parameter a
|
| 868 |
// used as default argument
|