- tmp/tmp9wi9n61u/{from.md → to.md} +205 -89
tmp/tmp9wi9n61u/{from.md → to.md}
RENAMED
|
@@ -92,11 +92,11 @@ some other access path.
|
|
| 92 |
|
| 93 |
[*Note 4*: Cv-qualifiers are supported by the type system so that they
|
| 94 |
cannot be subverted without casting [[expr.const.cast]]. — *end note*]
|
| 95 |
|
| 96 |
Any attempt to modify
|
| 97 |
-
[[expr.
|
| 98 |
[[basic.type.qualifier]] during its lifetime [[basic.life]] results in
|
| 99 |
undefined behavior.
|
| 100 |
|
| 101 |
[*Example 1*:
|
| 102 |
|
|
@@ -144,27 +144,27 @@ The semantics of an access through a volatile glvalue are
|
|
| 144 |
*implementation-defined*. If an attempt is made to access an object
|
| 145 |
defined with a volatile-qualified type through the use of a non-volatile
|
| 146 |
glvalue, the behavior is undefined.
|
| 147 |
|
| 148 |
[*Note 5*: `volatile` is a hint to the implementation to avoid
|
| 149 |
-
aggressive optimization involving the object because
|
| 150 |
-
|
| 151 |
-
Furthermore, for some implementations, `volatile`
|
| 152 |
-
special hardware instructions are
|
| 153 |
-
[[intro.execution]] for detailed semantics. In general, the
|
| 154 |
-
`volatile` are intended to be the same in C++ as they are
|
| 155 |
-
C. — *end note*]
|
| 156 |
|
| 157 |
#### Simple type specifiers <a id="dcl.type.simple">[[dcl.type.simple]]</a>
|
| 158 |
|
| 159 |
The simple type specifiers are
|
| 160 |
|
| 161 |
``` bnf
|
| 162 |
simple-type-specifier:
|
| 163 |
nested-name-specifierₒₚₜ type-name
|
| 164 |
nested-name-specifier template simple-template-id
|
| 165 |
-
|
| 166 |
placeholder-type-specifier
|
| 167 |
nested-name-specifierₒₚₜ template-name
|
| 168 |
char
|
| 169 |
char8_t
|
| 170 |
char16_t
|
|
@@ -186,24 +186,36 @@ type-name:
|
|
| 186 |
class-name
|
| 187 |
enum-name
|
| 188 |
typedef-name
|
| 189 |
```
|
| 190 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
The component names of a *simple-type-specifier* are those of its
|
| 192 |
*nested-name-specifier*, *type-name*, *simple-template-id*,
|
| 193 |
*template-name*, and/or *type-constraint* (if it is a
|
| 194 |
*placeholder-type-specifier*). The component name of a *type-name* is
|
| 195 |
the first name in it.
|
| 196 |
|
| 197 |
A *placeholder-type-specifier* is a placeholder for a type to be deduced
|
| 198 |
-
[[dcl.spec.auto]]. A *type-specifier*
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
*nested-name-specifier*
|
| 202 |
-
*template-name*
|
| 203 |
-
|
| 204 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
|
| 206 |
``` bnf
|
| 207 |
typenameₒₚₜ nested-name-specifierₒₚₜ templateₒₚₜ simple-template-id
|
| 208 |
```
|
| 209 |
|
|
@@ -224,12 +236,14 @@ combinations of *simple-type-specifier*s and the types they specify.
|
|
| 224 |
| Specifier(s) | Type |
|
| 225 |
| ---------------------------- | ------------------------------------------------- |
|
| 226 |
| *type-name* | the type named |
|
| 227 |
| *simple-template-id* | the type as defined in~ [[temp.names]] |
|
| 228 |
| *decltype-specifier* | the type as defined in~ [[dcl.type.decltype]] |
|
|
|
|
| 229 |
| *placeholder-type-specifier* | the type as defined in~ [[dcl.spec.auto]] |
|
| 230 |
| *template-name* | the type as defined in~ [[dcl.type.class.deduct]] |
|
|
|
|
| 231 |
| `char` | ```char`'' |
|
| 232 |
| `unsigned char` | ```unsigned char`'' |
|
| 233 |
| `signed char` | ```signed char`'' |
|
| 234 |
| `char8_t` | ```char8_t`'' |
|
| 235 |
| `char16_t` | ```char16_t`'' |
|
|
@@ -271,10 +285,28 @@ intermixed with other *decl-specifier*s in any order.
|
|
| 271 |
[*Note 2*: It is *implementation-defined* whether objects of `char`
|
| 272 |
type are represented as signed or unsigned quantities. The `signed`
|
| 273 |
specifier forces `char` objects to be signed; it is redundant in other
|
| 274 |
contexts. — *end note*]
|
| 275 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
#### Elaborated type specifiers <a id="dcl.type.elab">[[dcl.type.elab]]</a>
|
| 277 |
|
| 278 |
``` bnf
|
| 279 |
elaborated-type-specifier:
|
| 280 |
class-key attribute-specifier-seqₒₚₜ nested-name-specifierₒₚₜ identifier
|
|
@@ -287,77 +319,77 @@ The component names of an *elaborated-type-specifier* are its
|
|
| 287 |
*identifier* (if any) and those of its *nested-name-specifier* and
|
| 288 |
*simple-template-id* (if any).
|
| 289 |
|
| 290 |
If an *elaborated-type-specifier* is the sole constituent of a
|
| 291 |
declaration, the declaration is ill-formed unless it is an explicit
|
| 292 |
-
specialization [[temp.expl.spec]],
|
| 293 |
-
[[temp.
|
|
|
|
| 294 |
|
| 295 |
``` bnf
|
| 296 |
class-key attribute-specifier-seqₒₚₜ identifier ';'
|
| 297 |
class-key attribute-specifier-seqₒₚₜ simple-template-id ';'
|
| 298 |
```
|
| 299 |
|
| 300 |
In the first case, the *elaborated-type-specifier* declares the
|
| 301 |
*identifier* as a *class-name*. The second case shall appear only in an
|
| 302 |
*explicit-specialization* [[temp.expl.spec]] or in a
|
| 303 |
-
*template-declaration* (where it declares a partial specialization
|
| 304 |
-
|
| 305 |
-
|
| 306 |
|
| 307 |
Otherwise, an *elaborated-type-specifier* E shall not have an
|
| 308 |
*attribute-specifier-seq*. If E contains an *identifier* but no
|
| 309 |
*nested-name-specifier* and (unqualified) lookup for the *identifier*
|
| 310 |
finds nothing, E shall not be introduced by the `enum` keyword and
|
| 311 |
declares the *identifier* as a *class-name*. The target scope of E is
|
| 312 |
the nearest enclosing namespace or block scope.
|
| 313 |
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
of the following forms:
|
| 317 |
|
| 318 |
``` bnf
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
```
|
| 323 |
|
| 324 |
Any unqualified lookup for the *identifier* (in the first case) does not
|
| 325 |
-
consider scopes that contain the
|
|
|
|
| 326 |
|
| 327 |
[*Note 1*: A *using-directive* in the target scope is ignored if it
|
| 328 |
-
refers to a namespace not contained by that scope.
|
| 329 |
-
describes how name lookup proceeds in an
|
| 330 |
-
*elaborated-type-specifier*. — *end note*]
|
| 331 |
|
| 332 |
-
[*Note 2*:
|
| 333 |
-
|
| 334 |
-
|
|
|
|
| 335 |
|
| 336 |
-
If the *identifier* or *simple-template-id*
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
*type-
|
| 340 |
-
|
| 341 |
-
[[dcl.typedef]], [[temp.names]], the
|
| 342 |
-
ill-formed.
|
| 343 |
|
| 344 |
[*Note 3*:
|
| 345 |
|
| 346 |
This implies that, within a class template with a template
|
| 347 |
*type-parameter* `T`, the declaration
|
| 348 |
|
| 349 |
``` cpp
|
| 350 |
friend class T;
|
| 351 |
```
|
| 352 |
|
| 353 |
-
is ill-formed. However, the similar declaration `friend T;` is
|
| 354 |
-
[[class.friend]].
|
| 355 |
|
| 356 |
— *end note*]
|
| 357 |
|
| 358 |
-
The *class-key* or `enum` keyword present in
|
| 359 |
*elaborated-type-specifier* shall agree in kind with the declaration to
|
| 360 |
which the name in the *elaborated-type-specifier* refers. This rule also
|
| 361 |
applies to the form of *elaborated-type-specifier* that declares a
|
| 362 |
*class-name* or friend class since it can be construed as referring to
|
| 363 |
the definition of the class. Thus, in any *elaborated-type-specifier*,
|
|
@@ -389,17 +421,20 @@ follows:
|
|
| 389 |
|
| 390 |
- if E is an unparenthesized *id-expression* naming a structured binding
|
| 391 |
[[dcl.struct.bind]], `decltype(E)` is the referenced type as given in
|
| 392 |
the specification of the structured binding declaration;
|
| 393 |
- otherwise, if E is an unparenthesized *id-expression* naming a
|
| 394 |
-
|
| 395 |
-
|
| 396 |
deduction [[dcl.spec.auto]], [[dcl.type.class.deduct]];
|
| 397 |
- otherwise, if E is an unparenthesized *id-expression* or an
|
| 398 |
unparenthesized class member access [[expr.ref]], `decltype(E)` is the
|
| 399 |
type of the entity named by E. If there is no such entity, the program
|
| 400 |
is ill-formed;
|
|
|
|
|
|
|
|
|
|
| 401 |
- otherwise, if E is an xvalue, `decltype(E)` is `T&&`, where `T` is the
|
| 402 |
type of E;
|
| 403 |
- otherwise, if E is an lvalue, `decltype(E)` is `T&`, where `T` is the
|
| 404 |
type of E;
|
| 405 |
- otherwise, `decltype(E)` is the type of E.
|
|
@@ -416,10 +451,19 @@ struct A { double x; };
|
|
| 416 |
const A* a = new A();
|
| 417 |
decltype(foo()) x1 = 17; // type is const int&&
|
| 418 |
decltype(i) x2; // type is int
|
| 419 |
decltype(a->x) x3; // type is double
|
| 420 |
decltype((a->x)) x4 = x3; // type is const double&
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 421 |
```
|
| 422 |
|
| 423 |
— *end example*]
|
| 424 |
|
| 425 |
[*Note 1*: The rules for determining types involving `decltype(auto)`
|
|
@@ -485,64 +529,76 @@ placeholder-type-specifier:
|
|
| 485 |
type-constraintₒₚₜ auto
|
| 486 |
type-constraintₒₚₜ decltype '(' auto ')'
|
| 487 |
```
|
| 488 |
|
| 489 |
A *placeholder-type-specifier* designates a placeholder type that will
|
| 490 |
-
be replaced later by deduction from an initializer.
|
| 491 |
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 498 |
|
| 499 |
[*Note 1*: Having a generic parameter type placeholder signifies that
|
| 500 |
the function is an abbreviated function template [[dcl.fct]] or the
|
| 501 |
lambda is a generic lambda [[expr.prim.lambda]]. — *end note*]
|
| 502 |
|
| 503 |
-
A placeholder type can appear
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
non-discarded `return` statements, if any, in the body of the function
|
| 512 |
-
[[stmt.if]].
|
| 513 |
|
| 514 |
The type of a variable declared using a placeholder type is deduced from
|
| 515 |
its initializer. This use is allowed in an initializing declaration
|
| 516 |
[[dcl.init]] of a variable. The placeholder type shall appear as one of
|
| 517 |
-
the *decl-specifier*s in the *decl-specifier-seq*
|
| 518 |
-
*
|
| 519 |
-
|
|
|
|
|
|
|
| 520 |
|
| 521 |
[*Example 1*:
|
| 522 |
|
| 523 |
``` cpp
|
| 524 |
auto x = 5; // OK, x has type int
|
| 525 |
const auto *v = &x, u = 6; // OK, v has type const int*, u has type const int
|
| 526 |
static auto y = 0.0; // OK, y has type double
|
| 527 |
auto int r; // error: auto is not a storage-class-specifier
|
| 528 |
auto f() -> int; // OK, f returns int
|
| 529 |
auto g() { return 0.0; } // OK, g returns double
|
|
|
|
| 530 |
auto h(); // OK, h's return type will be deduced when it is defined
|
| 531 |
```
|
| 532 |
|
| 533 |
— *end example*]
|
| 534 |
|
| 535 |
The `auto` *type-specifier* can also be used to introduce a structured
|
| 536 |
binding declaration [[dcl.struct.bind]].
|
| 537 |
|
| 538 |
-
A placeholder type can also be used in the *type-specifier-seq*
|
| 539 |
-
*new-type-id* or *type-id* of a *new-expression* [[expr.new]]
|
| 540 |
-
*
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 544 |
|
| 545 |
A program that uses a placeholder type in a context not explicitly
|
| 546 |
allowed in [[dcl.spec.auto]] is ill-formed.
|
| 547 |
|
| 548 |
If the *init-declarator-list* contains more than one *init-declarator*,
|
|
@@ -606,10 +662,25 @@ auto sum(int i) {
|
|
| 606 |
}
|
| 607 |
```
|
| 608 |
|
| 609 |
— *end example*]
|
| 610 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 611 |
Return type deduction for a templated function with a placeholder in its
|
| 612 |
declared type occurs when the definition is instantiated even if the
|
| 613 |
function body contains a `return` statement with a non-type-dependent
|
| 614 |
operand.
|
| 615 |
|
|
@@ -617,11 +688,11 @@ operand.
|
|
| 617 |
template will cause an implicit instantiation. Any errors that arise
|
| 618 |
from this instantiation are not in the immediate context of the function
|
| 619 |
type and can result in the program being ill-formed
|
| 620 |
[[temp.deduct]]. — *end note*]
|
| 621 |
|
| 622 |
-
[*Example
|
| 623 |
|
| 624 |
``` cpp
|
| 625 |
template <class T> auto f(T t) { return t; } // return type deduced at instantiation time
|
| 626 |
typedef decltype(f(1)) fint_t; // instantiates f<int> to deduce return type
|
| 627 |
template<class T> auto f(T* t) { return *t; }
|
|
@@ -634,11 +705,11 @@ void g() { int (*p)(int*) = &f; } // instantiates both fs to deter
|
|
| 634 |
If a function or function template F has a declared return type that
|
| 635 |
uses a placeholder type, redeclarations or specializations of F shall
|
| 636 |
use that placeholder type, not a deduced type; otherwise, they shall not
|
| 637 |
use a placeholder type.
|
| 638 |
|
| 639 |
-
[*Example
|
| 640 |
|
| 641 |
``` cpp
|
| 642 |
auto f();
|
| 643 |
auto f() { return 42; } // return type is int
|
| 644 |
auto f(); // OK
|
|
@@ -679,11 +750,11 @@ shall not be a coroutine [[dcl.fct.def.coroutine]].
|
|
| 679 |
An explicit instantiation declaration [[temp.explicit]] does not cause
|
| 680 |
the instantiation of an entity declared using a placeholder type, but it
|
| 681 |
also does not prevent that entity from being instantiated as needed to
|
| 682 |
determine its type.
|
| 683 |
|
| 684 |
-
[*Example
|
| 685 |
|
| 686 |
``` cpp
|
| 687 |
template <typename T> auto f(T t) { return t; }
|
| 688 |
extern template auto f(int); // does not instantiate f<int>
|
| 689 |
int (*p)(int) = f; // instantiates f<int> to determine its return type, but an explicit
|
|
@@ -729,32 +800,31 @@ A type `T` containing a placeholder type, and a corresponding
|
|
| 729 |
single brace-enclosed *assignment-expression* and E is the
|
| 730 |
*assignment-expression*.
|
| 731 |
- If the initializer is a parenthesized *expression-list*, the
|
| 732 |
*expression-list* shall be a single *assignment-expression* and E is
|
| 733 |
the *assignment-expression*.
|
| 734 |
-
- For a
|
| 735 |
-
placeholder type, `T` is the declared type of the
|
| 736 |
parameter and E is the corresponding template argument.
|
| 737 |
|
| 738 |
`T` shall not be an array type.
|
| 739 |
|
| 740 |
If the *placeholder-type-specifier* is of the form *type-constraint*ₒₚₜ
|
| 741 |
`auto`, the deduced type T' replacing `T` is determined using the rules
|
| 742 |
for template argument deduction. If the initialization is
|
| 743 |
copy-list-initialization, a declaration of `std::initializer_list` shall
|
| 744 |
precede [[basic.lookup.general]] the *placeholder-type-specifier*.
|
| 745 |
-
Obtain `P` from `T` by replacing the
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
|
| 753 |
-
deduced `U` into `P`.
|
| 754 |
|
| 755 |
-
[*Example
|
| 756 |
|
| 757 |
``` cpp
|
| 758 |
auto x1 = { 1, 2 }; // decltype(x1) is std::initializer_list<int>
|
| 759 |
auto x2 = { 1, 2.0 }; // error: cannot deduce element type
|
| 760 |
auto x3{ 1, 2 }; // error: not a single element
|
|
@@ -762,11 +832,11 @@ auto x4 = { 3 }; // decltype(x4) is std::initializer_list<int>
|
|
| 762 |
auto x5{ 3 }; // decltype(x5) is int
|
| 763 |
```
|
| 764 |
|
| 765 |
— *end example*]
|
| 766 |
|
| 767 |
-
[*Example
|
| 768 |
|
| 769 |
``` cpp
|
| 770 |
const auto &i = expr;
|
| 771 |
```
|
| 772 |
|
|
@@ -782,11 +852,11 @@ template <class U> void f(const U& u);
|
|
| 782 |
If the *placeholder-type-specifier* is of the form *type-constraint*ₒₚₜ
|
| 783 |
`decltype(auto)`, `T` shall be the placeholder alone. The type deduced
|
| 784 |
for `T` is determined as described in [[dcl.type.decltype]], as though
|
| 785 |
E had been the operand of the `decltype`.
|
| 786 |
|
| 787 |
-
[*Example
|
| 788 |
|
| 789 |
``` cpp
|
| 790 |
int i;
|
| 791 |
int&& f();
|
| 792 |
auto x2a(i); // decltype(x2a) is int
|
|
@@ -861,5 +931,51 @@ auto d = container(v.begin(), v.end()); // OK, deduces double for T
|
|
| 861 |
container e{5, 6}; // error: int is not an iterator
|
| 862 |
```
|
| 863 |
|
| 864 |
— *end example*]
|
| 865 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
[*Note 4*: Cv-qualifiers are supported by the type system so that they
|
| 94 |
cannot be subverted without casting [[expr.const.cast]]. — *end note*]
|
| 95 |
|
| 96 |
Any attempt to modify
|
| 97 |
+
[[expr.assign]], [[expr.post.incr]], [[expr.pre.incr]] a const object
|
| 98 |
[[basic.type.qualifier]] during its lifetime [[basic.life]] results in
|
| 99 |
undefined behavior.
|
| 100 |
|
| 101 |
[*Example 1*:
|
| 102 |
|
|
|
|
| 144 |
*implementation-defined*. If an attempt is made to access an object
|
| 145 |
defined with a volatile-qualified type through the use of a non-volatile
|
| 146 |
glvalue, the behavior is undefined.
|
| 147 |
|
| 148 |
[*Note 5*: `volatile` is a hint to the implementation to avoid
|
| 149 |
+
aggressive optimization involving the object because it is possible for
|
| 150 |
+
the value of the object to change by means undetectable by an
|
| 151 |
+
implementation. Furthermore, for some implementations, `volatile` can
|
| 152 |
+
indicate that special hardware instructions are needed to access the
|
| 153 |
+
object. See [[intro.execution]] for detailed semantics. In general, the
|
| 154 |
+
semantics of `volatile` are intended to be the same in C++ as they are
|
| 155 |
+
in C. — *end note*]
|
| 156 |
|
| 157 |
#### Simple type specifiers <a id="dcl.type.simple">[[dcl.type.simple]]</a>
|
| 158 |
|
| 159 |
The simple type specifiers are
|
| 160 |
|
| 161 |
``` bnf
|
| 162 |
simple-type-specifier:
|
| 163 |
nested-name-specifierₒₚₜ type-name
|
| 164 |
nested-name-specifier template simple-template-id
|
| 165 |
+
computed-type-specifier
|
| 166 |
placeholder-type-specifier
|
| 167 |
nested-name-specifierₒₚₜ template-name
|
| 168 |
char
|
| 169 |
char8_t
|
| 170 |
char16_t
|
|
|
|
| 186 |
class-name
|
| 187 |
enum-name
|
| 188 |
typedef-name
|
| 189 |
```
|
| 190 |
|
| 191 |
+
``` bnf
|
| 192 |
+
computed-type-specifier:
|
| 193 |
+
decltype-specifier
|
| 194 |
+
pack-index-specifier
|
| 195 |
+
splice-type-specifier
|
| 196 |
+
```
|
| 197 |
+
|
| 198 |
The component names of a *simple-type-specifier* are those of its
|
| 199 |
*nested-name-specifier*, *type-name*, *simple-template-id*,
|
| 200 |
*template-name*, and/or *type-constraint* (if it is a
|
| 201 |
*placeholder-type-specifier*). The component name of a *type-name* is
|
| 202 |
the first name in it.
|
| 203 |
|
| 204 |
A *placeholder-type-specifier* is a placeholder for a type to be deduced
|
| 205 |
+
[[dcl.spec.auto]]. A *type-specifier* is a placeholder for a deduced
|
| 206 |
+
class type [[dcl.type.class.deduct]] if either
|
| 207 |
+
|
| 208 |
+
- it is of the form `typename`ₒₚₜ *nested-name-specifier*ₒₚₜ
|
| 209 |
+
*template-name* or
|
| 210 |
+
- it is of the form `typename`ₒₚₜ *splice-specifier* and the
|
| 211 |
+
*splice-specifier* designates a class template or alias template.
|
| 212 |
+
|
| 213 |
+
The *nested-name-specifier* or *splice-specifier*, if any, shall be
|
| 214 |
+
non-dependent and the *template-name* or *splice-specifier* shall
|
| 215 |
+
designate a deducible template. A *deducible template* is either a class
|
| 216 |
+
template or is an alias template whose *defining-type-id* is of the form
|
| 217 |
|
| 218 |
``` bnf
|
| 219 |
typenameₒₚₜ nested-name-specifierₒₚₜ templateₒₚₜ simple-template-id
|
| 220 |
```
|
| 221 |
|
|
|
|
| 236 |
| Specifier(s) | Type |
|
| 237 |
| ---------------------------- | ------------------------------------------------- |
|
| 238 |
| *type-name* | the type named |
|
| 239 |
| *simple-template-id* | the type as defined in~ [[temp.names]] |
|
| 240 |
| *decltype-specifier* | the type as defined in~ [[dcl.type.decltype]] |
|
| 241 |
+
| *pack-index-specifier* | the type as defined in~ [[dcl.type.pack.index]] |
|
| 242 |
| *placeholder-type-specifier* | the type as defined in~ [[dcl.spec.auto]] |
|
| 243 |
| *template-name* | the type as defined in~ [[dcl.type.class.deduct]] |
|
| 244 |
+
| *splice-type-specifier* | the type as defined in~ [[dcl.type.splice]] |
|
| 245 |
| `char` | ```char`'' |
|
| 246 |
| `unsigned char` | ```unsigned char`'' |
|
| 247 |
| `signed char` | ```signed char`'' |
|
| 248 |
| `char8_t` | ```char8_t`'' |
|
| 249 |
| `char16_t` | ```char16_t`'' |
|
|
|
|
| 285 |
[*Note 2*: It is *implementation-defined* whether objects of `char`
|
| 286 |
type are represented as signed or unsigned quantities. The `signed`
|
| 287 |
specifier forces `char` objects to be signed; it is redundant in other
|
| 288 |
contexts. — *end note*]
|
| 289 |
|
| 290 |
+
#### Pack indexing specifier <a id="dcl.type.pack.index">[[dcl.type.pack.index]]</a>
|
| 291 |
+
|
| 292 |
+
``` bnf
|
| 293 |
+
pack-index-specifier:
|
| 294 |
+
typedef-name '...' '[' constant-expression ']'
|
| 295 |
+
```
|
| 296 |
+
|
| 297 |
+
The *typedef-name* P in a *pack-index-specifier* shall denote a pack.
|
| 298 |
+
|
| 299 |
+
The *constant-expression* shall be a converted constant expression
|
| 300 |
+
[[expr.const]] of type `std::size_t` whose value V, termed the index, is
|
| 301 |
+
such that 0 ≤ V < `sizeof...($P$)`.
|
| 302 |
+
|
| 303 |
+
A *pack-index-specifier* is a pack expansion [[temp.variadic]].
|
| 304 |
+
|
| 305 |
+
[*Note 1*: The *pack-index-specifier* denotes the type of the Vᵗʰ
|
| 306 |
+
element of the pack. — *end note*]
|
| 307 |
+
|
| 308 |
#### Elaborated type specifiers <a id="dcl.type.elab">[[dcl.type.elab]]</a>
|
| 309 |
|
| 310 |
``` bnf
|
| 311 |
elaborated-type-specifier:
|
| 312 |
class-key attribute-specifier-seqₒₚₜ nested-name-specifierₒₚₜ identifier
|
|
|
|
| 319 |
*identifier* (if any) and those of its *nested-name-specifier* and
|
| 320 |
*simple-template-id* (if any).
|
| 321 |
|
| 322 |
If an *elaborated-type-specifier* is the sole constituent of a
|
| 323 |
declaration, the declaration is ill-formed unless it is an explicit
|
| 324 |
+
specialization [[temp.expl.spec]], a partial specialization
|
| 325 |
+
[[temp.spec.partial]], an explicit instantiation [[temp.explicit]], or
|
| 326 |
+
it has one of the following forms:
|
| 327 |
|
| 328 |
``` bnf
|
| 329 |
class-key attribute-specifier-seqₒₚₜ identifier ';'
|
| 330 |
class-key attribute-specifier-seqₒₚₜ simple-template-id ';'
|
| 331 |
```
|
| 332 |
|
| 333 |
In the first case, the *elaborated-type-specifier* declares the
|
| 334 |
*identifier* as a *class-name*. The second case shall appear only in an
|
| 335 |
*explicit-specialization* [[temp.expl.spec]] or in a
|
| 336 |
+
*template-declaration* (where it declares a partial specialization). The
|
| 337 |
+
*attribute-specifier-seq*, if any, appertains to the class or template
|
| 338 |
+
being declared.
|
| 339 |
|
| 340 |
Otherwise, an *elaborated-type-specifier* E shall not have an
|
| 341 |
*attribute-specifier-seq*. If E contains an *identifier* but no
|
| 342 |
*nested-name-specifier* and (unqualified) lookup for the *identifier*
|
| 343 |
finds nothing, E shall not be introduced by the `enum` keyword and
|
| 344 |
declares the *identifier* as a *class-name*. The target scope of E is
|
| 345 |
the nearest enclosing namespace or block scope.
|
| 346 |
|
| 347 |
+
A *friend-type-specifier* that is an *elaborated-type-specifier* shall
|
| 348 |
+
have one of the following forms:
|
|
|
|
| 349 |
|
| 350 |
``` bnf
|
| 351 |
+
class-key nested-name-specifierₒₚₜ identifier
|
| 352 |
+
class-key simple-template-id
|
| 353 |
+
class-key nested-name-specifier templateₒₚₜ simple-template-id
|
| 354 |
```
|
| 355 |
|
| 356 |
Any unqualified lookup for the *identifier* (in the first case) does not
|
| 357 |
+
consider scopes that contain the nearest enclosing namespace or block
|
| 358 |
+
scope; no name is bound.
|
| 359 |
|
| 360 |
[*Note 1*: A *using-directive* in the target scope is ignored if it
|
| 361 |
+
refers to a namespace not contained by that scope. — *end note*]
|
|
|
|
|
|
|
| 362 |
|
| 363 |
+
[*Note 2*: [[basic.lookup.elab]] describes how name lookup proceeds in
|
| 364 |
+
an *elaborated-type-specifier*. An *elaborated-type-specifier* can be
|
| 365 |
+
used to refer to a previously declared *class-name* or *enum-name* even
|
| 366 |
+
if the name has been hidden by a non-type declaration. — *end note*]
|
| 367 |
|
| 368 |
+
If the *identifier* or *simple-template-id* in an
|
| 369 |
+
*elaborated-type-specifier* resolves to a *class-name* or *enum-name*,
|
| 370 |
+
the *elaborated-type-specifier* introduces it into the declaration the
|
| 371 |
+
same way a *simple-type-specifier* introduces its *type-name*
|
| 372 |
+
[[dcl.type.simple]]. If the *identifier* or *simple-template-id*
|
| 373 |
+
resolves to a *typedef-name* [[dcl.typedef]], [[temp.names]], the
|
| 374 |
+
*elaborated-type-specifier* is ill-formed.
|
| 375 |
|
| 376 |
[*Note 3*:
|
| 377 |
|
| 378 |
This implies that, within a class template with a template
|
| 379 |
*type-parameter* `T`, the declaration
|
| 380 |
|
| 381 |
``` cpp
|
| 382 |
friend class T;
|
| 383 |
```
|
| 384 |
|
| 385 |
+
is ill-formed. However, the similar declaration `friend T;` is
|
| 386 |
+
well-formed [[class.friend]].
|
| 387 |
|
| 388 |
— *end note*]
|
| 389 |
|
| 390 |
+
The *class-key* or `enum` keyword present in an
|
| 391 |
*elaborated-type-specifier* shall agree in kind with the declaration to
|
| 392 |
which the name in the *elaborated-type-specifier* refers. This rule also
|
| 393 |
applies to the form of *elaborated-type-specifier* that declares a
|
| 394 |
*class-name* or friend class since it can be construed as referring to
|
| 395 |
the definition of the class. Thus, in any *elaborated-type-specifier*,
|
|
|
|
| 421 |
|
| 422 |
- if E is an unparenthesized *id-expression* naming a structured binding
|
| 423 |
[[dcl.struct.bind]], `decltype(E)` is the referenced type as given in
|
| 424 |
the specification of the structured binding declaration;
|
| 425 |
- otherwise, if E is an unparenthesized *id-expression* naming a
|
| 426 |
+
constant template parameter [[temp.param]], `decltype(E)` is the type
|
| 427 |
+
of the template parameter after performing any necessary type
|
| 428 |
deduction [[dcl.spec.auto]], [[dcl.type.class.deduct]];
|
| 429 |
- otherwise, if E is an unparenthesized *id-expression* or an
|
| 430 |
unparenthesized class member access [[expr.ref]], `decltype(E)` is the
|
| 431 |
type of the entity named by E. If there is no such entity, the program
|
| 432 |
is ill-formed;
|
| 433 |
+
- otherwise, if E is an unparenthesized *splice-expression*,
|
| 434 |
+
`decltype(E)` is the type of the entity, object, or value designated
|
| 435 |
+
by the *splice-specifier* of E;
|
| 436 |
- otherwise, if E is an xvalue, `decltype(E)` is `T&&`, where `T` is the
|
| 437 |
type of E;
|
| 438 |
- otherwise, if E is an lvalue, `decltype(E)` is `T&`, where `T` is the
|
| 439 |
type of E;
|
| 440 |
- otherwise, `decltype(E)` is the type of E.
|
|
|
|
| 451 |
const A* a = new A();
|
| 452 |
decltype(foo()) x1 = 17; // type is const int&&
|
| 453 |
decltype(i) x2; // type is int
|
| 454 |
decltype(a->x) x3; // type is double
|
| 455 |
decltype((a->x)) x4 = x3; // type is const double&
|
| 456 |
+
decltype([:^^x1:]) x5 = 18; // type is const int&&
|
| 457 |
+
decltype(([:^^x1:])) x6 = 19; // type is const int&
|
| 458 |
+
|
| 459 |
+
void f() {
|
| 460 |
+
[](auto ...pack) {
|
| 461 |
+
decltype(pack...[0]) x7; // type is int
|
| 462 |
+
decltype((pack...[0])) x8; // type is int&
|
| 463 |
+
}(0);
|
| 464 |
+
}
|
| 465 |
```
|
| 466 |
|
| 467 |
— *end example*]
|
| 468 |
|
| 469 |
[*Note 1*: The rules for determining types involving `decltype(auto)`
|
|
|
|
| 529 |
type-constraintₒₚₜ auto
|
| 530 |
type-constraintₒₚₜ decltype '(' auto ')'
|
| 531 |
```
|
| 532 |
|
| 533 |
A *placeholder-type-specifier* designates a placeholder type that will
|
| 534 |
+
be replaced later, typically by deduction from an initializer.
|
| 535 |
|
| 536 |
+
The type of a *parameter-declaration* of a
|
| 537 |
+
|
| 538 |
+
- function declaration [[dcl.fct]],
|
| 539 |
+
- *lambda-expression* [[expr.prim.lambda]], or
|
| 540 |
+
- *template-parameter* [[temp.param]]
|
| 541 |
+
|
| 542 |
+
can be declared using a *placeholder-type-specifier* of the form
|
| 543 |
+
*type-constraint*ₒₚₜ `auto`. The placeholder type shall appear as one
|
| 544 |
+
of the *decl-specifier*s in the *decl-specifier-seq* or as one of the
|
| 545 |
+
*type-specifier*s in a *trailing-return-type* that specifies the type
|
| 546 |
+
that replaces such a *decl-specifier* (see below); the placeholder type
|
| 547 |
+
is a *generic parameter type placeholder* of the function declaration,
|
| 548 |
+
*lambda-expression*, or *template-parameter*, respectively.
|
| 549 |
|
| 550 |
[*Note 1*: Having a generic parameter type placeholder signifies that
|
| 551 |
the function is an abbreviated function template [[dcl.fct]] or the
|
| 552 |
lambda is a generic lambda [[expr.prim.lambda]]. — *end note*]
|
| 553 |
|
| 554 |
+
A placeholder type can appear in the *decl-specifier-seq* for a function
|
| 555 |
+
declarator that includes a *trailing-return-type* [[dcl.fct]].
|
| 556 |
+
|
| 557 |
+
A placeholder type can appear in the *decl-specifier-seq* or
|
| 558 |
+
*type-specifier-seq* in the declared return type of a function
|
| 559 |
+
declarator that declares a function; the return type of the function is
|
| 560 |
+
deduced from non-discarded `return` statements, if any, in the body of
|
| 561 |
+
the function [[stmt.if]].
|
|
|
|
|
|
|
| 562 |
|
| 563 |
The type of a variable declared using a placeholder type is deduced from
|
| 564 |
its initializer. This use is allowed in an initializing declaration
|
| 565 |
[[dcl.init]] of a variable. The placeholder type shall appear as one of
|
| 566 |
+
the *decl-specifier*s in the *decl-specifier-seq* or as one of the
|
| 567 |
+
*type-specifier*s in a *trailing-return-type* that specifies the type
|
| 568 |
+
that replaces such a *decl-specifier*; the *decl-specifier-seq* shall be
|
| 569 |
+
followed by one or more *declarator*s, each of which shall be followed
|
| 570 |
+
by a non-empty *initializer*.
|
| 571 |
|
| 572 |
[*Example 1*:
|
| 573 |
|
| 574 |
``` cpp
|
| 575 |
auto x = 5; // OK, x has type int
|
| 576 |
const auto *v = &x, u = 6; // OK, v has type const int*, u has type const int
|
| 577 |
static auto y = 0.0; // OK, y has type double
|
| 578 |
auto int r; // error: auto is not a storage-class-specifier
|
| 579 |
auto f() -> int; // OK, f returns int
|
| 580 |
auto g() { return 0.0; } // OK, g returns double
|
| 581 |
+
auto (*fp)() -> auto = f; // OK
|
| 582 |
auto h(); // OK, h's return type will be deduced when it is defined
|
| 583 |
```
|
| 584 |
|
| 585 |
— *end example*]
|
| 586 |
|
| 587 |
The `auto` *type-specifier* can also be used to introduce a structured
|
| 588 |
binding declaration [[dcl.struct.bind]].
|
| 589 |
|
| 590 |
+
A placeholder type can also be used in the *type-specifier-seq* of the
|
| 591 |
+
*new-type-id* or in the *type-id* of a *new-expression* [[expr.new]]. In
|
| 592 |
+
such a *type-id*, the placeholder type shall appear as one of the
|
| 593 |
+
*type-specifier*s in the *type-specifier-seq* or as one of the
|
| 594 |
+
*type-specifier*s in a *trailing-return-type* that specifies the type
|
| 595 |
+
that replaces such a *type-specifier*.
|
| 596 |
+
|
| 597 |
+
The `auto` *type-specifier* can also be used as the
|
| 598 |
+
*simple-type-specifier* in an explicit type conversion (functional
|
| 599 |
+
notation) [[expr.type.conv]].
|
| 600 |
|
| 601 |
A program that uses a placeholder type in a context not explicitly
|
| 602 |
allowed in [[dcl.spec.auto]] is ill-formed.
|
| 603 |
|
| 604 |
If the *init-declarator-list* contains more than one *init-declarator*,
|
|
|
|
| 662 |
}
|
| 663 |
```
|
| 664 |
|
| 665 |
— *end example*]
|
| 666 |
|
| 667 |
+
A result binding never has an undeduced placeholder type
|
| 668 |
+
[[dcl.contract.res]].
|
| 669 |
+
|
| 670 |
+
[*Example 5*:
|
| 671 |
+
|
| 672 |
+
``` cpp
|
| 673 |
+
auto f()
|
| 674 |
+
post(r : r == 7) // OK
|
| 675 |
+
{
|
| 676 |
+
return 7;
|
| 677 |
+
}
|
| 678 |
+
```
|
| 679 |
+
|
| 680 |
+
— *end example*]
|
| 681 |
+
|
| 682 |
Return type deduction for a templated function with a placeholder in its
|
| 683 |
declared type occurs when the definition is instantiated even if the
|
| 684 |
function body contains a `return` statement with a non-type-dependent
|
| 685 |
operand.
|
| 686 |
|
|
|
|
| 688 |
template will cause an implicit instantiation. Any errors that arise
|
| 689 |
from this instantiation are not in the immediate context of the function
|
| 690 |
type and can result in the program being ill-formed
|
| 691 |
[[temp.deduct]]. — *end note*]
|
| 692 |
|
| 693 |
+
[*Example 6*:
|
| 694 |
|
| 695 |
``` cpp
|
| 696 |
template <class T> auto f(T t) { return t; } // return type deduced at instantiation time
|
| 697 |
typedef decltype(f(1)) fint_t; // instantiates f<int> to deduce return type
|
| 698 |
template<class T> auto f(T* t) { return *t; }
|
|
|
|
| 705 |
If a function or function template F has a declared return type that
|
| 706 |
uses a placeholder type, redeclarations or specializations of F shall
|
| 707 |
use that placeholder type, not a deduced type; otherwise, they shall not
|
| 708 |
use a placeholder type.
|
| 709 |
|
| 710 |
+
[*Example 7*:
|
| 711 |
|
| 712 |
``` cpp
|
| 713 |
auto f();
|
| 714 |
auto f() { return 42; } // return type is int
|
| 715 |
auto f(); // OK
|
|
|
|
| 750 |
An explicit instantiation declaration [[temp.explicit]] does not cause
|
| 751 |
the instantiation of an entity declared using a placeholder type, but it
|
| 752 |
also does not prevent that entity from being instantiated as needed to
|
| 753 |
determine its type.
|
| 754 |
|
| 755 |
+
[*Example 8*:
|
| 756 |
|
| 757 |
``` cpp
|
| 758 |
template <typename T> auto f(T t) { return t; }
|
| 759 |
extern template auto f(int); // does not instantiate f<int>
|
| 760 |
int (*p)(int) = f; // instantiates f<int> to determine its return type, but an explicit
|
|
|
|
| 800 |
single brace-enclosed *assignment-expression* and E is the
|
| 801 |
*assignment-expression*.
|
| 802 |
- If the initializer is a parenthesized *expression-list*, the
|
| 803 |
*expression-list* shall be a single *assignment-expression* and E is
|
| 804 |
the *assignment-expression*.
|
| 805 |
+
- For a constant template parameter declared with a type that contains a
|
| 806 |
+
placeholder type, `T` is the declared type of the constant template
|
| 807 |
parameter and E is the corresponding template argument.
|
| 808 |
|
| 809 |
`T` shall not be an array type.
|
| 810 |
|
| 811 |
If the *placeholder-type-specifier* is of the form *type-constraint*ₒₚₜ
|
| 812 |
`auto`, the deduced type T' replacing `T` is determined using the rules
|
| 813 |
for template argument deduction. If the initialization is
|
| 814 |
copy-list-initialization, a declaration of `std::initializer_list` shall
|
| 815 |
precede [[basic.lookup.general]] the *placeholder-type-specifier*.
|
| 816 |
+
Obtain `P` from `T` by replacing the occurrence of *type-constraint*ₒₚₜ
|
| 817 |
+
`auto` either with a new invented type template parameter `U` or, if the
|
| 818 |
+
initialization is copy-list-initialization, with
|
| 819 |
+
`std::initializer_list<U>`. Deduce a value for `U` using the rules of
|
| 820 |
+
template argument deduction from a function call [[temp.deduct.call]],
|
| 821 |
+
where `P` is a function template parameter type and the corresponding
|
| 822 |
+
argument is E. If the deduction fails, the declaration is ill-formed.
|
| 823 |
+
Otherwise, T' is obtained by substituting the deduced `U` into `P`.
|
|
|
|
| 824 |
|
| 825 |
+
[*Example 9*:
|
| 826 |
|
| 827 |
``` cpp
|
| 828 |
auto x1 = { 1, 2 }; // decltype(x1) is std::initializer_list<int>
|
| 829 |
auto x2 = { 1, 2.0 }; // error: cannot deduce element type
|
| 830 |
auto x3{ 1, 2 }; // error: not a single element
|
|
|
|
| 832 |
auto x5{ 3 }; // decltype(x5) is int
|
| 833 |
```
|
| 834 |
|
| 835 |
— *end example*]
|
| 836 |
|
| 837 |
+
[*Example 10*:
|
| 838 |
|
| 839 |
``` cpp
|
| 840 |
const auto &i = expr;
|
| 841 |
```
|
| 842 |
|
|
|
|
| 852 |
If the *placeholder-type-specifier* is of the form *type-constraint*ₒₚₜ
|
| 853 |
`decltype(auto)`, `T` shall be the placeholder alone. The type deduced
|
| 854 |
for `T` is determined as described in [[dcl.type.decltype]], as though
|
| 855 |
E had been the operand of the `decltype`.
|
| 856 |
|
| 857 |
+
[*Example 11*:
|
| 858 |
|
| 859 |
``` cpp
|
| 860 |
int i;
|
| 861 |
int&& f();
|
| 862 |
auto x2a(i); // decltype(x2a) is int
|
|
|
|
| 931 |
container e{5, 6}; // error: int is not an iterator
|
| 932 |
```
|
| 933 |
|
| 934 |
— *end example*]
|
| 935 |
|
| 936 |
+
#### Type splicing <a id="dcl.type.splice">[[dcl.type.splice]]</a>
|
| 937 |
+
|
| 938 |
+
``` bnf
|
| 939 |
+
splice-type-specifier:
|
| 940 |
+
typenameₒₚₜ splice-specifier
|
| 941 |
+
typenameₒₚₜ splice-specialization-specifier
|
| 942 |
+
```
|
| 943 |
+
|
| 944 |
+
A *splice-specifier* or *splice-specialization-specifier* immediately
|
| 945 |
+
followed by `::` is never interpreted as part of a
|
| 946 |
+
*splice-type-specifier*. A *splice-specifier* or
|
| 947 |
+
*splice-specialization-specifier* not preceded by `typename` is only
|
| 948 |
+
interpreted as a *splice-type-specifier* within a type-only context
|
| 949 |
+
[[temp.res.general]].
|
| 950 |
+
|
| 951 |
+
[*Example 1*:
|
| 952 |
+
|
| 953 |
+
``` cpp
|
| 954 |
+
template<std::meta::info R> void tfn() {
|
| 955 |
+
typename [:R:]::type m; // OK, typename applies to the qualified name
|
| 956 |
+
}
|
| 957 |
+
|
| 958 |
+
struct S { using type = int; };
|
| 959 |
+
void fn() {
|
| 960 |
+
[:^^S::type:] *var; // error: [:^^ S::type:] is an expression
|
| 961 |
+
typename [:^^S::type:] *var; // OK, declares variable with type int*
|
| 962 |
+
}
|
| 963 |
+
|
| 964 |
+
using alias = [:^^S::type:]; // OK, type-only context
|
| 965 |
+
```
|
| 966 |
+
|
| 967 |
+
— *end example*]
|
| 968 |
+
|
| 969 |
+
For a *splice-type-specifier* of the form `typename`ₒₚₜ
|
| 970 |
+
*splice-specifier*, the *splice-specifier* shall designate a type, a
|
| 971 |
+
class template, or an alias template. The *splice-type-specifier*
|
| 972 |
+
designates the same entity as the *splice-specifier*.
|
| 973 |
+
|
| 974 |
+
For a *splice-type-specifier* of the form `typename`ₒₚₜ
|
| 975 |
+
*splice-specialization-specifier*, the *splice-specifier* of the
|
| 976 |
+
*splice-specialization-specifier* shall designate a template `T` that is
|
| 977 |
+
either a class template or an alias template. The
|
| 978 |
+
*splice-type-specifier* designates the specialization of `T`
|
| 979 |
+
corresponding to the template argument list of the
|
| 980 |
+
*splice-specialization-specifier*.
|
| 981 |
+
|