- tmp/tmppwnft8oz/{from.md → to.md} +169 -110
tmp/tmppwnft8oz/{from.md → to.md}
RENAMED
|
@@ -13,23 +13,23 @@ init-declarator-list:
|
|
| 13 |
init-declarator-list ',' init-declarator
|
| 14 |
```
|
| 15 |
|
| 16 |
``` bnf
|
| 17 |
init-declarator:
|
| 18 |
-
declarator initializer
|
| 19 |
-
declarator requires-clause
|
| 20 |
```
|
| 21 |
|
| 22 |
In all contexts, a *declarator* is interpreted as given below. Where an
|
| 23 |
*abstract-declarator* can be used (or omitted) in place of a
|
| 24 |
*declarator* [[dcl.fct]], [[except.pre]], it is as if a unique
|
| 25 |
identifier were included in the appropriate place [[dcl.name]]. The
|
| 26 |
-
preceding specifiers indicate the type, storage
|
| 27 |
-
properties of the entity or entities being declared. Each
|
| 28 |
-
specifies one entity and (optionally) names it and/or
|
| 29 |
-
of the specifiers with operators such as `*` (pointer
|
| 30 |
-
(function returning).
|
| 31 |
|
| 32 |
[*Note 1*: An *init-declarator* can also specify an initializer
|
| 33 |
[[dcl.init]]. — *end note*]
|
| 34 |
|
| 35 |
Each *init-declarator* or *member-declarator* in a declaration is
|
|
@@ -107,10 +107,14 @@ void g(int (*)() requires true); // error: constraint on a parameter-
|
|
| 107 |
auto* p = new void(*)(char) requires true; // error: not a function declaration
|
| 108 |
```
|
| 109 |
|
| 110 |
— *end example*]
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
Declarators have the syntax
|
| 113 |
|
| 114 |
``` bnf
|
| 115 |
declarator:
|
| 116 |
ptr-declarator
|
|
@@ -174,13 +178,13 @@ declarator-id:
|
|
| 174 |
|
| 175 |
### Type names <a id="dcl.name">[[dcl.name]]</a>
|
| 176 |
|
| 177 |
To specify type conversions explicitly, and as an argument of `sizeof`,
|
| 178 |
`alignof`, `new`, or `typeid`, the name of a type shall be specified.
|
| 179 |
-
This can be done with a *type-id*
|
| 180 |
-
for a variable or function of that type
|
| 181 |
-
entity.
|
| 182 |
|
| 183 |
``` bnf
|
| 184 |
type-id:
|
| 185 |
type-specifier-seq abstract-declaratorₒₚₜ
|
| 186 |
```
|
|
@@ -217,11 +221,10 @@ abstract-pack-declarator:
|
|
| 217 |
```
|
| 218 |
|
| 219 |
``` bnf
|
| 220 |
noptr-abstract-pack-declarator:
|
| 221 |
noptr-abstract-pack-declarator parameters-and-qualifiers
|
| 222 |
-
noptr-abstract-pack-declarator '[' constant-expressionₒₚₜ ']' attribute-specifier-seqₒₚₜ
|
| 223 |
'...'
|
| 224 |
```
|
| 225 |
|
| 226 |
It is possible to identify uniquely the location in the
|
| 227 |
*abstract-declarator* where the identifier would appear if the
|
|
@@ -244,12 +247,13 @@ pointers to `int`”, “pointer to array of 3 `int`”, “function of (no
|
|
| 244 |
parameters) returning pointer to `int`”, and “pointer to a function of
|
| 245 |
(`double`) returning `int`”.
|
| 246 |
|
| 247 |
— *end example*]
|
| 248 |
|
| 249 |
-
A type can also be named
|
| 250 |
-
|
|
|
|
| 251 |
|
| 252 |
### Ambiguity resolution <a id="dcl.ambig.res">[[dcl.ambig.res]]</a>
|
| 253 |
|
| 254 |
The ambiguity arising from the similarity between a function-style cast
|
| 255 |
and a declaration mentioned in [[stmt.ambig]] can also occur in the
|
|
@@ -257,11 +261,14 @@ context of a declaration. In that context, the choice is between an
|
|
| 257 |
object declaration with a function-style cast as the initializer and a
|
| 258 |
declaration involving a function declarator with a redundant set of
|
| 259 |
parentheses around a parameter name. Just as for the ambiguities
|
| 260 |
mentioned in [[stmt.ambig]], the resolution is to consider any
|
| 261 |
construct, such as the potential parameter declaration, that could
|
| 262 |
-
possibly be a declaration to be a declaration.
|
|
|
|
|
|
|
|
|
|
| 263 |
|
| 264 |
[*Note 1*: A declaration can be explicitly disambiguated by adding
|
| 265 |
parentheses around the argument. The ambiguity can be avoided by use of
|
| 266 |
copy-initialization or list-initialization syntax, or by use of a
|
| 267 |
non-function-style cast. — *end note*]
|
|
@@ -270,26 +277,32 @@ non-function-style cast. — *end note*]
|
|
| 270 |
|
| 271 |
``` cpp
|
| 272 |
struct S {
|
| 273 |
S(int);
|
| 274 |
};
|
|
|
|
| 275 |
|
| 276 |
void foo(double a) {
|
| 277 |
-
S
|
| 278 |
-
S
|
| 279 |
-
S
|
| 280 |
S y((int)a); // object declaration
|
| 281 |
S z = int(a); // object declaration
|
|
|
|
|
|
|
| 282 |
}
|
| 283 |
```
|
| 284 |
|
| 285 |
— *end example*]
|
| 286 |
|
| 287 |
An ambiguity can arise from the similarity between a function-style cast
|
| 288 |
and a *type-id*. The resolution is that any construct that could
|
| 289 |
possibly be a *type-id* in its syntactic context shall be considered a
|
| 290 |
-
*type-id*.
|
|
|
|
|
|
|
|
|
|
| 291 |
|
| 292 |
[*Example 2*:
|
| 293 |
|
| 294 |
``` cpp
|
| 295 |
template <class T> struct X {};
|
|
@@ -306,10 +319,16 @@ void foo(signed char a) {
|
|
| 306 |
|
| 307 |
(int())+1; // type-id (ill-formed)
|
| 308 |
(int(a))+1; // expression
|
| 309 |
(int(unsigned(a)))+1; // type-id (ill-formed)
|
| 310 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 311 |
```
|
| 312 |
|
| 313 |
— *end example*]
|
| 314 |
|
| 315 |
Another ambiguity arises in a *parameter-declaration-clause* when a
|
|
@@ -503,11 +522,11 @@ the type specifiers `int` `unsigned` determine the type “`unsigned int`”
|
|
| 503 |
[[dcl.type.simple]].
|
| 504 |
|
| 505 |
— *end example*]
|
| 506 |
|
| 507 |
In a declaration *attribute-specifier-seq*ₒₚₜ `T` `D` where `D` is an
|
| 508 |
-
unadorned
|
| 509 |
|
| 510 |
In a declaration `T` `D` where `D` has the form
|
| 511 |
|
| 512 |
``` bnf
|
| 513 |
'(' 'D1' ')'
|
|
@@ -584,13 +603,13 @@ cv-unqualified pointer later, for example:
|
|
| 584 |
``` cpp
|
| 585 |
*ppc = &ci; // OK, but would make p point to ci because of previous error
|
| 586 |
*p = 5; // clobber ci
|
| 587 |
```
|
| 588 |
|
| 589 |
-
|
| 590 |
|
| 591 |
-
|
| 592 |
|
| 593 |
[*Note 1*: Forming a pointer to reference type is ill-formed; see
|
| 594 |
[[dcl.ref]]. Forming a function pointer type is ill-formed if the
|
| 595 |
function type has *cv-qualifier*s or a *ref-qualifier*; see
|
| 596 |
[[dcl.fct]]. Since the address of a bit-field [[class.bit]] cannot be
|
|
@@ -627,12 +646,11 @@ to `const int`”.
|
|
| 627 |
— *end example*]
|
| 628 |
|
| 629 |
[*Note 1*: A reference can be thought of as a name of an
|
| 630 |
object. — *end note*]
|
| 631 |
|
| 632 |
-
|
| 633 |
-
ill-formed.
|
| 634 |
|
| 635 |
A reference type that is declared using `&` is called an *lvalue
|
| 636 |
reference*, and a reference type that is declared using `&&` is called
|
| 637 |
an *rvalue reference*. Lvalue references and rvalue references are
|
| 638 |
distinct types. Except where explicitly noted, they are semantically
|
|
@@ -693,29 +711,57 @@ There shall be no references to references, no arrays of references, and
|
|
| 693 |
no pointers to references. The declaration of a reference shall contain
|
| 694 |
an *initializer* [[dcl.init.ref]] except when the declaration contains
|
| 695 |
an explicit `extern` specifier [[dcl.stc]], is a class member
|
| 696 |
[[class.mem]] declaration within a class definition, or is the
|
| 697 |
declaration of a parameter or a return type [[dcl.fct]]; see
|
| 698 |
-
[[basic.def]].
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
|
| 702 |
-
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
[[
|
| 706 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 707 |
|
| 708 |
If a *typedef-name* [[dcl.typedef]], [[temp.param]] or a
|
| 709 |
*decltype-specifier* [[dcl.type.decltype]] denotes a type `TR` that is a
|
| 710 |
reference to a type `T`, an attempt to create the type “lvalue reference
|
| 711 |
to cv `TR`” creates the type “lvalue reference to `T`”, while an attempt
|
| 712 |
to create the type “rvalue reference to cv `TR`” creates the type `TR`.
|
| 713 |
|
| 714 |
[*Note 3*: This rule is known as reference collapsing. — *end note*]
|
| 715 |
|
| 716 |
-
[*Example
|
| 717 |
|
| 718 |
``` cpp
|
| 719 |
int i;
|
| 720 |
typedef int& LRI;
|
| 721 |
typedef int&& RRI;
|
|
@@ -746,17 +792,18 @@ In a declaration `T` `D` where `D` has the form
|
|
| 746 |
|
| 747 |
``` bnf
|
| 748 |
nested-name-specifier '*' attribute-specifier-seqₒₚₜ cv-qualifier-seqₒₚₜ 'D1'
|
| 749 |
```
|
| 750 |
|
| 751 |
-
and the *nested-name-specifier*
|
| 752 |
contained *declarator-id* in the declaration `T` `D1` is
|
| 753 |
“*derived-declarator-type-list* `T`”, the type of the *declarator-id* in
|
| 754 |
`D` is “*derived-declarator-type-list* *cv-qualifier-seq* pointer to
|
| 755 |
member of class *nested-name-specifier* of type `T`”. The optional
|
| 756 |
*attribute-specifier-seq* [[dcl.attr.grammar]] appertains to the
|
| 757 |
-
pointer-to-member.
|
|
|
|
| 758 |
|
| 759 |
[*Example 1*:
|
| 760 |
|
| 761 |
``` cpp
|
| 762 |
struct X {
|
|
@@ -878,13 +925,14 @@ initialized and the declarator is followed by an initializer
|
|
| 878 |
cases, the array bound is calculated from the number of initial elements
|
| 879 |
(say, `N`) supplied [[dcl.init.aggr]], and the type of the array is
|
| 880 |
“array of `N` `U`”.
|
| 881 |
|
| 882 |
Furthermore, if there is a reachable declaration of the entity that
|
| 883 |
-
|
| 884 |
-
array bound is taken to be the same as in that earlier
|
| 885 |
-
similarly for the definition of a static data member of
|
|
|
|
| 886 |
|
| 887 |
[*Example 3*:
|
| 888 |
|
| 889 |
``` cpp
|
| 890 |
extern int x[10];
|
|
@@ -897,10 +945,13 @@ int S::y[]; // OK, bound is 10
|
|
| 897 |
|
| 898 |
void f() {
|
| 899 |
extern int x[];
|
| 900 |
int i = sizeof(x); // error: incomplete object type
|
| 901 |
}
|
|
|
|
|
|
|
|
|
|
| 902 |
```
|
| 903 |
|
| 904 |
— *end example*]
|
| 905 |
|
| 906 |
[*Note 3*:
|
|
@@ -949,58 +1000,55 @@ described in [[conv.array]]. — *end note*]
|
|
| 949 |
[[over.sub]]. For the operator’s built-in meaning, see
|
| 950 |
[[expr.sub]]. — *end note*]
|
| 951 |
|
| 952 |
#### Functions <a id="dcl.fct">[[dcl.fct]]</a>
|
| 953 |
|
| 954 |
-
In a declaration `T` `D` where `D` has the form
|
| 955 |
|
| 956 |
``` bnf
|
| 957 |
'D1' '(' parameter-declaration-clause ')' cv-qualifier-seqₒₚₜ
|
| 958 |
-
ref-qualifierₒₚₜ noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ
|
| 959 |
```
|
| 960 |
|
| 961 |
-
|
| 962 |
-
`D1` is “*derived-declarator-type-list* `T`”, the type of the
|
| 963 |
-
*declarator-id* in `D` is “*derived-declarator-type-list* `noexcept`ₒₚₜ
|
| 964 |
-
function of parameter-type-list *cv-qualifier-seq*ₒₚₜ
|
| 965 |
-
*ref-qualifier*ₒₚₜ returning `T`”, where
|
| 966 |
|
| 967 |
-
- the
|
| 968 |
-
*
|
| 969 |
-
- the
|
| 970 |
-
|
|
|
|
| 971 |
|
| 972 |
-
The
|
|
|
|
| 973 |
|
| 974 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 975 |
|
| 976 |
-
``
|
| 977 |
-
'D1' '(' parameter-declaration-clause ')' cv-qualifier-seqₒₚₜ
|
| 978 |
-
ref-qualifierₒₚₜ noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ trailing-return-type
|
| 979 |
-
```
|
| 980 |
-
|
| 981 |
-
and the type of the contained *declarator-id* in the declaration `T`
|
| 982 |
-
`D1` is “*derived-declarator-type-list* `T`”, `T` shall be the single
|
| 983 |
-
*type-specifier* `auto`. The type of the *declarator-id* in `D` is
|
| 984 |
“*derived-declarator-type-list* `noexcept`ₒₚₜ function of
|
| 985 |
parameter-type-list *cv-qualifier-seq*ₒₚₜ *ref-qualifier*ₒₚₜ returning
|
| 986 |
`U`”, where
|
| 987 |
|
| 988 |
- the parameter-type-list is derived from the
|
| 989 |
-
*parameter-declaration-clause* as described below
|
| 990 |
-
- `U` is the type specified by the *trailing-return-type*, and
|
| 991 |
- the optional `noexcept` is present if and only if the exception
|
| 992 |
-
specification is non-throwing.
|
|
|
|
|
|
|
| 993 |
|
| 994 |
The optional *attribute-specifier-seq* appertains to the function type.
|
| 995 |
|
| 996 |
-
A type of either form is a *function type*.[^2]
|
| 997 |
-
|
| 998 |
``` bnf
|
| 999 |
parameter-declaration-clause:
|
| 1000 |
-
|
|
|
|
| 1001 |
parameter-declaration-list ',' '...'
|
|
|
|
| 1002 |
```
|
| 1003 |
|
| 1004 |
``` bnf
|
| 1005 |
parameter-declaration-list:
|
| 1006 |
parameter-declaration
|
|
@@ -1024,20 +1072,23 @@ specified, and their processing, when the function is called.
|
|
| 1024 |
[*Note 1*: The *parameter-declaration-clause* is used to convert the
|
| 1025 |
arguments specified on the function call; see
|
| 1026 |
[[expr.call]]. — *end note*]
|
| 1027 |
|
| 1028 |
If the *parameter-declaration-clause* is empty, the function takes no
|
| 1029 |
-
arguments. A parameter list consisting of a single unnamed
|
| 1030 |
-
non-dependent type `void` is equivalent to an empty
|
| 1031 |
-
Except for this special case, a parameter shall not have
|
| 1032 |
-
A parameter with volatile-qualified type is deprecated;
|
| 1033 |
-
[[depr.volatile.type]]. If the *parameter-declaration-clause*
|
| 1034 |
-
with an ellipsis or a function parameter pack
|
| 1035 |
-
number of arguments shall be equal to or greater
|
| 1036 |
-
parameters that do not have a default argument and
|
| 1037 |
-
parameter packs. Where syntactically correct and where
|
| 1038 |
-
part of an *abstract-declarator*, “`
|
|
|
|
|
|
|
|
|
|
| 1039 |
|
| 1040 |
[*Example 1*:
|
| 1041 |
|
| 1042 |
The declaration
|
| 1043 |
|
|
@@ -1096,14 +1147,16 @@ void h(int (*)(int)) {} // defines #3
|
|
| 1096 |
— *end example*]
|
| 1097 |
|
| 1098 |
An *explicit-object-parameter-declaration* is a *parameter-declaration*
|
| 1099 |
with a `this` specifier. An explicit-object-parameter-declaration shall
|
| 1100 |
appear only as the first *parameter-declaration* of a
|
| 1101 |
-
*parameter-declaration-list* of
|
| 1102 |
|
| 1103 |
-
- a
|
| 1104 |
-
or
|
|
|
|
|
|
|
| 1105 |
- a *lambda-declarator* [[expr.prim.lambda]].
|
| 1106 |
|
| 1107 |
A *member-declarator* with an explicit-object-parameter-declaration
|
| 1108 |
shall not include a *ref-qualifier* or a *cv-qualifier-seq* and shall
|
| 1109 |
not be declared `static` or `virtual`.
|
|
@@ -1146,31 +1199,33 @@ explicit object parameter, if any, omitted.
|
|
| 1146 |
|
| 1147 |
[*Note 4*: The non-object-parameter-type-list consists of the adjusted
|
| 1148 |
types of all the non-object parameters. — *end note*]
|
| 1149 |
|
| 1150 |
A function type with a *cv-qualifier-seq* or a *ref-qualifier*
|
| 1151 |
-
(including a type
|
| 1152 |
[[dcl.typedef]], [[temp.param]]) shall appear only as:
|
| 1153 |
|
| 1154 |
- the function type for a non-static member function,
|
| 1155 |
- the function type to which a pointer to member refers,
|
| 1156 |
- the top-level function type of a function typedef declaration or
|
| 1157 |
*alias-declaration*,
|
| 1158 |
- the *type-id* in the default argument of a *type-parameter*
|
| 1159 |
-
[[temp.param]],
|
| 1160 |
- the *type-id* of a *template-argument* for a *type-parameter*
|
| 1161 |
-
[[temp.arg.type]]
|
|
|
|
| 1162 |
|
| 1163 |
[*Example 4*:
|
| 1164 |
|
| 1165 |
``` cpp
|
| 1166 |
typedef int FIC(int) const;
|
| 1167 |
FIC f; // error: does not declare a member function
|
| 1168 |
struct S {
|
| 1169 |
FIC f; // OK
|
| 1170 |
};
|
| 1171 |
FIC S::*pm = &S::f; // OK
|
|
|
|
| 1172 |
```
|
| 1173 |
|
| 1174 |
— *end example*]
|
| 1175 |
|
| 1176 |
The effect of a *cv-qualifier-seq* in a function declarator is not the
|
|
@@ -1317,24 +1372,24 @@ specialization.
|
|
| 1317 |
[*Note 11*: A function template is not a function. — *end note*]
|
| 1318 |
|
| 1319 |
An *abbreviated function template* is a function declaration that has
|
| 1320 |
one or more generic parameter type placeholders [[dcl.spec.auto]]. An
|
| 1321 |
abbreviated function template is equivalent to a function template
|
| 1322 |
-
[[temp.fct]] whose *template-parameter-list* includes one invented
|
| 1323 |
-
*
|
| 1324 |
function declaration, in order of appearance. For a
|
| 1325 |
*placeholder-type-specifier* of the form `auto`, the invented parameter
|
| 1326 |
is an unconstrained *type-parameter*. For a *placeholder-type-specifier*
|
| 1327 |
of the form *type-constraint* `auto`, the invented parameter is a
|
| 1328 |
-
*type-parameter* with that *type-constraint*. The invented
|
| 1329 |
-
*
|
| 1330 |
*parameter-declaration* declares a function parameter pack. If the
|
| 1331 |
placeholder contains `decltype(auto)`, the program is ill-formed. The
|
| 1332 |
adjusted function parameters of an abbreviated function template are
|
| 1333 |
derived from the *parameter-declaration-clause* by replacing each
|
| 1334 |
occurrence of a placeholder with the name of the corresponding invented
|
| 1335 |
-
*
|
| 1336 |
|
| 1337 |
[*Example 9*:
|
| 1338 |
|
| 1339 |
``` cpp
|
| 1340 |
template<typename T> concept C1 = /* ... */;
|
|
@@ -1365,13 +1420,12 @@ template<> void g1<int>(const int*, const double&); // OK, specialization of g1<
|
|
| 1365 |
```
|
| 1366 |
|
| 1367 |
— *end example*]
|
| 1368 |
|
| 1369 |
An abbreviated function template can have a *template-head*. The
|
| 1370 |
-
invented *
|
| 1371 |
-
|
| 1372 |
-
*template-parameter*s.
|
| 1373 |
|
| 1374 |
[*Example 10*:
|
| 1375 |
|
| 1376 |
``` cpp
|
| 1377 |
template<typename> concept C = /* ... */;
|
|
@@ -1455,20 +1509,19 @@ respectively.
|
|
| 1455 |
|
| 1456 |
— *end example*]
|
| 1457 |
|
| 1458 |
A default argument shall be specified only in the
|
| 1459 |
*parameter-declaration-clause* of a function declaration or
|
| 1460 |
-
*lambda-declarator* or in a *template-parameter* [[temp.param]]
|
| 1461 |
-
|
| 1462 |
-
|
| 1463 |
-
|
| 1464 |
-
|
| 1465 |
-
*declarator* or *abstract-declarator* of a *parameter-declaration*.[^4]
|
| 1466 |
|
| 1467 |
For non-template functions, default arguments can be added in later
|
| 1468 |
-
declarations of a function that
|
| 1469 |
-
that
|
| 1470 |
arguments. That is, declarations in inner scopes do not acquire default
|
| 1471 |
arguments from declarations in outer scopes, and vice versa. In a given
|
| 1472 |
function declaration, each parameter subsequent to a parameter with a
|
| 1473 |
default argument shall have a default argument supplied in this or a
|
| 1474 |
previous declaration, unless the parameter was expanded from a parameter
|
|
@@ -1549,19 +1602,19 @@ void h() {
|
|
| 1549 |
|
| 1550 |
[*Note 3*: A default argument is a complete-class context
|
| 1551 |
[[class.mem]]. Access checking applies to names in default arguments as
|
| 1552 |
described in [[class.access]]. — *end note*]
|
| 1553 |
|
| 1554 |
-
Except for member functions of
|
| 1555 |
-
a member function definition that appears outside of the class
|
| 1556 |
definition are added to the set of default arguments provided by the
|
| 1557 |
member function declaration in the class definition; the program is
|
| 1558 |
ill-formed if a default constructor [[class.default.ctor]], copy or move
|
| 1559 |
constructor [[class.copy.ctor]], or copy or move assignment operator
|
| 1560 |
[[class.copy.assign]] is so declared. Default arguments for a member
|
| 1561 |
-
function of a class
|
| 1562 |
-
declaration of the member function within the
|
| 1563 |
|
| 1564 |
[*Example 4*:
|
| 1565 |
|
| 1566 |
``` cpp
|
| 1567 |
class C {
|
|
@@ -1626,14 +1679,17 @@ int g(float I, int b = I(2)); // error: parameter I found
|
|
| 1626 |
int h(int a, int b = sizeof(a)); // OK, unevaluated operand[term.unevaluated.operand]
|
| 1627 |
```
|
| 1628 |
|
| 1629 |
— *end example*]
|
| 1630 |
|
| 1631 |
-
A non-static member shall not
|
| 1632 |
-
|
| 1633 |
-
|
| 1634 |
-
[[expr.
|
|
|
|
|
|
|
|
|
|
| 1635 |
|
| 1636 |
[*Example 8*:
|
| 1637 |
|
| 1638 |
The declaration of `X::mem1()` in the following example is ill-formed
|
| 1639 |
because no object is supplied for the non-static member `X::a` used as
|
|
@@ -1642,11 +1698,13 @@ an initializer.
|
|
| 1642 |
``` cpp
|
| 1643 |
int b;
|
| 1644 |
class X {
|
| 1645 |
int a;
|
| 1646 |
int mem1(int i = a); // error: non-static member a used as default argument
|
| 1647 |
-
int mem2(int i = b);
|
|
|
|
|
|
|
| 1648 |
static int b;
|
| 1649 |
};
|
| 1650 |
```
|
| 1651 |
|
| 1652 |
The declaration of `X::mem2()` is meaningful, however, since no object
|
|
@@ -1671,15 +1729,16 @@ int (*p1)(int) = &f;
|
|
| 1671 |
int (*p2)() = &f; // error: type mismatch
|
| 1672 |
```
|
| 1673 |
|
| 1674 |
— *end example*]
|
| 1675 |
|
| 1676 |
-
When an overload set contains a declaration of a function
|
| 1677 |
-
|
| 1678 |
-
declaration
|
|
|
|
| 1679 |
|
| 1680 |
-
[*Note
|
| 1681 |
*using-declarator* from which the declaration that provides the default
|
| 1682 |
argument is not reachable. — *end note*]
|
| 1683 |
|
| 1684 |
A virtual function call [[class.virtual]] uses the default arguments in
|
| 1685 |
the declaration of the virtual function determined by the static type of
|
|
|
|
| 13 |
init-declarator-list ',' init-declarator
|
| 14 |
```
|
| 15 |
|
| 16 |
``` bnf
|
| 17 |
init-declarator:
|
| 18 |
+
declarator initializer
|
| 19 |
+
declarator requires-clauseₒₚₜ function-contract-specifier-seqₒₚₜ
|
| 20 |
```
|
| 21 |
|
| 22 |
In all contexts, a *declarator* is interpreted as given below. Where an
|
| 23 |
*abstract-declarator* can be used (or omitted) in place of a
|
| 24 |
*declarator* [[dcl.fct]], [[except.pre]], it is as if a unique
|
| 25 |
identifier were included in the appropriate place [[dcl.name]]. The
|
| 26 |
+
preceding specifiers indicate the type, storage duration, linkage, or
|
| 27 |
+
other properties of the entity or entities being declared. Each
|
| 28 |
+
declarator specifies one entity and (optionally) names it and/or
|
| 29 |
+
modifies the type of the specifiers with operators such as `*` (pointer
|
| 30 |
+
to) and `()` (function returning).
|
| 31 |
|
| 32 |
[*Note 1*: An *init-declarator* can also specify an initializer
|
| 33 |
[[dcl.init]]. — *end note*]
|
| 34 |
|
| 35 |
Each *init-declarator* or *member-declarator* in a declaration is
|
|
|
|
| 107 |
auto* p = new void(*)(char) requires true; // error: not a function declaration
|
| 108 |
```
|
| 109 |
|
| 110 |
— *end example*]
|
| 111 |
|
| 112 |
+
The optional *function-contract-specifier-seq* [[dcl.contract.func]] in
|
| 113 |
+
an *init-declarator* shall be present only if the *declarator* declares
|
| 114 |
+
a function.
|
| 115 |
+
|
| 116 |
Declarators have the syntax
|
| 117 |
|
| 118 |
``` bnf
|
| 119 |
declarator:
|
| 120 |
ptr-declarator
|
|
|
|
| 178 |
|
| 179 |
### Type names <a id="dcl.name">[[dcl.name]]</a>
|
| 180 |
|
| 181 |
To specify type conversions explicitly, and as an argument of `sizeof`,
|
| 182 |
`alignof`, `new`, or `typeid`, the name of a type shall be specified.
|
| 183 |
+
This can be done with a *type-id* or *new-type-id* [[expr.new]], which
|
| 184 |
+
is syntactically a declaration for a variable or function of that type
|
| 185 |
+
that omits the name of the entity.
|
| 186 |
|
| 187 |
``` bnf
|
| 188 |
type-id:
|
| 189 |
type-specifier-seq abstract-declaratorₒₚₜ
|
| 190 |
```
|
|
|
|
| 221 |
```
|
| 222 |
|
| 223 |
``` bnf
|
| 224 |
noptr-abstract-pack-declarator:
|
| 225 |
noptr-abstract-pack-declarator parameters-and-qualifiers
|
|
|
|
| 226 |
'...'
|
| 227 |
```
|
| 228 |
|
| 229 |
It is possible to identify uniquely the location in the
|
| 230 |
*abstract-declarator* where the identifier would appear if the
|
|
|
|
| 247 |
parameters) returning pointer to `int`”, and “pointer to a function of
|
| 248 |
(`double`) returning `int`”.
|
| 249 |
|
| 250 |
— *end example*]
|
| 251 |
|
| 252 |
+
[*Note 1*: A type can also be named by a *typedef-name*, which is
|
| 253 |
+
introduced by a typedef declaration or *alias-declaration*
|
| 254 |
+
[[dcl.typedef]]. — *end note*]
|
| 255 |
|
| 256 |
### Ambiguity resolution <a id="dcl.ambig.res">[[dcl.ambig.res]]</a>
|
| 257 |
|
| 258 |
The ambiguity arising from the similarity between a function-style cast
|
| 259 |
and a declaration mentioned in [[stmt.ambig]] can also occur in the
|
|
|
|
| 261 |
object declaration with a function-style cast as the initializer and a
|
| 262 |
declaration involving a function declarator with a redundant set of
|
| 263 |
parentheses around a parameter name. Just as for the ambiguities
|
| 264 |
mentioned in [[stmt.ambig]], the resolution is to consider any
|
| 265 |
construct, such as the potential parameter declaration, that could
|
| 266 |
+
possibly be a declaration to be a declaration. However, a construct that
|
| 267 |
+
can syntactically be a *declaration* whose outermost *declarator* would
|
| 268 |
+
match the grammar of a *declarator* with a *trailing-return-type* is a
|
| 269 |
+
declaration only if it starts with `auto`.
|
| 270 |
|
| 271 |
[*Note 1*: A declaration can be explicitly disambiguated by adding
|
| 272 |
parentheses around the argument. The ambiguity can be avoided by use of
|
| 273 |
copy-initialization or list-initialization syntax, or by use of a
|
| 274 |
non-function-style cast. — *end note*]
|
|
|
|
| 277 |
|
| 278 |
``` cpp
|
| 279 |
struct S {
|
| 280 |
S(int);
|
| 281 |
};
|
| 282 |
+
typedef struct BB { int C[2]; } *B, C;
|
| 283 |
|
| 284 |
void foo(double a) {
|
| 285 |
+
S v(int(a)); // function declaration
|
| 286 |
+
S w(int()); // function declaration
|
| 287 |
+
S x((int(a))); // object declaration
|
| 288 |
S y((int)a); // object declaration
|
| 289 |
S z = int(a); // object declaration
|
| 290 |
+
S a(B()->C); // object declaration
|
| 291 |
+
S b(auto()->C); // function declaration
|
| 292 |
}
|
| 293 |
```
|
| 294 |
|
| 295 |
— *end example*]
|
| 296 |
|
| 297 |
An ambiguity can arise from the similarity between a function-style cast
|
| 298 |
and a *type-id*. The resolution is that any construct that could
|
| 299 |
possibly be a *type-id* in its syntactic context shall be considered a
|
| 300 |
+
*type-id*. However, a construct that can syntactically be a *type-id*
|
| 301 |
+
whose outermost *abstract-declarator* would match the grammar of an
|
| 302 |
+
*abstract-declarator* with a *trailing-return-type* is considered a
|
| 303 |
+
*type-id* only if it starts with `auto`.
|
| 304 |
|
| 305 |
[*Example 2*:
|
| 306 |
|
| 307 |
``` cpp
|
| 308 |
template <class T> struct X {};
|
|
|
|
| 319 |
|
| 320 |
(int())+1; // type-id (ill-formed)
|
| 321 |
(int(a))+1; // expression
|
| 322 |
(int(unsigned(a)))+1; // type-id (ill-formed)
|
| 323 |
}
|
| 324 |
+
|
| 325 |
+
typedef struct BB { int C[2]; } *B, C;
|
| 326 |
+
void g() {
|
| 327 |
+
sizeof(B()->C[1]); // OK, sizeof(expression)
|
| 328 |
+
sizeof(auto()->C[1]); // error: sizeof of a function returning an array
|
| 329 |
+
}
|
| 330 |
```
|
| 331 |
|
| 332 |
— *end example*]
|
| 333 |
|
| 334 |
Another ambiguity arises in a *parameter-declaration-clause* when a
|
|
|
|
| 522 |
[[dcl.type.simple]].
|
| 523 |
|
| 524 |
— *end example*]
|
| 525 |
|
| 526 |
In a declaration *attribute-specifier-seq*ₒₚₜ `T` `D` where `D` is an
|
| 527 |
+
unadorned *declarator-id*, the type of the declared entity is “`T`”.
|
| 528 |
|
| 529 |
In a declaration `T` `D` where `D` has the form
|
| 530 |
|
| 531 |
``` bnf
|
| 532 |
'(' 'D1' ')'
|
|
|
|
| 603 |
``` cpp
|
| 604 |
*ppc = &ci; // OK, but would make p point to ci because of previous error
|
| 605 |
*p = 5; // clobber ci
|
| 606 |
```
|
| 607 |
|
| 608 |
+
See also [[expr.assign]] and [[dcl.init]].
|
| 609 |
|
| 610 |
+
— *end example*]
|
| 611 |
|
| 612 |
[*Note 1*: Forming a pointer to reference type is ill-formed; see
|
| 613 |
[[dcl.ref]]. Forming a function pointer type is ill-formed if the
|
| 614 |
function type has *cv-qualifier*s or a *ref-qualifier*; see
|
| 615 |
[[dcl.fct]]. Since the address of a bit-field [[class.bit]] cannot be
|
|
|
|
| 646 |
— *end example*]
|
| 647 |
|
| 648 |
[*Note 1*: A reference can be thought of as a name of an
|
| 649 |
object. — *end note*]
|
| 650 |
|
| 651 |
+
Forming the type “reference to cv `void`” is ill-formed.
|
|
|
|
| 652 |
|
| 653 |
A reference type that is declared using `&` is called an *lvalue
|
| 654 |
reference*, and a reference type that is declared using `&&` is called
|
| 655 |
an *rvalue reference*. Lvalue references and rvalue references are
|
| 656 |
distinct types. Except where explicitly noted, they are semantically
|
|
|
|
| 711 |
no pointers to references. The declaration of a reference shall contain
|
| 712 |
an *initializer* [[dcl.init.ref]] except when the declaration contains
|
| 713 |
an explicit `extern` specifier [[dcl.stc]], is a class member
|
| 714 |
[[class.mem]] declaration within a class definition, or is the
|
| 715 |
declaration of a parameter or a return type [[dcl.fct]]; see
|
| 716 |
+
[[basic.def]].
|
| 717 |
+
|
| 718 |
+
Attempting to bind a reference to a function where the converted
|
| 719 |
+
initializer is a glvalue whose type is not call-compatible [[expr.call]]
|
| 720 |
+
with the type of the function’s definition results in undefined
|
| 721 |
+
behavior. Attempting to bind a reference to an object where the
|
| 722 |
+
converted initializer is a glvalue through which the object is not
|
| 723 |
+
type-accessible [[basic.lval]] results in undefined behavior.
|
| 724 |
+
|
| 725 |
+
[*Note 2*: The object designated by such a glvalue can be outside its
|
| 726 |
+
lifetime [[basic.life]]. Because a null pointer value or a pointer past
|
| 727 |
+
the end of an object does not point to an object, a reference in a
|
| 728 |
+
well-defined program cannot refer to such things; see
|
| 729 |
+
[[expr.unary.op]]. As described in [[class.bit]], a reference cannot be
|
| 730 |
+
bound directly to a bit-field. — *end note*]
|
| 731 |
+
|
| 732 |
+
The behavior of an evaluation of a reference
|
| 733 |
+
[[expr.prim.id]], [[expr.ref]] that does not happen after
|
| 734 |
+
[[intro.races]] the initialization of the reference is undefined.
|
| 735 |
+
|
| 736 |
+
[*Example 3*:
|
| 737 |
+
|
| 738 |
+
``` cpp
|
| 739 |
+
int &f(int&);
|
| 740 |
+
int &g();
|
| 741 |
+
extern int &ir3;
|
| 742 |
+
int *ip = 0;
|
| 743 |
+
int &ir1 = *ip; // undefined behavior: null pointer
|
| 744 |
+
int &ir2 = f(ir3); // undefined behavior: ir3 not yet initialized
|
| 745 |
+
int &ir3 = g();
|
| 746 |
+
int &ir4 = f(ir4); // undefined behavior: ir4 used in its own initializer
|
| 747 |
+
|
| 748 |
+
char x alignas(int);
|
| 749 |
+
int &ir5 = *reinterpret_cast<int *>(&x); // undefined behavior: initializer refers to char object
|
| 750 |
+
```
|
| 751 |
+
|
| 752 |
+
— *end example*]
|
| 753 |
|
| 754 |
If a *typedef-name* [[dcl.typedef]], [[temp.param]] or a
|
| 755 |
*decltype-specifier* [[dcl.type.decltype]] denotes a type `TR` that is a
|
| 756 |
reference to a type `T`, an attempt to create the type “lvalue reference
|
| 757 |
to cv `TR`” creates the type “lvalue reference to `T`”, while an attempt
|
| 758 |
to create the type “rvalue reference to cv `TR`” creates the type `TR`.
|
| 759 |
|
| 760 |
[*Note 3*: This rule is known as reference collapsing. — *end note*]
|
| 761 |
|
| 762 |
+
[*Example 4*:
|
| 763 |
|
| 764 |
``` cpp
|
| 765 |
int i;
|
| 766 |
typedef int& LRI;
|
| 767 |
typedef int&& RRI;
|
|
|
|
| 792 |
|
| 793 |
``` bnf
|
| 794 |
nested-name-specifier '*' attribute-specifier-seqₒₚₜ cv-qualifier-seqₒₚₜ 'D1'
|
| 795 |
```
|
| 796 |
|
| 797 |
+
and the *nested-name-specifier* designates a class, and the type of the
|
| 798 |
contained *declarator-id* in the declaration `T` `D1` is
|
| 799 |
“*derived-declarator-type-list* `T`”, the type of the *declarator-id* in
|
| 800 |
`D` is “*derived-declarator-type-list* *cv-qualifier-seq* pointer to
|
| 801 |
member of class *nested-name-specifier* of type `T`”. The optional
|
| 802 |
*attribute-specifier-seq* [[dcl.attr.grammar]] appertains to the
|
| 803 |
+
pointer-to-member. The *nested-name-specifier* shall not designate an
|
| 804 |
+
anonymous union.
|
| 805 |
|
| 806 |
[*Example 1*:
|
| 807 |
|
| 808 |
``` cpp
|
| 809 |
struct X {
|
|
|
|
| 925 |
cases, the array bound is calculated from the number of initial elements
|
| 926 |
(say, `N`) supplied [[dcl.init.aggr]], and the type of the array is
|
| 927 |
“array of `N` `U`”.
|
| 928 |
|
| 929 |
Furthermore, if there is a reachable declaration of the entity that
|
| 930 |
+
specifies a bound and has the same host scope [[basic.scope.scope]], an
|
| 931 |
+
omitted array bound is taken to be the same as in that earlier
|
| 932 |
+
declaration, and similarly for the definition of a static data member of
|
| 933 |
+
a class.
|
| 934 |
|
| 935 |
[*Example 3*:
|
| 936 |
|
| 937 |
``` cpp
|
| 938 |
extern int x[10];
|
|
|
|
| 945 |
|
| 946 |
void f() {
|
| 947 |
extern int x[];
|
| 948 |
int i = sizeof(x); // error: incomplete object type
|
| 949 |
}
|
| 950 |
+
|
| 951 |
+
namespace A { extern int z[3]; }
|
| 952 |
+
int A::z[] = {}; // OK, defines an array of 3 elements
|
| 953 |
```
|
| 954 |
|
| 955 |
— *end example*]
|
| 956 |
|
| 957 |
[*Note 3*:
|
|
|
|
| 1000 |
[[over.sub]]. For the operator’s built-in meaning, see
|
| 1001 |
[[expr.sub]]. — *end note*]
|
| 1002 |
|
| 1003 |
#### Functions <a id="dcl.fct">[[dcl.fct]]</a>
|
| 1004 |
|
| 1005 |
+
In a declaration `T` `D` where `T` may be empty and `D` has the form
|
| 1006 |
|
| 1007 |
``` bnf
|
| 1008 |
'D1' '(' parameter-declaration-clause ')' cv-qualifier-seqₒₚₜ
|
| 1009 |
+
ref-qualifierₒₚₜ noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ trailing-return-typeₒₚₜ
|
| 1010 |
```
|
| 1011 |
|
| 1012 |
+
a *derived-declarator-type-list* is determined as follows:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1013 |
|
| 1014 |
+
- If the *unqualified-id* of the *declarator-id* is a
|
| 1015 |
+
*conversion-function-id*, the *derived-declarator-type-list* is empty.
|
| 1016 |
+
- Otherwise, the *derived-declarator-type-list* is as appears in the
|
| 1017 |
+
type “*derived-declarator-type-list* `T`” of the contained
|
| 1018 |
+
*declarator-id* in the declaration `T` `D1`.
|
| 1019 |
|
| 1020 |
+
The declared return type `U` of the function type is determined as
|
| 1021 |
+
follows:
|
| 1022 |
|
| 1023 |
+
- If the *trailing-return-type* is present, `T` shall be the single
|
| 1024 |
+
*type-specifier* `auto`, and `U` is the type specified by the
|
| 1025 |
+
*trailing-return-type*.
|
| 1026 |
+
- Otherwise, if the declaration declares a conversion function, see
|
| 1027 |
+
[[class.conv.fct]].
|
| 1028 |
+
- Otherwise, `U` is `T`.
|
| 1029 |
|
| 1030 |
+
The type of the *declarator-id* in `D` is
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1031 |
“*derived-declarator-type-list* `noexcept`ₒₚₜ function of
|
| 1032 |
parameter-type-list *cv-qualifier-seq*ₒₚₜ *ref-qualifier*ₒₚₜ returning
|
| 1033 |
`U`”, where
|
| 1034 |
|
| 1035 |
- the parameter-type-list is derived from the
|
| 1036 |
+
*parameter-declaration-clause* as described below and
|
|
|
|
| 1037 |
- the optional `noexcept` is present if and only if the exception
|
| 1038 |
+
specification [[except.spec]] is non-throwing.
|
| 1039 |
+
|
| 1040 |
+
Such a type is a *function type*.[^2]
|
| 1041 |
|
| 1042 |
The optional *attribute-specifier-seq* appertains to the function type.
|
| 1043 |
|
|
|
|
|
|
|
| 1044 |
``` bnf
|
| 1045 |
parameter-declaration-clause:
|
| 1046 |
+
'...'
|
| 1047 |
+
parameter-declaration-listₒₚₜ
|
| 1048 |
parameter-declaration-list ',' '...'
|
| 1049 |
+
parameter-declaration-list '...'
|
| 1050 |
```
|
| 1051 |
|
| 1052 |
``` bnf
|
| 1053 |
parameter-declaration-list:
|
| 1054 |
parameter-declaration
|
|
|
|
| 1072 |
[*Note 1*: The *parameter-declaration-clause* is used to convert the
|
| 1073 |
arguments specified on the function call; see
|
| 1074 |
[[expr.call]]. — *end note*]
|
| 1075 |
|
| 1076 |
If the *parameter-declaration-clause* is empty, the function takes no
|
| 1077 |
+
arguments. A parameter list consisting of a single unnamed non-object
|
| 1078 |
+
parameter of non-dependent type `void` is equivalent to an empty
|
| 1079 |
+
parameter list. Except for this special case, a parameter shall not have
|
| 1080 |
+
type cv `void`. A parameter with volatile-qualified type is deprecated;
|
| 1081 |
+
see [[depr.volatile.type]]. If the *parameter-declaration-clause*
|
| 1082 |
+
terminates with an ellipsis or a function parameter pack
|
| 1083 |
+
[[temp.variadic]], the number of arguments shall be equal to or greater
|
| 1084 |
+
than the number of parameters that do not have a default argument and
|
| 1085 |
+
are not function parameter packs. Where syntactically correct and where
|
| 1086 |
+
“`...`” is not part of an *abstract-declarator*, “`...`” is synonymous
|
| 1087 |
+
with “`, ...`”. A *parameter-declaration-clause* of the form
|
| 1088 |
+
*parameter-declaration-list* `...` is deprecated
|
| 1089 |
+
[[depr.ellipsis.comma]].
|
| 1090 |
|
| 1091 |
[*Example 1*:
|
| 1092 |
|
| 1093 |
The declaration
|
| 1094 |
|
|
|
|
| 1147 |
— *end example*]
|
| 1148 |
|
| 1149 |
An *explicit-object-parameter-declaration* is a *parameter-declaration*
|
| 1150 |
with a `this` specifier. An explicit-object-parameter-declaration shall
|
| 1151 |
appear only as the first *parameter-declaration* of a
|
| 1152 |
+
*parameter-declaration-list* of one of:
|
| 1153 |
|
| 1154 |
+
- a declaration of a member function or member function template
|
| 1155 |
+
[[class.mem]], or
|
| 1156 |
+
- an explicit instantiation [[temp.explicit]] or explicit specialization
|
| 1157 |
+
[[temp.expl.spec]] of a templated member function, or
|
| 1158 |
- a *lambda-declarator* [[expr.prim.lambda]].
|
| 1159 |
|
| 1160 |
A *member-declarator* with an explicit-object-parameter-declaration
|
| 1161 |
shall not include a *ref-qualifier* or a *cv-qualifier-seq* and shall
|
| 1162 |
not be declared `static` or `virtual`.
|
|
|
|
| 1199 |
|
| 1200 |
[*Note 4*: The non-object-parameter-type-list consists of the adjusted
|
| 1201 |
types of all the non-object parameters. — *end note*]
|
| 1202 |
|
| 1203 |
A function type with a *cv-qualifier-seq* or a *ref-qualifier*
|
| 1204 |
+
(including a type denoted by *typedef-name*
|
| 1205 |
[[dcl.typedef]], [[temp.param]]) shall appear only as:
|
| 1206 |
|
| 1207 |
- the function type for a non-static member function,
|
| 1208 |
- the function type to which a pointer to member refers,
|
| 1209 |
- the top-level function type of a function typedef declaration or
|
| 1210 |
*alias-declaration*,
|
| 1211 |
- the *type-id* in the default argument of a *type-parameter*
|
| 1212 |
+
[[temp.param]],
|
| 1213 |
- the *type-id* of a *template-argument* for a *type-parameter*
|
| 1214 |
+
[[temp.arg.type]], or
|
| 1215 |
+
- the operand of a *reflect-expression* [[expr.reflect]].
|
| 1216 |
|
| 1217 |
[*Example 4*:
|
| 1218 |
|
| 1219 |
``` cpp
|
| 1220 |
typedef int FIC(int) const;
|
| 1221 |
FIC f; // error: does not declare a member function
|
| 1222 |
struct S {
|
| 1223 |
FIC f; // OK
|
| 1224 |
};
|
| 1225 |
FIC S::*pm = &S::f; // OK
|
| 1226 |
+
constexpr std::meta::info yeti = ^^void(int) const &; // OK
|
| 1227 |
```
|
| 1228 |
|
| 1229 |
— *end example*]
|
| 1230 |
|
| 1231 |
The effect of a *cv-qualifier-seq* in a function declarator is not the
|
|
|
|
| 1372 |
[*Note 11*: A function template is not a function. — *end note*]
|
| 1373 |
|
| 1374 |
An *abbreviated function template* is a function declaration that has
|
| 1375 |
one or more generic parameter type placeholders [[dcl.spec.auto]]. An
|
| 1376 |
abbreviated function template is equivalent to a function template
|
| 1377 |
+
[[temp.fct]] whose *template-parameter-list* includes one invented
|
| 1378 |
+
*type-parameter* for each generic parameter type placeholder of the
|
| 1379 |
function declaration, in order of appearance. For a
|
| 1380 |
*placeholder-type-specifier* of the form `auto`, the invented parameter
|
| 1381 |
is an unconstrained *type-parameter*. For a *placeholder-type-specifier*
|
| 1382 |
of the form *type-constraint* `auto`, the invented parameter is a
|
| 1383 |
+
*type-parameter* with that *type-constraint*. The invented
|
| 1384 |
+
*type-parameter* declares a template parameter pack if the corresponding
|
| 1385 |
*parameter-declaration* declares a function parameter pack. If the
|
| 1386 |
placeholder contains `decltype(auto)`, the program is ill-formed. The
|
| 1387 |
adjusted function parameters of an abbreviated function template are
|
| 1388 |
derived from the *parameter-declaration-clause* by replacing each
|
| 1389 |
occurrence of a placeholder with the name of the corresponding invented
|
| 1390 |
+
*type-parameter*.
|
| 1391 |
|
| 1392 |
[*Example 9*:
|
| 1393 |
|
| 1394 |
``` cpp
|
| 1395 |
template<typename T> concept C1 = /* ... */;
|
|
|
|
| 1420 |
```
|
| 1421 |
|
| 1422 |
— *end example*]
|
| 1423 |
|
| 1424 |
An abbreviated function template can have a *template-head*. The
|
| 1425 |
+
invented *type-parameter*s are appended to the *template-parameter-list*
|
| 1426 |
+
after the explicitly declared *template-parameter*s.
|
|
|
|
| 1427 |
|
| 1428 |
[*Example 10*:
|
| 1429 |
|
| 1430 |
``` cpp
|
| 1431 |
template<typename> concept C = /* ... */;
|
|
|
|
| 1509 |
|
| 1510 |
— *end example*]
|
| 1511 |
|
| 1512 |
A default argument shall be specified only in the
|
| 1513 |
*parameter-declaration-clause* of a function declaration or
|
| 1514 |
+
*lambda-declarator* or in a *template-parameter* [[temp.param]]. A
|
| 1515 |
+
default argument shall not be specified for a template parameter pack or
|
| 1516 |
+
a function parameter pack. If it is specified in a
|
| 1517 |
+
*parameter-declaration-clause*, it shall not occur within a *declarator*
|
| 1518 |
+
or *abstract-declarator* of a *parameter-declaration*.[^4]
|
|
|
|
| 1519 |
|
| 1520 |
For non-template functions, default arguments can be added in later
|
| 1521 |
+
declarations of a function that have the same host scope. Declarations
|
| 1522 |
+
that have different host scopes have completely distinct sets of default
|
| 1523 |
arguments. That is, declarations in inner scopes do not acquire default
|
| 1524 |
arguments from declarations in outer scopes, and vice versa. In a given
|
| 1525 |
function declaration, each parameter subsequent to a parameter with a
|
| 1526 |
default argument shall have a default argument supplied in this or a
|
| 1527 |
previous declaration, unless the parameter was expanded from a parameter
|
|
|
|
| 1602 |
|
| 1603 |
[*Note 3*: A default argument is a complete-class context
|
| 1604 |
[[class.mem]]. Access checking applies to names in default arguments as
|
| 1605 |
described in [[class.access]]. — *end note*]
|
| 1606 |
|
| 1607 |
+
Except for member functions of templated classes, the default arguments
|
| 1608 |
+
in a member function definition that appears outside of the class
|
| 1609 |
definition are added to the set of default arguments provided by the
|
| 1610 |
member function declaration in the class definition; the program is
|
| 1611 |
ill-formed if a default constructor [[class.default.ctor]], copy or move
|
| 1612 |
constructor [[class.copy.ctor]], or copy or move assignment operator
|
| 1613 |
[[class.copy.assign]] is so declared. Default arguments for a member
|
| 1614 |
+
function of a templated class shall be specified on the initial
|
| 1615 |
+
declaration of the member function within the templated class.
|
| 1616 |
|
| 1617 |
[*Example 4*:
|
| 1618 |
|
| 1619 |
``` cpp
|
| 1620 |
class C {
|
|
|
|
| 1679 |
int h(int a, int b = sizeof(a)); // OK, unevaluated operand[term.unevaluated.operand]
|
| 1680 |
```
|
| 1681 |
|
| 1682 |
— *end example*]
|
| 1683 |
|
| 1684 |
+
A non-static member shall not be designated in a default argument unless
|
| 1685 |
+
|
| 1686 |
+
- it is designated by the *id-expression* or *splice-expression* of a
|
| 1687 |
+
class member access expression [[expr.ref]],
|
| 1688 |
+
- it is designated by an expression used to form a pointer to member
|
| 1689 |
+
[[expr.unary.op]], or
|
| 1690 |
+
- it appears as the operand of a *reflect-expression* [[expr.reflect]].
|
| 1691 |
|
| 1692 |
[*Example 8*:
|
| 1693 |
|
| 1694 |
The declaration of `X::mem1()` in the following example is ill-formed
|
| 1695 |
because no object is supplied for the non-static member `X::a` used as
|
|
|
|
| 1698 |
``` cpp
|
| 1699 |
int b;
|
| 1700 |
class X {
|
| 1701 |
int a;
|
| 1702 |
int mem1(int i = a); // error: non-static member a used as default argument
|
| 1703 |
+
int mem2(int i = b); // OK, use X::b
|
| 1704 |
+
consteval void mem3(std::meta::info r = ^^a) {} // OK
|
| 1705 |
+
int mem4(int i = [:^^a:]); // error: non-static member a designated in default argument
|
| 1706 |
static int b;
|
| 1707 |
};
|
| 1708 |
```
|
| 1709 |
|
| 1710 |
The declaration of `X::mem2()` is meaningful, however, since no object
|
|
|
|
| 1729 |
int (*p2)() = &f; // error: type mismatch
|
| 1730 |
```
|
| 1731 |
|
| 1732 |
— *end example*]
|
| 1733 |
|
| 1734 |
+
[*Note 7*: When an overload set contains a declaration of a function
|
| 1735 |
+
whose host scope is S, any default argument associated with any
|
| 1736 |
+
reachable declaration whose host scope is S is available to the call
|
| 1737 |
+
[[over.match.viable]]. — *end note*]
|
| 1738 |
|
| 1739 |
+
[*Note 8*: The candidate might have been found through a
|
| 1740 |
*using-declarator* from which the declaration that provides the default
|
| 1741 |
argument is not reachable. — *end note*]
|
| 1742 |
|
| 1743 |
A virtual function call [[class.virtual]] uses the default arguments in
|
| 1744 |
the declaration of the virtual function determined by the static type of
|