- tmp/tmplf5w5u91/{from.md → to.md} +132 -92
tmp/tmplf5w5u91/{from.md → to.md}
RENAMED
|
@@ -157,11 +157,11 @@ the type specifiers `int` `unsigned` determine the type “`unsigned int`”
|
|
| 157 |
[[dcl.type.simple]].
|
| 158 |
|
| 159 |
— *end example*]
|
| 160 |
|
| 161 |
In a declaration *attribute-specifier-seq*ₒₚₜ `T` `D` where `D` is an
|
| 162 |
-
unadorned
|
| 163 |
|
| 164 |
In a declaration `T` `D` where `D` has the form
|
| 165 |
|
| 166 |
``` bnf
|
| 167 |
'(' 'D1' ')'
|
|
@@ -238,13 +238,13 @@ cv-unqualified pointer later, for example:
|
|
| 238 |
``` cpp
|
| 239 |
*ppc = &ci; // OK, but would make p point to ci because of previous error
|
| 240 |
*p = 5; // clobber ci
|
| 241 |
```
|
| 242 |
|
| 243 |
-
|
| 244 |
|
| 245 |
-
|
| 246 |
|
| 247 |
[*Note 1*: Forming a pointer to reference type is ill-formed; see
|
| 248 |
[[dcl.ref]]. Forming a function pointer type is ill-formed if the
|
| 249 |
function type has *cv-qualifier*s or a *ref-qualifier*; see
|
| 250 |
[[dcl.fct]]. Since the address of a bit-field [[class.bit]] cannot be
|
|
@@ -281,12 +281,11 @@ to `const int`”.
|
|
| 281 |
— *end example*]
|
| 282 |
|
| 283 |
[*Note 1*: A reference can be thought of as a name of an
|
| 284 |
object. — *end note*]
|
| 285 |
|
| 286 |
-
|
| 287 |
-
ill-formed.
|
| 288 |
|
| 289 |
A reference type that is declared using `&` is called an *lvalue
|
| 290 |
reference*, and a reference type that is declared using `&&` is called
|
| 291 |
an *rvalue reference*. Lvalue references and rvalue references are
|
| 292 |
distinct types. Except where explicitly noted, they are semantically
|
|
@@ -347,29 +346,57 @@ There shall be no references to references, no arrays of references, and
|
|
| 347 |
no pointers to references. The declaration of a reference shall contain
|
| 348 |
an *initializer* [[dcl.init.ref]] except when the declaration contains
|
| 349 |
an explicit `extern` specifier [[dcl.stc]], is a class member
|
| 350 |
[[class.mem]] declaration within a class definition, or is the
|
| 351 |
declaration of a parameter or a return type [[dcl.fct]]; see
|
| 352 |
-
[[basic.def]].
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
[[
|
| 360 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
|
| 362 |
If a *typedef-name* [[dcl.typedef]], [[temp.param]] or a
|
| 363 |
*decltype-specifier* [[dcl.type.decltype]] denotes a type `TR` that is a
|
| 364 |
reference to a type `T`, an attempt to create the type “lvalue reference
|
| 365 |
to cv `TR`” creates the type “lvalue reference to `T`”, while an attempt
|
| 366 |
to create the type “rvalue reference to cv `TR`” creates the type `TR`.
|
| 367 |
|
| 368 |
[*Note 3*: This rule is known as reference collapsing. — *end note*]
|
| 369 |
|
| 370 |
-
[*Example
|
| 371 |
|
| 372 |
``` cpp
|
| 373 |
int i;
|
| 374 |
typedef int& LRI;
|
| 375 |
typedef int&& RRI;
|
|
@@ -400,17 +427,18 @@ In a declaration `T` `D` where `D` has the form
|
|
| 400 |
|
| 401 |
``` bnf
|
| 402 |
nested-name-specifier '*' attribute-specifier-seqₒₚₜ cv-qualifier-seqₒₚₜ 'D1'
|
| 403 |
```
|
| 404 |
|
| 405 |
-
and the *nested-name-specifier*
|
| 406 |
contained *declarator-id* in the declaration `T` `D1` is
|
| 407 |
“*derived-declarator-type-list* `T`”, the type of the *declarator-id* in
|
| 408 |
`D` is “*derived-declarator-type-list* *cv-qualifier-seq* pointer to
|
| 409 |
member of class *nested-name-specifier* of type `T`”. The optional
|
| 410 |
*attribute-specifier-seq* [[dcl.attr.grammar]] appertains to the
|
| 411 |
-
pointer-to-member.
|
|
|
|
| 412 |
|
| 413 |
[*Example 1*:
|
| 414 |
|
| 415 |
``` cpp
|
| 416 |
struct X {
|
|
@@ -532,13 +560,14 @@ initialized and the declarator is followed by an initializer
|
|
| 532 |
cases, the array bound is calculated from the number of initial elements
|
| 533 |
(say, `N`) supplied [[dcl.init.aggr]], and the type of the array is
|
| 534 |
“array of `N` `U`”.
|
| 535 |
|
| 536 |
Furthermore, if there is a reachable declaration of the entity that
|
| 537 |
-
|
| 538 |
-
array bound is taken to be the same as in that earlier
|
| 539 |
-
similarly for the definition of a static data member of
|
|
|
|
| 540 |
|
| 541 |
[*Example 3*:
|
| 542 |
|
| 543 |
``` cpp
|
| 544 |
extern int x[10];
|
|
@@ -551,10 +580,13 @@ int S::y[]; // OK, bound is 10
|
|
| 551 |
|
| 552 |
void f() {
|
| 553 |
extern int x[];
|
| 554 |
int i = sizeof(x); // error: incomplete object type
|
| 555 |
}
|
|
|
|
|
|
|
|
|
|
| 556 |
```
|
| 557 |
|
| 558 |
— *end example*]
|
| 559 |
|
| 560 |
[*Note 3*:
|
|
@@ -603,58 +635,55 @@ described in [[conv.array]]. — *end note*]
|
|
| 603 |
[[over.sub]]. For the operator’s built-in meaning, see
|
| 604 |
[[expr.sub]]. — *end note*]
|
| 605 |
|
| 606 |
#### Functions <a id="dcl.fct">[[dcl.fct]]</a>
|
| 607 |
|
| 608 |
-
In a declaration `T` `D` where `D` has the form
|
| 609 |
|
| 610 |
``` bnf
|
| 611 |
'D1' '(' parameter-declaration-clause ')' cv-qualifier-seqₒₚₜ
|
| 612 |
-
ref-qualifierₒₚₜ noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ
|
| 613 |
```
|
| 614 |
|
| 615 |
-
|
| 616 |
-
`D1` is “*derived-declarator-type-list* `T`”, the type of the
|
| 617 |
-
*declarator-id* in `D` is “*derived-declarator-type-list* `noexcept`ₒₚₜ
|
| 618 |
-
function of parameter-type-list *cv-qualifier-seq*ₒₚₜ
|
| 619 |
-
*ref-qualifier*ₒₚₜ returning `T`”, where
|
| 620 |
|
| 621 |
-
- the
|
| 622 |
-
*
|
| 623 |
-
- the
|
| 624 |
-
|
|
|
|
| 625 |
|
| 626 |
-
The
|
|
|
|
| 627 |
|
| 628 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 629 |
|
| 630 |
-
``
|
| 631 |
-
'D1' '(' parameter-declaration-clause ')' cv-qualifier-seqₒₚₜ
|
| 632 |
-
ref-qualifierₒₚₜ noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ trailing-return-type
|
| 633 |
-
```
|
| 634 |
-
|
| 635 |
-
and the type of the contained *declarator-id* in the declaration `T`
|
| 636 |
-
`D1` is “*derived-declarator-type-list* `T`”, `T` shall be the single
|
| 637 |
-
*type-specifier* `auto`. The type of the *declarator-id* in `D` is
|
| 638 |
“*derived-declarator-type-list* `noexcept`ₒₚₜ function of
|
| 639 |
parameter-type-list *cv-qualifier-seq*ₒₚₜ *ref-qualifier*ₒₚₜ returning
|
| 640 |
`U`”, where
|
| 641 |
|
| 642 |
- the parameter-type-list is derived from the
|
| 643 |
-
*parameter-declaration-clause* as described below
|
| 644 |
-
- `U` is the type specified by the *trailing-return-type*, and
|
| 645 |
- the optional `noexcept` is present if and only if the exception
|
| 646 |
-
specification is non-throwing.
|
|
|
|
|
|
|
| 647 |
|
| 648 |
The optional *attribute-specifier-seq* appertains to the function type.
|
| 649 |
|
| 650 |
-
A type of either form is a *function type*.[^2]
|
| 651 |
-
|
| 652 |
``` bnf
|
| 653 |
parameter-declaration-clause:
|
| 654 |
-
|
|
|
|
| 655 |
parameter-declaration-list ',' '...'
|
|
|
|
| 656 |
```
|
| 657 |
|
| 658 |
``` bnf
|
| 659 |
parameter-declaration-list:
|
| 660 |
parameter-declaration
|
|
@@ -678,20 +707,23 @@ specified, and their processing, when the function is called.
|
|
| 678 |
[*Note 1*: The *parameter-declaration-clause* is used to convert the
|
| 679 |
arguments specified on the function call; see
|
| 680 |
[[expr.call]]. — *end note*]
|
| 681 |
|
| 682 |
If the *parameter-declaration-clause* is empty, the function takes no
|
| 683 |
-
arguments. A parameter list consisting of a single unnamed
|
| 684 |
-
non-dependent type `void` is equivalent to an empty
|
| 685 |
-
Except for this special case, a parameter shall not have
|
| 686 |
-
A parameter with volatile-qualified type is deprecated;
|
| 687 |
-
[[depr.volatile.type]]. If the *parameter-declaration-clause*
|
| 688 |
-
with an ellipsis or a function parameter pack
|
| 689 |
-
number of arguments shall be equal to or greater
|
| 690 |
-
parameters that do not have a default argument and
|
| 691 |
-
parameter packs. Where syntactically correct and where
|
| 692 |
-
part of an *abstract-declarator*, “`
|
|
|
|
|
|
|
|
|
|
| 693 |
|
| 694 |
[*Example 1*:
|
| 695 |
|
| 696 |
The declaration
|
| 697 |
|
|
@@ -750,14 +782,16 @@ void h(int (*)(int)) {} // defines #3
|
|
| 750 |
— *end example*]
|
| 751 |
|
| 752 |
An *explicit-object-parameter-declaration* is a *parameter-declaration*
|
| 753 |
with a `this` specifier. An explicit-object-parameter-declaration shall
|
| 754 |
appear only as the first *parameter-declaration* of a
|
| 755 |
-
*parameter-declaration-list* of
|
| 756 |
|
| 757 |
-
- a
|
| 758 |
-
or
|
|
|
|
|
|
|
| 759 |
- a *lambda-declarator* [[expr.prim.lambda]].
|
| 760 |
|
| 761 |
A *member-declarator* with an explicit-object-parameter-declaration
|
| 762 |
shall not include a *ref-qualifier* or a *cv-qualifier-seq* and shall
|
| 763 |
not be declared `static` or `virtual`.
|
|
@@ -800,31 +834,33 @@ explicit object parameter, if any, omitted.
|
|
| 800 |
|
| 801 |
[*Note 4*: The non-object-parameter-type-list consists of the adjusted
|
| 802 |
types of all the non-object parameters. — *end note*]
|
| 803 |
|
| 804 |
A function type with a *cv-qualifier-seq* or a *ref-qualifier*
|
| 805 |
-
(including a type
|
| 806 |
[[dcl.typedef]], [[temp.param]]) shall appear only as:
|
| 807 |
|
| 808 |
- the function type for a non-static member function,
|
| 809 |
- the function type to which a pointer to member refers,
|
| 810 |
- the top-level function type of a function typedef declaration or
|
| 811 |
*alias-declaration*,
|
| 812 |
- the *type-id* in the default argument of a *type-parameter*
|
| 813 |
-
[[temp.param]],
|
| 814 |
- the *type-id* of a *template-argument* for a *type-parameter*
|
| 815 |
-
[[temp.arg.type]]
|
|
|
|
| 816 |
|
| 817 |
[*Example 4*:
|
| 818 |
|
| 819 |
``` cpp
|
| 820 |
typedef int FIC(int) const;
|
| 821 |
FIC f; // error: does not declare a member function
|
| 822 |
struct S {
|
| 823 |
FIC f; // OK
|
| 824 |
};
|
| 825 |
FIC S::*pm = &S::f; // OK
|
|
|
|
| 826 |
```
|
| 827 |
|
| 828 |
— *end example*]
|
| 829 |
|
| 830 |
The effect of a *cv-qualifier-seq* in a function declarator is not the
|
|
@@ -971,24 +1007,24 @@ specialization.
|
|
| 971 |
[*Note 11*: A function template is not a function. — *end note*]
|
| 972 |
|
| 973 |
An *abbreviated function template* is a function declaration that has
|
| 974 |
one or more generic parameter type placeholders [[dcl.spec.auto]]. An
|
| 975 |
abbreviated function template is equivalent to a function template
|
| 976 |
-
[[temp.fct]] whose *template-parameter-list* includes one invented
|
| 977 |
-
*
|
| 978 |
function declaration, in order of appearance. For a
|
| 979 |
*placeholder-type-specifier* of the form `auto`, the invented parameter
|
| 980 |
is an unconstrained *type-parameter*. For a *placeholder-type-specifier*
|
| 981 |
of the form *type-constraint* `auto`, the invented parameter is a
|
| 982 |
-
*type-parameter* with that *type-constraint*. The invented
|
| 983 |
-
*
|
| 984 |
*parameter-declaration* declares a function parameter pack. If the
|
| 985 |
placeholder contains `decltype(auto)`, the program is ill-formed. The
|
| 986 |
adjusted function parameters of an abbreviated function template are
|
| 987 |
derived from the *parameter-declaration-clause* by replacing each
|
| 988 |
occurrence of a placeholder with the name of the corresponding invented
|
| 989 |
-
*
|
| 990 |
|
| 991 |
[*Example 9*:
|
| 992 |
|
| 993 |
``` cpp
|
| 994 |
template<typename T> concept C1 = /* ... */;
|
|
@@ -1019,13 +1055,12 @@ template<> void g1<int>(const int*, const double&); // OK, specialization of g1<
|
|
| 1019 |
```
|
| 1020 |
|
| 1021 |
— *end example*]
|
| 1022 |
|
| 1023 |
An abbreviated function template can have a *template-head*. The
|
| 1024 |
-
invented *
|
| 1025 |
-
|
| 1026 |
-
*template-parameter*s.
|
| 1027 |
|
| 1028 |
[*Example 10*:
|
| 1029 |
|
| 1030 |
``` cpp
|
| 1031 |
template<typename> concept C = /* ... */;
|
|
@@ -1109,20 +1144,19 @@ respectively.
|
|
| 1109 |
|
| 1110 |
— *end example*]
|
| 1111 |
|
| 1112 |
A default argument shall be specified only in the
|
| 1113 |
*parameter-declaration-clause* of a function declaration or
|
| 1114 |
-
*lambda-declarator* or in a *template-parameter* [[temp.param]]
|
| 1115 |
-
|
| 1116 |
-
|
| 1117 |
-
|
| 1118 |
-
|
| 1119 |
-
*declarator* or *abstract-declarator* of a *parameter-declaration*.[^4]
|
| 1120 |
|
| 1121 |
For non-template functions, default arguments can be added in later
|
| 1122 |
-
declarations of a function that
|
| 1123 |
-
that
|
| 1124 |
arguments. That is, declarations in inner scopes do not acquire default
|
| 1125 |
arguments from declarations in outer scopes, and vice versa. In a given
|
| 1126 |
function declaration, each parameter subsequent to a parameter with a
|
| 1127 |
default argument shall have a default argument supplied in this or a
|
| 1128 |
previous declaration, unless the parameter was expanded from a parameter
|
|
@@ -1203,19 +1237,19 @@ void h() {
|
|
| 1203 |
|
| 1204 |
[*Note 3*: A default argument is a complete-class context
|
| 1205 |
[[class.mem]]. Access checking applies to names in default arguments as
|
| 1206 |
described in [[class.access]]. — *end note*]
|
| 1207 |
|
| 1208 |
-
Except for member functions of
|
| 1209 |
-
a member function definition that appears outside of the class
|
| 1210 |
definition are added to the set of default arguments provided by the
|
| 1211 |
member function declaration in the class definition; the program is
|
| 1212 |
ill-formed if a default constructor [[class.default.ctor]], copy or move
|
| 1213 |
constructor [[class.copy.ctor]], or copy or move assignment operator
|
| 1214 |
[[class.copy.assign]] is so declared. Default arguments for a member
|
| 1215 |
-
function of a class
|
| 1216 |
-
declaration of the member function within the
|
| 1217 |
|
| 1218 |
[*Example 4*:
|
| 1219 |
|
| 1220 |
``` cpp
|
| 1221 |
class C {
|
|
@@ -1280,14 +1314,17 @@ int g(float I, int b = I(2)); // error: parameter I found
|
|
| 1280 |
int h(int a, int b = sizeof(a)); // OK, unevaluated operand[term.unevaluated.operand]
|
| 1281 |
```
|
| 1282 |
|
| 1283 |
— *end example*]
|
| 1284 |
|
| 1285 |
-
A non-static member shall not
|
| 1286 |
-
|
| 1287 |
-
|
| 1288 |
-
[[expr.
|
|
|
|
|
|
|
|
|
|
| 1289 |
|
| 1290 |
[*Example 8*:
|
| 1291 |
|
| 1292 |
The declaration of `X::mem1()` in the following example is ill-formed
|
| 1293 |
because no object is supplied for the non-static member `X::a` used as
|
|
@@ -1296,11 +1333,13 @@ an initializer.
|
|
| 1296 |
``` cpp
|
| 1297 |
int b;
|
| 1298 |
class X {
|
| 1299 |
int a;
|
| 1300 |
int mem1(int i = a); // error: non-static member a used as default argument
|
| 1301 |
-
int mem2(int i = b);
|
|
|
|
|
|
|
| 1302 |
static int b;
|
| 1303 |
};
|
| 1304 |
```
|
| 1305 |
|
| 1306 |
The declaration of `X::mem2()` is meaningful, however, since no object
|
|
@@ -1325,15 +1364,16 @@ int (*p1)(int) = &f;
|
|
| 1325 |
int (*p2)() = &f; // error: type mismatch
|
| 1326 |
```
|
| 1327 |
|
| 1328 |
— *end example*]
|
| 1329 |
|
| 1330 |
-
When an overload set contains a declaration of a function
|
| 1331 |
-
|
| 1332 |
-
declaration
|
|
|
|
| 1333 |
|
| 1334 |
-
[*Note
|
| 1335 |
*using-declarator* from which the declaration that provides the default
|
| 1336 |
argument is not reachable. — *end note*]
|
| 1337 |
|
| 1338 |
A virtual function call [[class.virtual]] uses the default arguments in
|
| 1339 |
the declaration of the virtual function determined by the static type of
|
|
|
|
| 157 |
[[dcl.type.simple]].
|
| 158 |
|
| 159 |
— *end example*]
|
| 160 |
|
| 161 |
In a declaration *attribute-specifier-seq*ₒₚₜ `T` `D` where `D` is an
|
| 162 |
+
unadorned *declarator-id*, the type of the declared entity is “`T`”.
|
| 163 |
|
| 164 |
In a declaration `T` `D` where `D` has the form
|
| 165 |
|
| 166 |
``` bnf
|
| 167 |
'(' 'D1' ')'
|
|
|
|
| 238 |
``` cpp
|
| 239 |
*ppc = &ci; // OK, but would make p point to ci because of previous error
|
| 240 |
*p = 5; // clobber ci
|
| 241 |
```
|
| 242 |
|
| 243 |
+
See also [[expr.assign]] and [[dcl.init]].
|
| 244 |
|
| 245 |
+
— *end example*]
|
| 246 |
|
| 247 |
[*Note 1*: Forming a pointer to reference type is ill-formed; see
|
| 248 |
[[dcl.ref]]. Forming a function pointer type is ill-formed if the
|
| 249 |
function type has *cv-qualifier*s or a *ref-qualifier*; see
|
| 250 |
[[dcl.fct]]. Since the address of a bit-field [[class.bit]] cannot be
|
|
|
|
| 281 |
— *end example*]
|
| 282 |
|
| 283 |
[*Note 1*: A reference can be thought of as a name of an
|
| 284 |
object. — *end note*]
|
| 285 |
|
| 286 |
+
Forming the type “reference to cv `void`” is ill-formed.
|
|
|
|
| 287 |
|
| 288 |
A reference type that is declared using `&` is called an *lvalue
|
| 289 |
reference*, and a reference type that is declared using `&&` is called
|
| 290 |
an *rvalue reference*. Lvalue references and rvalue references are
|
| 291 |
distinct types. Except where explicitly noted, they are semantically
|
|
|
|
| 346 |
no pointers to references. The declaration of a reference shall contain
|
| 347 |
an *initializer* [[dcl.init.ref]] except when the declaration contains
|
| 348 |
an explicit `extern` specifier [[dcl.stc]], is a class member
|
| 349 |
[[class.mem]] declaration within a class definition, or is the
|
| 350 |
declaration of a parameter or a return type [[dcl.fct]]; see
|
| 351 |
+
[[basic.def]].
|
| 352 |
+
|
| 353 |
+
Attempting to bind a reference to a function where the converted
|
| 354 |
+
initializer is a glvalue whose type is not call-compatible [[expr.call]]
|
| 355 |
+
with the type of the function’s definition results in undefined
|
| 356 |
+
behavior. Attempting to bind a reference to an object where the
|
| 357 |
+
converted initializer is a glvalue through which the object is not
|
| 358 |
+
type-accessible [[basic.lval]] results in undefined behavior.
|
| 359 |
+
|
| 360 |
+
[*Note 2*: The object designated by such a glvalue can be outside its
|
| 361 |
+
lifetime [[basic.life]]. Because a null pointer value or a pointer past
|
| 362 |
+
the end of an object does not point to an object, a reference in a
|
| 363 |
+
well-defined program cannot refer to such things; see
|
| 364 |
+
[[expr.unary.op]]. As described in [[class.bit]], a reference cannot be
|
| 365 |
+
bound directly to a bit-field. — *end note*]
|
| 366 |
+
|
| 367 |
+
The behavior of an evaluation of a reference
|
| 368 |
+
[[expr.prim.id]], [[expr.ref]] that does not happen after
|
| 369 |
+
[[intro.races]] the initialization of the reference is undefined.
|
| 370 |
+
|
| 371 |
+
[*Example 3*:
|
| 372 |
+
|
| 373 |
+
``` cpp
|
| 374 |
+
int &f(int&);
|
| 375 |
+
int &g();
|
| 376 |
+
extern int &ir3;
|
| 377 |
+
int *ip = 0;
|
| 378 |
+
int &ir1 = *ip; // undefined behavior: null pointer
|
| 379 |
+
int &ir2 = f(ir3); // undefined behavior: ir3 not yet initialized
|
| 380 |
+
int &ir3 = g();
|
| 381 |
+
int &ir4 = f(ir4); // undefined behavior: ir4 used in its own initializer
|
| 382 |
+
|
| 383 |
+
char x alignas(int);
|
| 384 |
+
int &ir5 = *reinterpret_cast<int *>(&x); // undefined behavior: initializer refers to char object
|
| 385 |
+
```
|
| 386 |
+
|
| 387 |
+
— *end example*]
|
| 388 |
|
| 389 |
If a *typedef-name* [[dcl.typedef]], [[temp.param]] or a
|
| 390 |
*decltype-specifier* [[dcl.type.decltype]] denotes a type `TR` that is a
|
| 391 |
reference to a type `T`, an attempt to create the type “lvalue reference
|
| 392 |
to cv `TR`” creates the type “lvalue reference to `T`”, while an attempt
|
| 393 |
to create the type “rvalue reference to cv `TR`” creates the type `TR`.
|
| 394 |
|
| 395 |
[*Note 3*: This rule is known as reference collapsing. — *end note*]
|
| 396 |
|
| 397 |
+
[*Example 4*:
|
| 398 |
|
| 399 |
``` cpp
|
| 400 |
int i;
|
| 401 |
typedef int& LRI;
|
| 402 |
typedef int&& RRI;
|
|
|
|
| 427 |
|
| 428 |
``` bnf
|
| 429 |
nested-name-specifier '*' attribute-specifier-seqₒₚₜ cv-qualifier-seqₒₚₜ 'D1'
|
| 430 |
```
|
| 431 |
|
| 432 |
+
and the *nested-name-specifier* designates a class, and the type of the
|
| 433 |
contained *declarator-id* in the declaration `T` `D1` is
|
| 434 |
“*derived-declarator-type-list* `T`”, the type of the *declarator-id* in
|
| 435 |
`D` is “*derived-declarator-type-list* *cv-qualifier-seq* pointer to
|
| 436 |
member of class *nested-name-specifier* of type `T`”. The optional
|
| 437 |
*attribute-specifier-seq* [[dcl.attr.grammar]] appertains to the
|
| 438 |
+
pointer-to-member. The *nested-name-specifier* shall not designate an
|
| 439 |
+
anonymous union.
|
| 440 |
|
| 441 |
[*Example 1*:
|
| 442 |
|
| 443 |
``` cpp
|
| 444 |
struct X {
|
|
|
|
| 560 |
cases, the array bound is calculated from the number of initial elements
|
| 561 |
(say, `N`) supplied [[dcl.init.aggr]], and the type of the array is
|
| 562 |
“array of `N` `U`”.
|
| 563 |
|
| 564 |
Furthermore, if there is a reachable declaration of the entity that
|
| 565 |
+
specifies a bound and has the same host scope [[basic.scope.scope]], an
|
| 566 |
+
omitted array bound is taken to be the same as in that earlier
|
| 567 |
+
declaration, and similarly for the definition of a static data member of
|
| 568 |
+
a class.
|
| 569 |
|
| 570 |
[*Example 3*:
|
| 571 |
|
| 572 |
``` cpp
|
| 573 |
extern int x[10];
|
|
|
|
| 580 |
|
| 581 |
void f() {
|
| 582 |
extern int x[];
|
| 583 |
int i = sizeof(x); // error: incomplete object type
|
| 584 |
}
|
| 585 |
+
|
| 586 |
+
namespace A { extern int z[3]; }
|
| 587 |
+
int A::z[] = {}; // OK, defines an array of 3 elements
|
| 588 |
```
|
| 589 |
|
| 590 |
— *end example*]
|
| 591 |
|
| 592 |
[*Note 3*:
|
|
|
|
| 635 |
[[over.sub]]. For the operator’s built-in meaning, see
|
| 636 |
[[expr.sub]]. — *end note*]
|
| 637 |
|
| 638 |
#### Functions <a id="dcl.fct">[[dcl.fct]]</a>
|
| 639 |
|
| 640 |
+
In a declaration `T` `D` where `T` may be empty and `D` has the form
|
| 641 |
|
| 642 |
``` bnf
|
| 643 |
'D1' '(' parameter-declaration-clause ')' cv-qualifier-seqₒₚₜ
|
| 644 |
+
ref-qualifierₒₚₜ noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ trailing-return-typeₒₚₜ
|
| 645 |
```
|
| 646 |
|
| 647 |
+
a *derived-declarator-type-list* is determined as follows:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 648 |
|
| 649 |
+
- If the *unqualified-id* of the *declarator-id* is a
|
| 650 |
+
*conversion-function-id*, the *derived-declarator-type-list* is empty.
|
| 651 |
+
- Otherwise, the *derived-declarator-type-list* is as appears in the
|
| 652 |
+
type “*derived-declarator-type-list* `T`” of the contained
|
| 653 |
+
*declarator-id* in the declaration `T` `D1`.
|
| 654 |
|
| 655 |
+
The declared return type `U` of the function type is determined as
|
| 656 |
+
follows:
|
| 657 |
|
| 658 |
+
- If the *trailing-return-type* is present, `T` shall be the single
|
| 659 |
+
*type-specifier* `auto`, and `U` is the type specified by the
|
| 660 |
+
*trailing-return-type*.
|
| 661 |
+
- Otherwise, if the declaration declares a conversion function, see
|
| 662 |
+
[[class.conv.fct]].
|
| 663 |
+
- Otherwise, `U` is `T`.
|
| 664 |
|
| 665 |
+
The type of the *declarator-id* in `D` is
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 666 |
“*derived-declarator-type-list* `noexcept`ₒₚₜ function of
|
| 667 |
parameter-type-list *cv-qualifier-seq*ₒₚₜ *ref-qualifier*ₒₚₜ returning
|
| 668 |
`U`”, where
|
| 669 |
|
| 670 |
- the parameter-type-list is derived from the
|
| 671 |
+
*parameter-declaration-clause* as described below and
|
|
|
|
| 672 |
- the optional `noexcept` is present if and only if the exception
|
| 673 |
+
specification [[except.spec]] is non-throwing.
|
| 674 |
+
|
| 675 |
+
Such a type is a *function type*.[^2]
|
| 676 |
|
| 677 |
The optional *attribute-specifier-seq* appertains to the function type.
|
| 678 |
|
|
|
|
|
|
|
| 679 |
``` bnf
|
| 680 |
parameter-declaration-clause:
|
| 681 |
+
'...'
|
| 682 |
+
parameter-declaration-listₒₚₜ
|
| 683 |
parameter-declaration-list ',' '...'
|
| 684 |
+
parameter-declaration-list '...'
|
| 685 |
```
|
| 686 |
|
| 687 |
``` bnf
|
| 688 |
parameter-declaration-list:
|
| 689 |
parameter-declaration
|
|
|
|
| 707 |
[*Note 1*: The *parameter-declaration-clause* is used to convert the
|
| 708 |
arguments specified on the function call; see
|
| 709 |
[[expr.call]]. — *end note*]
|
| 710 |
|
| 711 |
If the *parameter-declaration-clause* is empty, the function takes no
|
| 712 |
+
arguments. A parameter list consisting of a single unnamed non-object
|
| 713 |
+
parameter of non-dependent type `void` is equivalent to an empty
|
| 714 |
+
parameter list. Except for this special case, a parameter shall not have
|
| 715 |
+
type cv `void`. A parameter with volatile-qualified type is deprecated;
|
| 716 |
+
see [[depr.volatile.type]]. If the *parameter-declaration-clause*
|
| 717 |
+
terminates with an ellipsis or a function parameter pack
|
| 718 |
+
[[temp.variadic]], the number of arguments shall be equal to or greater
|
| 719 |
+
than the number of parameters that do not have a default argument and
|
| 720 |
+
are not function parameter packs. Where syntactically correct and where
|
| 721 |
+
“`...`” is not part of an *abstract-declarator*, “`...`” is synonymous
|
| 722 |
+
with “`, ...`”. A *parameter-declaration-clause* of the form
|
| 723 |
+
*parameter-declaration-list* `...` is deprecated
|
| 724 |
+
[[depr.ellipsis.comma]].
|
| 725 |
|
| 726 |
[*Example 1*:
|
| 727 |
|
| 728 |
The declaration
|
| 729 |
|
|
|
|
| 782 |
— *end example*]
|
| 783 |
|
| 784 |
An *explicit-object-parameter-declaration* is a *parameter-declaration*
|
| 785 |
with a `this` specifier. An explicit-object-parameter-declaration shall
|
| 786 |
appear only as the first *parameter-declaration* of a
|
| 787 |
+
*parameter-declaration-list* of one of:
|
| 788 |
|
| 789 |
+
- a declaration of a member function or member function template
|
| 790 |
+
[[class.mem]], or
|
| 791 |
+
- an explicit instantiation [[temp.explicit]] or explicit specialization
|
| 792 |
+
[[temp.expl.spec]] of a templated member function, or
|
| 793 |
- a *lambda-declarator* [[expr.prim.lambda]].
|
| 794 |
|
| 795 |
A *member-declarator* with an explicit-object-parameter-declaration
|
| 796 |
shall not include a *ref-qualifier* or a *cv-qualifier-seq* and shall
|
| 797 |
not be declared `static` or `virtual`.
|
|
|
|
| 834 |
|
| 835 |
[*Note 4*: The non-object-parameter-type-list consists of the adjusted
|
| 836 |
types of all the non-object parameters. — *end note*]
|
| 837 |
|
| 838 |
A function type with a *cv-qualifier-seq* or a *ref-qualifier*
|
| 839 |
+
(including a type denoted by *typedef-name*
|
| 840 |
[[dcl.typedef]], [[temp.param]]) shall appear only as:
|
| 841 |
|
| 842 |
- the function type for a non-static member function,
|
| 843 |
- the function type to which a pointer to member refers,
|
| 844 |
- the top-level function type of a function typedef declaration or
|
| 845 |
*alias-declaration*,
|
| 846 |
- the *type-id* in the default argument of a *type-parameter*
|
| 847 |
+
[[temp.param]],
|
| 848 |
- the *type-id* of a *template-argument* for a *type-parameter*
|
| 849 |
+
[[temp.arg.type]], or
|
| 850 |
+
- the operand of a *reflect-expression* [[expr.reflect]].
|
| 851 |
|
| 852 |
[*Example 4*:
|
| 853 |
|
| 854 |
``` cpp
|
| 855 |
typedef int FIC(int) const;
|
| 856 |
FIC f; // error: does not declare a member function
|
| 857 |
struct S {
|
| 858 |
FIC f; // OK
|
| 859 |
};
|
| 860 |
FIC S::*pm = &S::f; // OK
|
| 861 |
+
constexpr std::meta::info yeti = ^^void(int) const &; // OK
|
| 862 |
```
|
| 863 |
|
| 864 |
— *end example*]
|
| 865 |
|
| 866 |
The effect of a *cv-qualifier-seq* in a function declarator is not the
|
|
|
|
| 1007 |
[*Note 11*: A function template is not a function. — *end note*]
|
| 1008 |
|
| 1009 |
An *abbreviated function template* is a function declaration that has
|
| 1010 |
one or more generic parameter type placeholders [[dcl.spec.auto]]. An
|
| 1011 |
abbreviated function template is equivalent to a function template
|
| 1012 |
+
[[temp.fct]] whose *template-parameter-list* includes one invented
|
| 1013 |
+
*type-parameter* for each generic parameter type placeholder of the
|
| 1014 |
function declaration, in order of appearance. For a
|
| 1015 |
*placeholder-type-specifier* of the form `auto`, the invented parameter
|
| 1016 |
is an unconstrained *type-parameter*. For a *placeholder-type-specifier*
|
| 1017 |
of the form *type-constraint* `auto`, the invented parameter is a
|
| 1018 |
+
*type-parameter* with that *type-constraint*. The invented
|
| 1019 |
+
*type-parameter* declares a template parameter pack if the corresponding
|
| 1020 |
*parameter-declaration* declares a function parameter pack. If the
|
| 1021 |
placeholder contains `decltype(auto)`, the program is ill-formed. The
|
| 1022 |
adjusted function parameters of an abbreviated function template are
|
| 1023 |
derived from the *parameter-declaration-clause* by replacing each
|
| 1024 |
occurrence of a placeholder with the name of the corresponding invented
|
| 1025 |
+
*type-parameter*.
|
| 1026 |
|
| 1027 |
[*Example 9*:
|
| 1028 |
|
| 1029 |
``` cpp
|
| 1030 |
template<typename T> concept C1 = /* ... */;
|
|
|
|
| 1055 |
```
|
| 1056 |
|
| 1057 |
— *end example*]
|
| 1058 |
|
| 1059 |
An abbreviated function template can have a *template-head*. The
|
| 1060 |
+
invented *type-parameter*s are appended to the *template-parameter-list*
|
| 1061 |
+
after the explicitly declared *template-parameter*s.
|
|
|
|
| 1062 |
|
| 1063 |
[*Example 10*:
|
| 1064 |
|
| 1065 |
``` cpp
|
| 1066 |
template<typename> concept C = /* ... */;
|
|
|
|
| 1144 |
|
| 1145 |
— *end example*]
|
| 1146 |
|
| 1147 |
A default argument shall be specified only in the
|
| 1148 |
*parameter-declaration-clause* of a function declaration or
|
| 1149 |
+
*lambda-declarator* or in a *template-parameter* [[temp.param]]. A
|
| 1150 |
+
default argument shall not be specified for a template parameter pack or
|
| 1151 |
+
a function parameter pack. If it is specified in a
|
| 1152 |
+
*parameter-declaration-clause*, it shall not occur within a *declarator*
|
| 1153 |
+
or *abstract-declarator* of a *parameter-declaration*.[^4]
|
|
|
|
| 1154 |
|
| 1155 |
For non-template functions, default arguments can be added in later
|
| 1156 |
+
declarations of a function that have the same host scope. Declarations
|
| 1157 |
+
that have different host scopes have completely distinct sets of default
|
| 1158 |
arguments. That is, declarations in inner scopes do not acquire default
|
| 1159 |
arguments from declarations in outer scopes, and vice versa. In a given
|
| 1160 |
function declaration, each parameter subsequent to a parameter with a
|
| 1161 |
default argument shall have a default argument supplied in this or a
|
| 1162 |
previous declaration, unless the parameter was expanded from a parameter
|
|
|
|
| 1237 |
|
| 1238 |
[*Note 3*: A default argument is a complete-class context
|
| 1239 |
[[class.mem]]. Access checking applies to names in default arguments as
|
| 1240 |
described in [[class.access]]. — *end note*]
|
| 1241 |
|
| 1242 |
+
Except for member functions of templated classes, the default arguments
|
| 1243 |
+
in a member function definition that appears outside of the class
|
| 1244 |
definition are added to the set of default arguments provided by the
|
| 1245 |
member function declaration in the class definition; the program is
|
| 1246 |
ill-formed if a default constructor [[class.default.ctor]], copy or move
|
| 1247 |
constructor [[class.copy.ctor]], or copy or move assignment operator
|
| 1248 |
[[class.copy.assign]] is so declared. Default arguments for a member
|
| 1249 |
+
function of a templated class shall be specified on the initial
|
| 1250 |
+
declaration of the member function within the templated class.
|
| 1251 |
|
| 1252 |
[*Example 4*:
|
| 1253 |
|
| 1254 |
``` cpp
|
| 1255 |
class C {
|
|
|
|
| 1314 |
int h(int a, int b = sizeof(a)); // OK, unevaluated operand[term.unevaluated.operand]
|
| 1315 |
```
|
| 1316 |
|
| 1317 |
— *end example*]
|
| 1318 |
|
| 1319 |
+
A non-static member shall not be designated in a default argument unless
|
| 1320 |
+
|
| 1321 |
+
- it is designated by the *id-expression* or *splice-expression* of a
|
| 1322 |
+
class member access expression [[expr.ref]],
|
| 1323 |
+
- it is designated by an expression used to form a pointer to member
|
| 1324 |
+
[[expr.unary.op]], or
|
| 1325 |
+
- it appears as the operand of a *reflect-expression* [[expr.reflect]].
|
| 1326 |
|
| 1327 |
[*Example 8*:
|
| 1328 |
|
| 1329 |
The declaration of `X::mem1()` in the following example is ill-formed
|
| 1330 |
because no object is supplied for the non-static member `X::a` used as
|
|
|
|
| 1333 |
``` cpp
|
| 1334 |
int b;
|
| 1335 |
class X {
|
| 1336 |
int a;
|
| 1337 |
int mem1(int i = a); // error: non-static member a used as default argument
|
| 1338 |
+
int mem2(int i = b); // OK, use X::b
|
| 1339 |
+
consteval void mem3(std::meta::info r = ^^a) {} // OK
|
| 1340 |
+
int mem4(int i = [:^^a:]); // error: non-static member a designated in default argument
|
| 1341 |
static int b;
|
| 1342 |
};
|
| 1343 |
```
|
| 1344 |
|
| 1345 |
The declaration of `X::mem2()` is meaningful, however, since no object
|
|
|
|
| 1364 |
int (*p2)() = &f; // error: type mismatch
|
| 1365 |
```
|
| 1366 |
|
| 1367 |
— *end example*]
|
| 1368 |
|
| 1369 |
+
[*Note 7*: When an overload set contains a declaration of a function
|
| 1370 |
+
whose host scope is S, any default argument associated with any
|
| 1371 |
+
reachable declaration whose host scope is S is available to the call
|
| 1372 |
+
[[over.match.viable]]. — *end note*]
|
| 1373 |
|
| 1374 |
+
[*Note 8*: The candidate might have been found through a
|
| 1375 |
*using-declarator* from which the declaration that provides the default
|
| 1376 |
argument is not reachable. — *end note*]
|
| 1377 |
|
| 1378 |
A virtual function call [[class.virtual]] uses the default arguments in
|
| 1379 |
the declaration of the virtual function determined by the static type of
|