- tmp/tmpfyuvfhy1/{from.md → to.md} +227 -141
tmp/tmpfyuvfhy1/{from.md → to.md}
RENAMED
|
@@ -1,20 +1,22 @@
|
|
| 1 |
## Attributes <a id="dcl.attr">[[dcl.attr]]</a>
|
| 2 |
|
| 3 |
### Attribute syntax and semantics <a id="dcl.attr.grammar">[[dcl.attr.grammar]]</a>
|
| 4 |
|
| 5 |
-
Attributes specify additional information for various
|
| 6 |
-
such as types, variables, names,
|
|
|
|
| 7 |
|
| 8 |
``` bnf
|
| 9 |
attribute-specifier-seq:
|
| 10 |
-
attribute-specifier-seqₒₚₜ
|
| 11 |
```
|
| 12 |
|
| 13 |
``` bnf
|
| 14 |
attribute-specifier:
|
| 15 |
'[' '[' attribute-using-prefixₒₚₜ attribute-list ']' ']'
|
|
|
|
| 16 |
alignment-specifier
|
| 17 |
```
|
| 18 |
|
| 19 |
``` bnf
|
| 20 |
alignment-specifier:
|
|
@@ -33,15 +35,26 @@ attribute-list:
|
|
| 33 |
attribute-list ',' attributeₒₚₜ
|
| 34 |
attribute '...'
|
| 35 |
attribute-list ',' attribute '...'
|
| 36 |
```
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
``` bnf
|
| 39 |
attribute:
|
| 40 |
attribute-token attribute-argument-clauseₒₚₜ
|
| 41 |
```
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
``` bnf
|
| 44 |
attribute-token:
|
| 45 |
identifier
|
| 46 |
attribute-scoped-token
|
| 47 |
```
|
|
@@ -61,20 +74,20 @@ attribute-argument-clause:
|
|
| 61 |
'(' balanced-token-seqₒₚₜ ')'
|
| 62 |
```
|
| 63 |
|
| 64 |
``` bnf
|
| 65 |
balanced-token-seq:
|
| 66 |
-
balanced-token
|
| 67 |
-
balanced-token-seq balanced-token
|
| 68 |
```
|
| 69 |
|
| 70 |
``` bnf
|
| 71 |
balanced-token:
|
| 72 |
'(' balanced-token-seqₒₚₜ ')'
|
| 73 |
'[' balanced-token-seqₒₚₜ ']'
|
| 74 |
'{' balanced-token-seqₒₚₜ '}'
|
| 75 |
-
|
|
|
|
| 76 |
```
|
| 77 |
|
| 78 |
If an *attribute-specifier* contains an *attribute-using-prefix*, the
|
| 79 |
*attribute-list* following that *attribute-using-prefix* shall not
|
| 80 |
contain an *attribute-scoped-token* and every *attribute-token* in that
|
|
@@ -103,30 +116,34 @@ contain an *attribute-scoped-token* and every *attribute-token* in that
|
|
| 103 |
*balanced-token-seq* will be specified. — *end note*]
|
| 104 |
|
| 105 |
In an *attribute-list*, an ellipsis may appear only if that
|
| 106 |
*attribute*’s specification permits it. An *attribute* followed by an
|
| 107 |
ellipsis is a pack expansion [[temp.variadic]]. An *attribute-specifier*
|
| 108 |
-
that contains no *attribute*s has no effect.
|
| 109 |
-
*attribute-token*s appear in an *attribute-list*
|
| 110 |
-
a keyword [[lex.key]] or an alternative token
|
| 111 |
-
satisfies the syntactic requirements of an
|
| 112 |
-
contained in an *attribute-token*, it is
|
| 113 |
-
name lookup [[basic.lookup]] is performed
|
| 114 |
-
contained in an *attribute-token*. The
|
| 115 |
-
additional requirements on the
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
Each *attribute-specifier-seq* is said to *appertain* to some entity or
|
| 118 |
statement, identified by the syntactic context where it appears
|
| 119 |
-
[[stmt
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
|
| 126 |
-
[*Note 3*: An *attribute-specifier-seq* cannot
|
| 127 |
-
|
| 128 |
|
| 129 |
For an *attribute-token* (including an *attribute-scoped-token*) not
|
| 130 |
specified in this document, the behavior is *implementation-defined*;
|
| 131 |
any such *attribute-token* that is not recognized by the implementation
|
| 132 |
is ignored.
|
|
@@ -277,17 +294,21 @@ present and shall have the form:
|
|
| 277 |
```
|
| 278 |
|
| 279 |
The expression is contextually converted to `bool` [[conv.general]]. The
|
| 280 |
expression is not evaluated. If the converted expression would evaluate
|
| 281 |
to `true` at the point where the assumption appears, the assumption has
|
| 282 |
-
no effect. Otherwise, the
|
|
|
|
| 283 |
|
| 284 |
[*Note 1*: The expression is potentially evaluated [[basic.def.odr]].
|
| 285 |
The use of assumptions is intended to allow implementations to analyze
|
| 286 |
the form of the expression and deduce information used to optimize the
|
| 287 |
program. Implementations are not required to deduce any information from
|
| 288 |
-
any particular assumption.
|
|
|
|
|
|
|
|
|
|
| 289 |
|
| 290 |
[*Example 1*:
|
| 291 |
|
| 292 |
``` cpp
|
| 293 |
int divide_by_32(int x) {
|
|
@@ -301,84 +322,10 @@ int f(int y) {
|
|
| 301 |
}
|
| 302 |
```
|
| 303 |
|
| 304 |
— *end example*]
|
| 305 |
|
| 306 |
-
### Carries dependency attribute <a id="dcl.attr.depend">[[dcl.attr.depend]]</a>
|
| 307 |
-
|
| 308 |
-
The *attribute-token* `carries_dependency` specifies dependency
|
| 309 |
-
propagation into and out of functions. No *attribute-argument-clause*
|
| 310 |
-
shall be present. The attribute may be applied to a parameter of a
|
| 311 |
-
function or lambda, in which case it specifies that the initialization
|
| 312 |
-
of the parameter carries a dependency to [[intro.multithread]] each
|
| 313 |
-
lvalue-to-rvalue conversion [[conv.lval]] of that object. The attribute
|
| 314 |
-
may also be applied to a function or a lambda call operator, in which
|
| 315 |
-
case it specifies that the return value, if any, carries a dependency to
|
| 316 |
-
the evaluation of the function call expression.
|
| 317 |
-
|
| 318 |
-
The first declaration of a function shall specify the
|
| 319 |
-
`carries_dependency` attribute for its *declarator-id* if any
|
| 320 |
-
declaration of the function specifies the `carries_dependency`
|
| 321 |
-
attribute. Furthermore, the first declaration of a function shall
|
| 322 |
-
specify the `carries_dependency` attribute for a parameter if any
|
| 323 |
-
declaration of that function specifies the `carries_dependency`
|
| 324 |
-
attribute for that parameter. If a function or one of its parameters is
|
| 325 |
-
declared with the `carries_dependency` attribute in its first
|
| 326 |
-
declaration in one translation unit and the same function or one of its
|
| 327 |
-
parameters is declared without the `carries_dependency` attribute in its
|
| 328 |
-
first declaration in another translation unit, the program is
|
| 329 |
-
ill-formed, no diagnostic required.
|
| 330 |
-
|
| 331 |
-
[*Note 1*: The `carries_dependency` attribute does not change the
|
| 332 |
-
meaning of the program, but might result in generation of more efficient
|
| 333 |
-
code. — *end note*]
|
| 334 |
-
|
| 335 |
-
[*Example 1*:
|
| 336 |
-
|
| 337 |
-
``` cpp
|
| 338 |
-
/* Translation unit A. */
|
| 339 |
-
|
| 340 |
-
struct foo { int* a; int* b; };
|
| 341 |
-
std::atomic<struct foo *> foo_head[10];
|
| 342 |
-
int foo_array[10][10];
|
| 343 |
-
|
| 344 |
-
[[carries_dependency]] struct foo* f(int i) {
|
| 345 |
-
return foo_head[i].load(memory_order::consume);
|
| 346 |
-
}
|
| 347 |
-
|
| 348 |
-
int g(int* x, int* y [[carries_dependency]]) {
|
| 349 |
-
return kill_dependency(foo_array[*x][*y]);
|
| 350 |
-
}
|
| 351 |
-
|
| 352 |
-
/* Translation unit B. */
|
| 353 |
-
|
| 354 |
-
[[carries_dependency]] struct foo* f(int i);
|
| 355 |
-
int g(int* x, int* y [[carries_dependency]]);
|
| 356 |
-
|
| 357 |
-
int c = 3;
|
| 358 |
-
|
| 359 |
-
void h(int i) {
|
| 360 |
-
struct foo* p;
|
| 361 |
-
|
| 362 |
-
p = f(i);
|
| 363 |
-
do_something_with(g(&c, p->a));
|
| 364 |
-
do_something_with(g(p->a, &c));
|
| 365 |
-
}
|
| 366 |
-
```
|
| 367 |
-
|
| 368 |
-
The `carries_dependency` attribute on function `f` means that the return
|
| 369 |
-
value carries a dependency out of `f`, so that the implementation need
|
| 370 |
-
not constrain ordering upon return from `f`. Implementations of `f` and
|
| 371 |
-
its caller may choose to preserve dependencies instead of emitting
|
| 372 |
-
hardware memory ordering instructions (a.k.a. fences). Function `g`’s
|
| 373 |
-
second parameter has a `carries_dependency` attribute, but its first
|
| 374 |
-
parameter does not. Therefore, function `h`’s first call to `g` carries
|
| 375 |
-
a dependency into `g`, but its second call does not. The implementation
|
| 376 |
-
might need to insert a fence prior to the second call to `g`.
|
| 377 |
-
|
| 378 |
-
— *end example*]
|
| 379 |
-
|
| 380 |
### Deprecated attribute <a id="dcl.attr.deprecated">[[dcl.attr.deprecated]]</a>
|
| 381 |
|
| 382 |
The *attribute-token* `deprecated` can be used to mark names and
|
| 383 |
entities whose use is still allowed, but is discouraged for some reason.
|
| 384 |
|
|
@@ -387,21 +334,20 @@ entities that are deemed obsolescent or unsafe. — *end note*]
|
|
| 387 |
|
| 388 |
An *attribute-argument-clause* may be present and, if present, it shall
|
| 389 |
have the form:
|
| 390 |
|
| 391 |
``` bnf
|
| 392 |
-
'('
|
| 393 |
```
|
| 394 |
|
| 395 |
-
[*Note 2*: The *
|
| 396 |
-
be used to explain the rationale for deprecation and/or to suggest a
|
| 397 |
replacing entity. — *end note*]
|
| 398 |
|
| 399 |
-
The attribute may be applied to the declaration of a class, a
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
specialization.
|
| 403 |
|
| 404 |
An entity declared without the `deprecated` attribute can later be
|
| 405 |
redeclared with the attribute and vice-versa.
|
| 406 |
|
| 407 |
[*Note 3*: Thus, an entity initially declared without the attribute can
|
|
@@ -416,16 +362,18 @@ the *attribute-argument-clause* or with different
|
|
| 416 |
*Recommended practice:* Implementations should use the `deprecated`
|
| 417 |
attribute to produce a diagnostic message in case the program refers to
|
| 418 |
a name or entity other than to declare it, after a declaration that
|
| 419 |
specifies the attribute. The diagnostic message should include the text
|
| 420 |
provided within the *attribute-argument-clause* of any `deprecated`
|
| 421 |
-
attribute applied to the name or entity.
|
|
|
|
|
|
|
| 422 |
|
| 423 |
### Fallthrough attribute <a id="dcl.attr.fallthrough">[[dcl.attr.fallthrough]]</a>
|
| 424 |
|
| 425 |
The *attribute-token* `fallthrough` may be applied to a null statement
|
| 426 |
-
[[stmt.expr]]; such a statement is a fallthrough statement. No
|
| 427 |
*attribute-argument-clause* shall be present. A fallthrough statement
|
| 428 |
may only appear within an enclosing `switch` statement [[stmt.switch]].
|
| 429 |
The next statement that would be executed after a fallthrough statement
|
| 430 |
shall be a labeled statement whose label is a case label or default
|
| 431 |
label for the same `switch` statement and, if the fallthrough statement
|
|
@@ -435,12 +383,15 @@ iteration statement. The program is ill-formed if there is no such
|
|
| 435 |
statement.
|
| 436 |
|
| 437 |
*Recommended practice:* The use of a fallthrough statement should
|
| 438 |
suppress a warning that an implementation might otherwise issue for a
|
| 439 |
case or default label that is reachable from another case or default
|
| 440 |
-
label along some path of execution.
|
| 441 |
-
|
|
|
|
|
|
|
|
|
|
| 442 |
|
| 443 |
[*Example 1*:
|
| 444 |
|
| 445 |
``` cpp
|
| 446 |
void f(int n) {
|
|
@@ -471,30 +422,76 @@ void f(int n) {
|
|
| 471 |
}
|
| 472 |
```
|
| 473 |
|
| 474 |
— *end example*]
|
| 475 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 476 |
### Likelihood attributes <a id="dcl.attr.likelihood">[[dcl.attr.likelihood]]</a>
|
| 477 |
|
| 478 |
The *attribute-token*s `likely` and `unlikely` may be applied to labels
|
| 479 |
or statements. No *attribute-argument-clause* shall be present. The
|
| 480 |
*attribute-token* `likely` shall not appear in an
|
| 481 |
*attribute-specifier-seq* that contains the *attribute-token*
|
| 482 |
`unlikely`.
|
| 483 |
|
| 484 |
-
*
|
| 485 |
-
|
| 486 |
including it are arbitrarily more likely than any alternative path of
|
| 487 |
execution that does not include such an attribute on a statement or
|
| 488 |
label. The use of the `unlikely` attribute is intended to allow
|
| 489 |
implementations to optimize for the case where paths of execution
|
| 490 |
including it are arbitrarily more unlikely than any alternative path of
|
| 491 |
execution that does not include such an attribute on a statement or
|
| 492 |
-
label.
|
| 493 |
-
|
|
|
|
|
|
|
|
|
|
| 494 |
|
| 495 |
-
[*Note
|
| 496 |
result in performance degradation. — *end note*]
|
| 497 |
|
| 498 |
[*Example 1*:
|
| 499 |
|
| 500 |
``` cpp
|
|
@@ -520,41 +517,50 @@ int f(int n) {
|
|
| 520 |
|
| 521 |
— *end example*]
|
| 522 |
|
| 523 |
### Maybe unused attribute <a id="dcl.attr.unused">[[dcl.attr.unused]]</a>
|
| 524 |
|
| 525 |
-
The *attribute-token* `maybe_unused` indicates that a name
|
| 526 |
-
possibly intentionally unused. No *attribute-argument-clause*
|
| 527 |
-
present.
|
| 528 |
|
| 529 |
-
The attribute may be applied to the declaration of a class,
|
| 530 |
-
|
| 531 |
-
|
|
|
|
|
|
|
| 532 |
|
| 533 |
A name or entity declared without the `maybe_unused` attribute can later
|
| 534 |
be redeclared with the attribute and vice versa. An entity is considered
|
| 535 |
marked after the first declaration that marks it.
|
| 536 |
|
| 537 |
*Recommended practice:* For an entity marked `maybe_unused`,
|
| 538 |
implementations should not emit a warning that the entity or its
|
| 539 |
structured bindings (if any) are used or unused. For a structured
|
| 540 |
binding declaration not marked `maybe_unused`, implementations should
|
| 541 |
not emit such a warning unless all of its structured bindings are
|
| 542 |
-
unused.
|
|
|
|
|
|
|
|
|
|
| 543 |
|
| 544 |
[*Example 1*:
|
| 545 |
|
| 546 |
``` cpp
|
| 547 |
[[maybe_unused]] void f([[maybe_unused]] bool thing1,
|
| 548 |
[[maybe_unused]] bool thing2) {
|
| 549 |
[[maybe_unused]] bool b = thing1 && thing2;
|
| 550 |
assert(b);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 551 |
}
|
| 552 |
```
|
| 553 |
|
| 554 |
-
Implementations should not warn that `b` is unused, whether or
|
| 555 |
-
`NDEBUG` is defined.
|
| 556 |
|
| 557 |
— *end example*]
|
| 558 |
|
| 559 |
### Nodiscard attribute <a id="dcl.attr.nodiscard">[[dcl.attr.nodiscard]]</a>
|
| 560 |
|
|
@@ -562,11 +568,11 @@ The *attribute-token* `nodiscard` may be applied to a function or a
|
|
| 562 |
lambda call operator or to the declaration of a class or enumeration. An
|
| 563 |
*attribute-argument-clause* may be present and, if present, shall have
|
| 564 |
the form:
|
| 565 |
|
| 566 |
``` bnf
|
| 567 |
-
'('
|
| 568 |
```
|
| 569 |
|
| 570 |
A name or entity declared without the `nodiscard` attribute can later be
|
| 571 |
redeclared with the attribute and vice-versa.
|
| 572 |
|
|
@@ -591,20 +597,22 @@ is either
|
|
| 591 |
constructs an object through a constructor declared `nodiscard` in a
|
| 592 |
reachable declaration, or that initializes an object of a nodiscard
|
| 593 |
type.
|
| 594 |
|
| 595 |
*Recommended practice:* Appearance of a nodiscard call as a
|
| 596 |
-
potentially-evaluated discarded-value expression [[expr.prop]]
|
| 597 |
-
discouraged unless explicitly cast to `void`.
|
| 598 |
-
issue a warning in such cases.
|
|
|
|
|
|
|
| 599 |
|
| 600 |
[*Note 2*: This is typically because discarding the return value of a
|
| 601 |
nodiscard call has surprising consequences. — *end note*]
|
| 602 |
|
| 603 |
-
The *
|
| 604 |
-
be used in the message of the warning as the rationale for why
|
| 605 |
-
result should not be discarded.
|
| 606 |
|
| 607 |
[*Example 1*:
|
| 608 |
|
| 609 |
``` cpp
|
| 610 |
struct [[nodiscard]] my_scopeguard { ... };
|
|
@@ -643,19 +651,21 @@ declaration of that function specifies the `noreturn` attribute. If a
|
|
| 643 |
function is declared with the `noreturn` attribute in one translation
|
| 644 |
unit and the same function is declared without the `noreturn` attribute
|
| 645 |
in another translation unit, the program is ill-formed, no diagnostic
|
| 646 |
required.
|
| 647 |
|
| 648 |
-
If a function `f` is
|
| 649 |
-
`noreturn` attribute and
|
| 650 |
-
undefined.
|
| 651 |
|
| 652 |
-
[*Note 1*: The function
|
| 653 |
exception. — *end note*]
|
| 654 |
|
| 655 |
*Recommended practice:* Implementations should issue a warning if a
|
| 656 |
-
function marked `[[noreturn]]` might return.
|
|
|
|
|
|
|
| 657 |
|
| 658 |
[*Example 1*:
|
| 659 |
|
| 660 |
``` cpp
|
| 661 |
[[ noreturn ]] void f() {
|
|
@@ -680,10 +690,15 @@ appertain to a non-static data member other than a bit-field.
|
|
| 680 |
[*Note 1*: The non-static data member can share the address of another
|
| 681 |
non-static data member or that of a base class, and any padding that
|
| 682 |
would normally be inserted at the end of the object can be reused as
|
| 683 |
storage for other members. — *end note*]
|
| 684 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 685 |
[*Example 1*:
|
| 686 |
|
| 687 |
``` cpp
|
| 688 |
template<typename Key, typename Value,
|
| 689 |
typename Hash, typename Pred, typename Allocator>
|
|
@@ -701,27 +716,76 @@ public:
|
|
| 701 |
Here, `hasher`, `pred`, and `alloc` could have the same address as
|
| 702 |
`buckets` if their respective types are all empty.
|
| 703 |
|
| 704 |
— *end example*]
|
| 705 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 706 |
<!-- Link reference definitions -->
|
| 707 |
[basic.align]: basic.md#basic.align
|
| 708 |
[basic.compound]: basic.md#basic.compound
|
|
|
|
| 709 |
[basic.def]: basic.md#basic.def
|
| 710 |
[basic.def.odr]: basic.md#basic.def.odr
|
| 711 |
[basic.fundamental]: basic.md#basic.fundamental
|
|
|
|
| 712 |
[basic.life]: basic.md#basic.life
|
| 713 |
[basic.link]: basic.md#basic.link
|
| 714 |
[basic.lookup]: basic.md#basic.lookup
|
| 715 |
[basic.lookup.argdep]: basic.md#basic.lookup.argdep
|
| 716 |
[basic.lookup.elab]: basic.md#basic.lookup.elab
|
| 717 |
[basic.lookup.general]: basic.md#basic.lookup.general
|
| 718 |
[basic.lookup.qual]: basic.md#basic.lookup.qual
|
| 719 |
[basic.lookup.udir]: basic.md#basic.lookup.udir
|
| 720 |
[basic.lookup.unqual]: basic.md#basic.lookup.unqual
|
|
|
|
| 721 |
[basic.namespace]: #basic.namespace
|
| 722 |
[basic.namespace.general]: #basic.namespace.general
|
|
|
|
| 723 |
[basic.scope.namespace]: basic.md#basic.scope.namespace
|
| 724 |
[basic.scope.scope]: basic.md#basic.scope.scope
|
| 725 |
[basic.start]: basic.md#basic.start
|
| 726 |
[basic.start.dynamic]: basic.md#basic.start.dynamic
|
| 727 |
[basic.start.static]: basic.md#basic.start.static
|
|
@@ -736,10 +800,11 @@ Here, `hasher`, `pred`, and `alloc` could have the same address as
|
|
| 736 |
[class]: class.md#class
|
| 737 |
[class.access]: class.md#class.access
|
| 738 |
[class.access.base]: class.md#class.access.base
|
| 739 |
[class.base.init]: class.md#class.base.init
|
| 740 |
[class.bit]: class.md#class.bit
|
|
|
|
| 741 |
[class.conv.ctor]: class.md#class.conv.ctor
|
| 742 |
[class.conv.fct]: class.md#class.conv.fct
|
| 743 |
[class.copy.assign]: class.md#class.copy.assign
|
| 744 |
[class.copy.ctor]: class.md#class.copy.ctor
|
| 745 |
[class.copy.elision]: class.md#class.copy.elision
|
|
@@ -774,37 +839,43 @@ Here, `hasher`, `pred`, and `alloc` could have the same address as
|
|
| 774 |
[conv.ptr]: expr.md#conv.ptr
|
| 775 |
[conv.qual]: expr.md#conv.qual
|
| 776 |
[conv.rval]: expr.md#conv.rval
|
| 777 |
[coroutine.handle]: support.md#coroutine.handle
|
| 778 |
[coroutine.handle.resumption]: support.md#coroutine.handle.resumption
|
|
|
|
|
|
|
| 779 |
[dcl.align]: #dcl.align
|
| 780 |
[dcl.ambig.res]: #dcl.ambig.res
|
| 781 |
[dcl.array]: #dcl.array
|
| 782 |
[dcl.asm]: #dcl.asm
|
| 783 |
[dcl.attr]: #dcl.attr
|
|
|
|
| 784 |
[dcl.attr.assume]: #dcl.attr.assume
|
| 785 |
-
[dcl.attr.depend]: #dcl.attr.depend
|
| 786 |
[dcl.attr.deprecated]: #dcl.attr.deprecated
|
| 787 |
[dcl.attr.fallthrough]: #dcl.attr.fallthrough
|
| 788 |
[dcl.attr.grammar]: #dcl.attr.grammar
|
|
|
|
| 789 |
[dcl.attr.likelihood]: #dcl.attr.likelihood
|
| 790 |
[dcl.attr.nodiscard]: #dcl.attr.nodiscard
|
| 791 |
[dcl.attr.noreturn]: #dcl.attr.noreturn
|
| 792 |
[dcl.attr.nouniqueaddr]: #dcl.attr.nouniqueaddr
|
| 793 |
[dcl.attr.unused]: #dcl.attr.unused
|
| 794 |
[dcl.constexpr]: #dcl.constexpr
|
| 795 |
[dcl.constinit]: #dcl.constinit
|
| 796 |
-
[dcl.
|
|
|
|
|
|
|
| 797 |
[dcl.decl]: #dcl.decl
|
| 798 |
[dcl.decl.general]: #dcl.decl.general
|
| 799 |
[dcl.enum]: #dcl.enum
|
| 800 |
[dcl.fct]: #dcl.fct
|
| 801 |
[dcl.fct.def]: #dcl.fct.def
|
| 802 |
[dcl.fct.def.coroutine]: #dcl.fct.def.coroutine
|
| 803 |
[dcl.fct.def.default]: #dcl.fct.def.default
|
| 804 |
[dcl.fct.def.delete]: #dcl.fct.def.delete
|
| 805 |
[dcl.fct.def.general]: #dcl.fct.def.general
|
|
|
|
| 806 |
[dcl.fct.default]: #dcl.fct.default
|
| 807 |
[dcl.fct.spec]: #dcl.fct.spec
|
| 808 |
[dcl.friend]: #dcl.friend
|
| 809 |
[dcl.init]: #dcl.init
|
| 810 |
[dcl.init.aggr]: #dcl.init.aggr
|
|
@@ -832,53 +903,63 @@ Here, `hasher`, `pred`, and `alloc` could have the same address as
|
|
| 832 |
[dcl.type.class.deduct]: #dcl.type.class.deduct
|
| 833 |
[dcl.type.cv]: #dcl.type.cv
|
| 834 |
[dcl.type.decltype]: #dcl.type.decltype
|
| 835 |
[dcl.type.elab]: #dcl.type.elab
|
| 836 |
[dcl.type.general]: #dcl.type.general
|
|
|
|
| 837 |
[dcl.type.simple]: #dcl.type.simple
|
|
|
|
| 838 |
[dcl.typedef]: #dcl.typedef
|
|
|
|
| 839 |
[depr.volatile.type]: future.md#depr.volatile.type
|
| 840 |
[enum]: #enum
|
| 841 |
[enum.udecl]: #enum.udecl
|
| 842 |
[except.ctor]: except.md#except.ctor
|
| 843 |
[except.handle]: except.md#except.handle
|
| 844 |
[except.pre]: except.md#except.pre
|
| 845 |
[except.spec]: except.md#except.spec
|
| 846 |
[except.throw]: except.md#except.throw
|
| 847 |
[expr.alignof]: expr.md#expr.alignof
|
| 848 |
-
[expr.
|
| 849 |
[expr.await]: expr.md#expr.await
|
| 850 |
[expr.call]: expr.md#expr.call
|
| 851 |
[expr.cast]: expr.md#expr.cast
|
| 852 |
[expr.comma]: expr.md#expr.comma
|
| 853 |
[expr.const]: expr.md#expr.const
|
| 854 |
[expr.const.cast]: expr.md#expr.const.cast
|
| 855 |
[expr.mptr.oper]: expr.md#expr.mptr.oper
|
| 856 |
[expr.new]: expr.md#expr.new
|
| 857 |
[expr.post.incr]: expr.md#expr.post.incr
|
| 858 |
[expr.pre.incr]: expr.md#expr.pre.incr
|
|
|
|
| 859 |
[expr.prim.id.unqual]: expr.md#expr.prim.id.unqual
|
| 860 |
[expr.prim.lambda]: expr.md#expr.prim.lambda
|
|
|
|
| 861 |
[expr.prim.this]: expr.md#expr.prim.this
|
| 862 |
[expr.prop]: expr.md#expr.prop
|
| 863 |
[expr.ref]: expr.md#expr.ref
|
|
|
|
| 864 |
[expr.static.cast]: expr.md#expr.static.cast
|
| 865 |
[expr.sub]: expr.md#expr.sub
|
|
|
|
| 866 |
[expr.type.conv]: expr.md#expr.type.conv
|
| 867 |
[expr.unary]: expr.md#expr.unary
|
| 868 |
[expr.unary.op]: expr.md#expr.unary.op
|
| 869 |
[expr.yield]: expr.md#expr.yield
|
| 870 |
[initializer.list.syn]: support.md#initializer.list.syn
|
| 871 |
[intro.abstract]: intro.md#intro.abstract
|
| 872 |
-
[intro.compliance]: intro.md#intro.compliance
|
| 873 |
[intro.execution]: basic.md#intro.execution
|
| 874 |
-
[intro.multithread]: basic.md#intro.multithread
|
| 875 |
[intro.object]: basic.md#intro.object
|
|
|
|
|
|
|
| 876 |
[lex.digraph]: lex.md#lex.digraph
|
| 877 |
[lex.key]: lex.md#lex.key
|
| 878 |
[lex.name]: lex.md#lex.name
|
|
|
|
| 879 |
[lex.string]: lex.md#lex.string
|
|
|
|
|
|
|
| 880 |
[module.interface]: module.md#module.interface
|
| 881 |
[module.reach]: module.md#module.reach
|
| 882 |
[module.unit]: module.md#module.unit
|
| 883 |
[namespace.alias]: #namespace.alias
|
| 884 |
[namespace.def]: #namespace.def
|
|
@@ -902,21 +983,24 @@ Here, `hasher`, `pred`, and `alloc` could have the same address as
|
|
| 902 |
[over.match.viable]: over.md#over.match.viable
|
| 903 |
[over.oper]: over.md#over.oper
|
| 904 |
[over.sub]: over.md#over.sub
|
| 905 |
[special]: class.md#special
|
| 906 |
[std.modules]: library.md#std.modules
|
|
|
|
| 907 |
[stmt.ambig]: stmt.md#stmt.ambig
|
| 908 |
[stmt.dcl]: stmt.md#stmt.dcl
|
| 909 |
[stmt.expr]: stmt.md#stmt.expr
|
| 910 |
[stmt.if]: stmt.md#stmt.if
|
| 911 |
[stmt.iter]: stmt.md#stmt.iter
|
|
|
|
|
|
|
| 912 |
[stmt.return]: stmt.md#stmt.return
|
| 913 |
[stmt.return.coroutine]: stmt.md#stmt.return.coroutine
|
| 914 |
[stmt.select]: stmt.md#stmt.select
|
| 915 |
-
[stmt.stmt]: stmt.md#stmt.stmt
|
| 916 |
[stmt.switch]: stmt.md#stmt.switch
|
| 917 |
[support.runtime]: support.md#support.runtime
|
|
|
|
| 918 |
[temp.arg.type]: temp.md#temp.arg.type
|
| 919 |
[temp.decls]: temp.md#temp.decls
|
| 920 |
[temp.deduct]: temp.md#temp.deduct
|
| 921 |
[temp.deduct.call]: temp.md#temp.deduct.call
|
| 922 |
[temp.deduct.decl]: temp.md#temp.deduct.decl
|
|
@@ -929,10 +1013,12 @@ Here, `hasher`, `pred`, and `alloc` could have the same address as
|
|
| 929 |
[temp.local]: temp.md#temp.local
|
| 930 |
[temp.names]: temp.md#temp.names
|
| 931 |
[temp.param]: temp.md#temp.param
|
| 932 |
[temp.pre]: temp.md#temp.pre
|
| 933 |
[temp.res]: temp.md#temp.res
|
|
|
|
|
|
|
| 934 |
[temp.spec.partial]: temp.md#temp.spec.partial
|
| 935 |
[temp.variadic]: temp.md#temp.variadic
|
| 936 |
[term.odr.use]: basic.md#term.odr.use
|
| 937 |
[term.padding.bits]: basic.md#term.padding.bits
|
| 938 |
[term.scalar.type]: basic.md#term.scalar.type
|
|
|
|
| 1 |
## Attributes <a id="dcl.attr">[[dcl.attr]]</a>
|
| 2 |
|
| 3 |
### Attribute syntax and semantics <a id="dcl.attr.grammar">[[dcl.attr.grammar]]</a>
|
| 4 |
|
| 5 |
+
Attributes and annotations specify additional information for various
|
| 6 |
+
source constructs such as types, variables, names, contract assertions,
|
| 7 |
+
blocks, or translation units.
|
| 8 |
|
| 9 |
``` bnf
|
| 10 |
attribute-specifier-seq:
|
| 11 |
+
attribute-specifier attribute-specifier-seqₒₚₜ
|
| 12 |
```
|
| 13 |
|
| 14 |
``` bnf
|
| 15 |
attribute-specifier:
|
| 16 |
'[' '[' attribute-using-prefixₒₚₜ attribute-list ']' ']'
|
| 17 |
+
'[' '[' annotation-list ']' ']'
|
| 18 |
alignment-specifier
|
| 19 |
```
|
| 20 |
|
| 21 |
``` bnf
|
| 22 |
alignment-specifier:
|
|
|
|
| 35 |
attribute-list ',' attributeₒₚₜ
|
| 36 |
attribute '...'
|
| 37 |
attribute-list ',' attribute '...'
|
| 38 |
```
|
| 39 |
|
| 40 |
+
``` bnf
|
| 41 |
+
annotation-list:
|
| 42 |
+
annotation '...'ₒₚₜ
|
| 43 |
+
annotation-list ',' annotation '...'ₒₚₜ
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
``` bnf
|
| 47 |
attribute:
|
| 48 |
attribute-token attribute-argument-clauseₒₚₜ
|
| 49 |
```
|
| 50 |
|
| 51 |
+
``` bnf
|
| 52 |
+
annotation:
|
| 53 |
+
'=' constant-expression
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
``` bnf
|
| 57 |
attribute-token:
|
| 58 |
identifier
|
| 59 |
attribute-scoped-token
|
| 60 |
```
|
|
|
|
| 74 |
'(' balanced-token-seqₒₚₜ ')'
|
| 75 |
```
|
| 76 |
|
| 77 |
``` bnf
|
| 78 |
balanced-token-seq:
|
| 79 |
+
balanced-token balanced-token-seqₒₚₜ
|
|
|
|
| 80 |
```
|
| 81 |
|
| 82 |
``` bnf
|
| 83 |
balanced-token:
|
| 84 |
'(' balanced-token-seqₒₚₜ ')'
|
| 85 |
'[' balanced-token-seqₒₚₜ ']'
|
| 86 |
'{' balanced-token-seqₒₚₜ '}'
|
| 87 |
+
'[:' balanced-token-seqₒₚₜ ':]'
|
| 88 |
+
any *token* other than '(', ')', '[', ']', '{', '}', '[:', or ':]'
|
| 89 |
```
|
| 90 |
|
| 91 |
If an *attribute-specifier* contains an *attribute-using-prefix*, the
|
| 92 |
*attribute-list* following that *attribute-using-prefix* shall not
|
| 93 |
contain an *attribute-scoped-token* and every *attribute-token* in that
|
|
|
|
| 116 |
*balanced-token-seq* will be specified. — *end note*]
|
| 117 |
|
| 118 |
In an *attribute-list*, an ellipsis may appear only if that
|
| 119 |
*attribute*’s specification permits it. An *attribute* followed by an
|
| 120 |
ellipsis is a pack expansion [[temp.variadic]]. An *attribute-specifier*
|
| 121 |
+
that contains an *attribute-list* with no *attribute*s has no effect.
|
| 122 |
+
The order in which the *attribute-token*s appear in an *attribute-list*
|
| 123 |
+
is not significant. If a keyword [[lex.key]] or an alternative token
|
| 124 |
+
[[lex.digraph]] that satisfies the syntactic requirements of an
|
| 125 |
+
*identifier* [[lex.name]] is contained in an *attribute-token*, it is
|
| 126 |
+
considered an identifier. No name lookup [[basic.lookup]] is performed
|
| 127 |
+
on any of the identifiers contained in an *attribute-token*. The
|
| 128 |
+
*attribute-token* determines additional requirements on the
|
| 129 |
+
*attribute-argument-clause* (if any).
|
| 130 |
+
|
| 131 |
+
An *annotation* followed by an ellipsis is a pack expansion
|
| 132 |
+
[[temp.variadic]].
|
| 133 |
|
| 134 |
Each *attribute-specifier-seq* is said to *appertain* to some entity or
|
| 135 |
statement, identified by the syntactic context where it appears
|
| 136 |
+
[[stmt]], [[dcl]], [[dcl.decl]]. If an *attribute-specifier-seq* that
|
| 137 |
+
appertains to some entity or statement contains an *attribute* or
|
| 138 |
+
*alignment-specifier* that is not allowed to apply to that entity or
|
| 139 |
+
statement, the program is ill-formed. If an *attribute-specifier-seq*
|
| 140 |
+
appertains to a friend declaration [[class.friend]], that declaration
|
| 141 |
+
shall be a definition.
|
| 142 |
|
| 143 |
+
[*Note 3*: An *attribute-specifier-seq* cannot appertain to an explicit
|
| 144 |
+
instantiation [[temp.explicit]]. — *end note*]
|
| 145 |
|
| 146 |
For an *attribute-token* (including an *attribute-scoped-token*) not
|
| 147 |
specified in this document, the behavior is *implementation-defined*;
|
| 148 |
any such *attribute-token* that is not recognized by the implementation
|
| 149 |
is ignored.
|
|
|
|
| 294 |
```
|
| 295 |
|
| 296 |
The expression is contextually converted to `bool` [[conv.general]]. The
|
| 297 |
expression is not evaluated. If the converted expression would evaluate
|
| 298 |
to `true` at the point where the assumption appears, the assumption has
|
| 299 |
+
no effect. Otherwise, evaluation of the assumption has runtime-undefined
|
| 300 |
+
behavior.
|
| 301 |
|
| 302 |
[*Note 1*: The expression is potentially evaluated [[basic.def.odr]].
|
| 303 |
The use of assumptions is intended to allow implementations to analyze
|
| 304 |
the form of the expression and deduce information used to optimize the
|
| 305 |
program. Implementations are not required to deduce any information from
|
| 306 |
+
any particular assumption. It is expected that the value of a
|
| 307 |
+
*has-attribute-expression* for the `assume` attribute is `0` if an
|
| 308 |
+
implementation does not attempt to deduce any such information from
|
| 309 |
+
assumptions. — *end note*]
|
| 310 |
|
| 311 |
[*Example 1*:
|
| 312 |
|
| 313 |
``` cpp
|
| 314 |
int divide_by_32(int x) {
|
|
|
|
| 322 |
}
|
| 323 |
```
|
| 324 |
|
| 325 |
— *end example*]
|
| 326 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
### Deprecated attribute <a id="dcl.attr.deprecated">[[dcl.attr.deprecated]]</a>
|
| 328 |
|
| 329 |
The *attribute-token* `deprecated` can be used to mark names and
|
| 330 |
entities whose use is still allowed, but is discouraged for some reason.
|
| 331 |
|
|
|
|
| 334 |
|
| 335 |
An *attribute-argument-clause* may be present and, if present, it shall
|
| 336 |
have the form:
|
| 337 |
|
| 338 |
``` bnf
|
| 339 |
+
'(' unevaluated-string ')'
|
| 340 |
```
|
| 341 |
|
| 342 |
+
[*Note 2*: The *unevaluated-string* in the *attribute-argument-clause*
|
| 343 |
+
can be used to explain the rationale for deprecation and/or to suggest a
|
| 344 |
replacing entity. — *end note*]
|
| 345 |
|
| 346 |
+
The attribute may be applied to the declaration of a class, a type
|
| 347 |
+
alias, a variable, a non-static data member, a function, a namespace, an
|
| 348 |
+
enumeration, an enumerator, a concept, or a template specialization.
|
|
|
|
| 349 |
|
| 350 |
An entity declared without the `deprecated` attribute can later be
|
| 351 |
redeclared with the attribute and vice-versa.
|
| 352 |
|
| 353 |
[*Note 3*: Thus, an entity initially declared without the attribute can
|
|
|
|
| 362 |
*Recommended practice:* Implementations should use the `deprecated`
|
| 363 |
attribute to produce a diagnostic message in case the program refers to
|
| 364 |
a name or entity other than to declare it, after a declaration that
|
| 365 |
specifies the attribute. The diagnostic message should include the text
|
| 366 |
provided within the *attribute-argument-clause* of any `deprecated`
|
| 367 |
+
attribute applied to the name or entity. The value of a
|
| 368 |
+
*has-attribute-expression* for the `deprecated` attribute should be `0`
|
| 369 |
+
unless the implementation can issue such diagnostic messages.
|
| 370 |
|
| 371 |
### Fallthrough attribute <a id="dcl.attr.fallthrough">[[dcl.attr.fallthrough]]</a>
|
| 372 |
|
| 373 |
The *attribute-token* `fallthrough` may be applied to a null statement
|
| 374 |
+
[[stmt.expr]]; such a statement is a *fallthrough statement*. No
|
| 375 |
*attribute-argument-clause* shall be present. A fallthrough statement
|
| 376 |
may only appear within an enclosing `switch` statement [[stmt.switch]].
|
| 377 |
The next statement that would be executed after a fallthrough statement
|
| 378 |
shall be a labeled statement whose label is a case label or default
|
| 379 |
label for the same `switch` statement and, if the fallthrough statement
|
|
|
|
| 383 |
statement.
|
| 384 |
|
| 385 |
*Recommended practice:* The use of a fallthrough statement should
|
| 386 |
suppress a warning that an implementation might otherwise issue for a
|
| 387 |
case or default label that is reachable from another case or default
|
| 388 |
+
label along some path of execution. The value of a
|
| 389 |
+
*has-attribute-expression* for the `fallthrough` attribute should be `0`
|
| 390 |
+
if the attribute does not cause suppression of such warnings.
|
| 391 |
+
Implementations should issue a warning if a fallthrough statement is not
|
| 392 |
+
dynamically reachable.
|
| 393 |
|
| 394 |
[*Example 1*:
|
| 395 |
|
| 396 |
``` cpp
|
| 397 |
void f(int n) {
|
|
|
|
| 422 |
}
|
| 423 |
```
|
| 424 |
|
| 425 |
— *end example*]
|
| 426 |
|
| 427 |
+
### Indeterminate storage <a id="dcl.attr.indet">[[dcl.attr.indet]]</a>
|
| 428 |
+
|
| 429 |
+
The *attribute-token* `indeterminate` may be applied to the definition
|
| 430 |
+
of a block variable with automatic storage duration or to a
|
| 431 |
+
*parameter-declaration* of a function declaration. No
|
| 432 |
+
*attribute-argument-clause* shall be present. The attribute specifies
|
| 433 |
+
that the storage of an object with automatic storage duration is
|
| 434 |
+
initially indeterminate rather than erroneous [[basic.indet]].
|
| 435 |
+
|
| 436 |
+
If a function parameter is declared with the `indeterminate` attribute,
|
| 437 |
+
it shall be so declared in the first declaration of its function. If a
|
| 438 |
+
function parameter is declared with the `indeterminate` attribute in the
|
| 439 |
+
first declaration of its function in one translation unit and the same
|
| 440 |
+
function is declared without the `indeterminate` attribute on the same
|
| 441 |
+
parameter in its first declaration in another translation unit, the
|
| 442 |
+
program is ill-formed, no diagnostic required.
|
| 443 |
+
|
| 444 |
+
[*Note 1*:
|
| 445 |
+
|
| 446 |
+
Reading from an uninitialized variable that is marked
|
| 447 |
+
`[[indeterminate]]` can cause undefined behavior.
|
| 448 |
+
|
| 449 |
+
``` cpp
|
| 450 |
+
void f(int);
|
| 451 |
+
void g() {
|
| 452 |
+
int x [[indeterminate]], y;
|
| 453 |
+
f(y); // erroneous behavior[basic.indet]
|
| 454 |
+
f(x); // undefined behavior
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
struct T {
|
| 458 |
+
T() {}
|
| 459 |
+
int x;
|
| 460 |
+
};
|
| 461 |
+
int h(T t [[indeterminate]]) {
|
| 462 |
+
f(t.x); // undefined behavior when called below
|
| 463 |
+
return 0;
|
| 464 |
+
}
|
| 465 |
+
int _ = h(T());
|
| 466 |
+
```
|
| 467 |
+
|
| 468 |
+
— *end note*]
|
| 469 |
+
|
| 470 |
### Likelihood attributes <a id="dcl.attr.likelihood">[[dcl.attr.likelihood]]</a>
|
| 471 |
|
| 472 |
The *attribute-token*s `likely` and `unlikely` may be applied to labels
|
| 473 |
or statements. No *attribute-argument-clause* shall be present. The
|
| 474 |
*attribute-token* `likely` shall not appear in an
|
| 475 |
*attribute-specifier-seq* that contains the *attribute-token*
|
| 476 |
`unlikely`.
|
| 477 |
|
| 478 |
+
[*Note 1*: The use of the `likely` attribute is intended to allow
|
| 479 |
+
implementations to optimize for the case where paths of execution
|
| 480 |
including it are arbitrarily more likely than any alternative path of
|
| 481 |
execution that does not include such an attribute on a statement or
|
| 482 |
label. The use of the `unlikely` attribute is intended to allow
|
| 483 |
implementations to optimize for the case where paths of execution
|
| 484 |
including it are arbitrarily more unlikely than any alternative path of
|
| 485 |
execution that does not include such an attribute on a statement or
|
| 486 |
+
label. It is expected that the value of a *has-attribute-expression* for
|
| 487 |
+
the `likely` and `unlikely` attributes is `0` if the implementation does
|
| 488 |
+
not attempt to use these attributes for such optimizations. A path of
|
| 489 |
+
execution includes a label if and only if it contains a jump to that
|
| 490 |
+
label. — *end note*]
|
| 491 |
|
| 492 |
+
[*Note 2*: Excessive usage of either of these attributes is liable to
|
| 493 |
result in performance degradation. — *end note*]
|
| 494 |
|
| 495 |
[*Example 1*:
|
| 496 |
|
| 497 |
``` cpp
|
|
|
|
| 517 |
|
| 518 |
— *end example*]
|
| 519 |
|
| 520 |
### Maybe unused attribute <a id="dcl.attr.unused">[[dcl.attr.unused]]</a>
|
| 521 |
|
| 522 |
+
The *attribute-token* `maybe_unused` indicates that a name, label, or
|
| 523 |
+
entity is possibly intentionally unused. No *attribute-argument-clause*
|
| 524 |
+
shall be present.
|
| 525 |
|
| 526 |
+
The attribute may be applied to the declaration of a class, type alias,
|
| 527 |
+
variable (including a structured binding declaration), structured
|
| 528 |
+
binding, result binding [[dcl.contract.res]], non-static data member,
|
| 529 |
+
function, enumeration, or enumerator, or to an *identifier* label
|
| 530 |
+
[[stmt.label]].
|
| 531 |
|
| 532 |
A name or entity declared without the `maybe_unused` attribute can later
|
| 533 |
be redeclared with the attribute and vice versa. An entity is considered
|
| 534 |
marked after the first declaration that marks it.
|
| 535 |
|
| 536 |
*Recommended practice:* For an entity marked `maybe_unused`,
|
| 537 |
implementations should not emit a warning that the entity or its
|
| 538 |
structured bindings (if any) are used or unused. For a structured
|
| 539 |
binding declaration not marked `maybe_unused`, implementations should
|
| 540 |
not emit such a warning unless all of its structured bindings are
|
| 541 |
+
unused. For a label to which `maybe_unused` is applied, implementations
|
| 542 |
+
should not emit a warning that the label is used or unused. The value of
|
| 543 |
+
a *has-attribute-expression* for the `maybe_unused` attribute should be
|
| 544 |
+
`0` if the attribute does not cause suppression of such warnings.
|
| 545 |
|
| 546 |
[*Example 1*:
|
| 547 |
|
| 548 |
``` cpp
|
| 549 |
[[maybe_unused]] void f([[maybe_unused]] bool thing1,
|
| 550 |
[[maybe_unused]] bool thing2) {
|
| 551 |
[[maybe_unused]] bool b = thing1 && thing2;
|
| 552 |
assert(b);
|
| 553 |
+
#ifdef NDEBUG
|
| 554 |
+
goto x;
|
| 555 |
+
#endif
|
| 556 |
+
[[maybe_unused]] x:
|
| 557 |
}
|
| 558 |
```
|
| 559 |
|
| 560 |
+
Implementations should not warn that `b` or `x` is unused, whether or
|
| 561 |
+
not `NDEBUG` is defined.
|
| 562 |
|
| 563 |
— *end example*]
|
| 564 |
|
| 565 |
### Nodiscard attribute <a id="dcl.attr.nodiscard">[[dcl.attr.nodiscard]]</a>
|
| 566 |
|
|
|
|
| 568 |
lambda call operator or to the declaration of a class or enumeration. An
|
| 569 |
*attribute-argument-clause* may be present and, if present, shall have
|
| 570 |
the form:
|
| 571 |
|
| 572 |
``` bnf
|
| 573 |
+
'(' unevaluated-string ')'
|
| 574 |
```
|
| 575 |
|
| 576 |
A name or entity declared without the `nodiscard` attribute can later be
|
| 577 |
redeclared with the attribute and vice-versa.
|
| 578 |
|
|
|
|
| 597 |
constructs an object through a constructor declared `nodiscard` in a
|
| 598 |
reachable declaration, or that initializes an object of a nodiscard
|
| 599 |
type.
|
| 600 |
|
| 601 |
*Recommended practice:* Appearance of a nodiscard call as a
|
| 602 |
+
potentially-evaluated discarded-value expression [[expr.prop]] of
|
| 603 |
+
non-void type is discouraged unless explicitly cast to `void`.
|
| 604 |
+
Implementations should issue a warning in such cases. The value of a
|
| 605 |
+
*has-attribute-expression* for the `nodiscard` attribute should be `0`
|
| 606 |
+
unless the implementation can issue such warnings.
|
| 607 |
|
| 608 |
[*Note 2*: This is typically because discarding the return value of a
|
| 609 |
nodiscard call has surprising consequences. — *end note*]
|
| 610 |
|
| 611 |
+
The *unevaluated-string* in a `nodiscard` *attribute-argument-clause*
|
| 612 |
+
should be used in the message of the warning as the rationale for why
|
| 613 |
+
the result should not be discarded.
|
| 614 |
|
| 615 |
[*Example 1*:
|
| 616 |
|
| 617 |
``` cpp
|
| 618 |
struct [[nodiscard]] my_scopeguard { ... };
|
|
|
|
| 651 |
function is declared with the `noreturn` attribute in one translation
|
| 652 |
unit and the same function is declared without the `noreturn` attribute
|
| 653 |
in another translation unit, the program is ill-formed, no diagnostic
|
| 654 |
required.
|
| 655 |
|
| 656 |
+
If a function `f` is invoked where `f` was previously declared with the
|
| 657 |
+
`noreturn` attribute and that invocation eventually returns, the
|
| 658 |
+
behavior is runtime-undefined.
|
| 659 |
|
| 660 |
+
[*Note 1*: The function can terminate by throwing an
|
| 661 |
exception. — *end note*]
|
| 662 |
|
| 663 |
*Recommended practice:* Implementations should issue a warning if a
|
| 664 |
+
function marked `[[noreturn]]` might return. The value of a
|
| 665 |
+
*has-attribute-expression* for the `noreturn` attribute should be `0`
|
| 666 |
+
unless the implementation can issue such warnings.
|
| 667 |
|
| 668 |
[*Example 1*:
|
| 669 |
|
| 670 |
``` cpp
|
| 671 |
[[ noreturn ]] void f() {
|
|
|
|
| 690 |
[*Note 1*: The non-static data member can share the address of another
|
| 691 |
non-static data member or that of a base class, and any padding that
|
| 692 |
would normally be inserted at the end of the object can be reused as
|
| 693 |
storage for other members. — *end note*]
|
| 694 |
|
| 695 |
+
*Recommended practice:* The value of a *has-attribute-expression* for
|
| 696 |
+
the `no_unique_address` attribute should be `0` for a given
|
| 697 |
+
implementation unless this attribute can cause a potentially-overlapping
|
| 698 |
+
subobject to have zero size.
|
| 699 |
+
|
| 700 |
[*Example 1*:
|
| 701 |
|
| 702 |
``` cpp
|
| 703 |
template<typename Key, typename Value,
|
| 704 |
typename Hash, typename Pred, typename Allocator>
|
|
|
|
| 716 |
Here, `hasher`, `pred`, and `alloc` could have the same address as
|
| 717 |
`buckets` if their respective types are all empty.
|
| 718 |
|
| 719 |
— *end example*]
|
| 720 |
|
| 721 |
+
### Annotations <a id="dcl.attr.annotation">[[dcl.attr.annotation]]</a>
|
| 722 |
+
|
| 723 |
+
An annotation may be applied to any declaration of a type, type alias,
|
| 724 |
+
variable, function, namespace, enumerator, *base-specifier*, or
|
| 725 |
+
non-static data member.
|
| 726 |
+
|
| 727 |
+
Let E be the expression
|
| 728 |
+
`std::meta::reflect_constant(constant-expression)`. E shall be a
|
| 729 |
+
constant expression; the result of E is the *underlying constant* of the
|
| 730 |
+
annotation.
|
| 731 |
+
|
| 732 |
+
Each *annotation* produces a unique annotation.
|
| 733 |
+
|
| 734 |
+
Substituting into an *annotation* is not in the immediate context.
|
| 735 |
+
|
| 736 |
+
[*Example 1*:
|
| 737 |
+
|
| 738 |
+
``` cpp
|
| 739 |
+
[[=1]] void f();
|
| 740 |
+
[[=2, =3, =2]] void g();
|
| 741 |
+
void g [[=4, =2]] ();
|
| 742 |
+
```
|
| 743 |
+
|
| 744 |
+
`f` has one annotation and `g` has five annotations. These can be
|
| 745 |
+
queried with metafunctions such as `std::{}meta::{}annotations_of`
|
| 746 |
+
[[meta.reflection.annotation]].
|
| 747 |
+
|
| 748 |
+
— *end example*]
|
| 749 |
+
|
| 750 |
+
[*Example 2*:
|
| 751 |
+
|
| 752 |
+
``` cpp
|
| 753 |
+
template<class T>
|
| 754 |
+
[[=T::type()]] void f(T t);
|
| 755 |
+
|
| 756 |
+
void f(int);
|
| 757 |
+
|
| 758 |
+
void g() {
|
| 759 |
+
f(0); // OK
|
| 760 |
+
f('0'); // error, substituting into the annotation results in an invalid expression
|
| 761 |
+
}
|
| 762 |
+
```
|
| 763 |
+
|
| 764 |
+
— *end example*]
|
| 765 |
+
|
| 766 |
<!-- Link reference definitions -->
|
| 767 |
[basic.align]: basic.md#basic.align
|
| 768 |
[basic.compound]: basic.md#basic.compound
|
| 769 |
+
[basic.contract.general]: basic.md#basic.contract.general
|
| 770 |
[basic.def]: basic.md#basic.def
|
| 771 |
[basic.def.odr]: basic.md#basic.def.odr
|
| 772 |
[basic.fundamental]: basic.md#basic.fundamental
|
| 773 |
+
[basic.indet]: basic.md#basic.indet
|
| 774 |
[basic.life]: basic.md#basic.life
|
| 775 |
[basic.link]: basic.md#basic.link
|
| 776 |
[basic.lookup]: basic.md#basic.lookup
|
| 777 |
[basic.lookup.argdep]: basic.md#basic.lookup.argdep
|
| 778 |
[basic.lookup.elab]: basic.md#basic.lookup.elab
|
| 779 |
[basic.lookup.general]: basic.md#basic.lookup.general
|
| 780 |
[basic.lookup.qual]: basic.md#basic.lookup.qual
|
| 781 |
[basic.lookup.udir]: basic.md#basic.lookup.udir
|
| 782 |
[basic.lookup.unqual]: basic.md#basic.lookup.unqual
|
| 783 |
+
[basic.lval]: expr.md#basic.lval
|
| 784 |
[basic.namespace]: #basic.namespace
|
| 785 |
[basic.namespace.general]: #basic.namespace.general
|
| 786 |
+
[basic.pre]: basic.md#basic.pre
|
| 787 |
[basic.scope.namespace]: basic.md#basic.scope.namespace
|
| 788 |
[basic.scope.scope]: basic.md#basic.scope.scope
|
| 789 |
[basic.start]: basic.md#basic.start
|
| 790 |
[basic.start.dynamic]: basic.md#basic.start.dynamic
|
| 791 |
[basic.start.static]: basic.md#basic.start.static
|
|
|
|
| 800 |
[class]: class.md#class
|
| 801 |
[class.access]: class.md#class.access
|
| 802 |
[class.access.base]: class.md#class.access.base
|
| 803 |
[class.base.init]: class.md#class.base.init
|
| 804 |
[class.bit]: class.md#class.bit
|
| 805 |
+
[class.compare.default]: class.md#class.compare.default
|
| 806 |
[class.conv.ctor]: class.md#class.conv.ctor
|
| 807 |
[class.conv.fct]: class.md#class.conv.fct
|
| 808 |
[class.copy.assign]: class.md#class.copy.assign
|
| 809 |
[class.copy.ctor]: class.md#class.copy.ctor
|
| 810 |
[class.copy.elision]: class.md#class.copy.elision
|
|
|
|
| 839 |
[conv.ptr]: expr.md#conv.ptr
|
| 840 |
[conv.qual]: expr.md#conv.qual
|
| 841 |
[conv.rval]: expr.md#conv.rval
|
| 842 |
[coroutine.handle]: support.md#coroutine.handle
|
| 843 |
[coroutine.handle.resumption]: support.md#coroutine.handle.resumption
|
| 844 |
+
[csetjmp.syn]: support.md#csetjmp.syn
|
| 845 |
+
[dcl]: #dcl
|
| 846 |
[dcl.align]: #dcl.align
|
| 847 |
[dcl.ambig.res]: #dcl.ambig.res
|
| 848 |
[dcl.array]: #dcl.array
|
| 849 |
[dcl.asm]: #dcl.asm
|
| 850 |
[dcl.attr]: #dcl.attr
|
| 851 |
+
[dcl.attr.annotation]: #dcl.attr.annotation
|
| 852 |
[dcl.attr.assume]: #dcl.attr.assume
|
|
|
|
| 853 |
[dcl.attr.deprecated]: #dcl.attr.deprecated
|
| 854 |
[dcl.attr.fallthrough]: #dcl.attr.fallthrough
|
| 855 |
[dcl.attr.grammar]: #dcl.attr.grammar
|
| 856 |
+
[dcl.attr.indet]: #dcl.attr.indet
|
| 857 |
[dcl.attr.likelihood]: #dcl.attr.likelihood
|
| 858 |
[dcl.attr.nodiscard]: #dcl.attr.nodiscard
|
| 859 |
[dcl.attr.noreturn]: #dcl.attr.noreturn
|
| 860 |
[dcl.attr.nouniqueaddr]: #dcl.attr.nouniqueaddr
|
| 861 |
[dcl.attr.unused]: #dcl.attr.unused
|
| 862 |
[dcl.constexpr]: #dcl.constexpr
|
| 863 |
[dcl.constinit]: #dcl.constinit
|
| 864 |
+
[dcl.contract]: #dcl.contract
|
| 865 |
+
[dcl.contract.func]: #dcl.contract.func
|
| 866 |
+
[dcl.contract.res]: #dcl.contract.res
|
| 867 |
[dcl.decl]: #dcl.decl
|
| 868 |
[dcl.decl.general]: #dcl.decl.general
|
| 869 |
[dcl.enum]: #dcl.enum
|
| 870 |
[dcl.fct]: #dcl.fct
|
| 871 |
[dcl.fct.def]: #dcl.fct.def
|
| 872 |
[dcl.fct.def.coroutine]: #dcl.fct.def.coroutine
|
| 873 |
[dcl.fct.def.default]: #dcl.fct.def.default
|
| 874 |
[dcl.fct.def.delete]: #dcl.fct.def.delete
|
| 875 |
[dcl.fct.def.general]: #dcl.fct.def.general
|
| 876 |
+
[dcl.fct.def.replace]: #dcl.fct.def.replace
|
| 877 |
[dcl.fct.default]: #dcl.fct.default
|
| 878 |
[dcl.fct.spec]: #dcl.fct.spec
|
| 879 |
[dcl.friend]: #dcl.friend
|
| 880 |
[dcl.init]: #dcl.init
|
| 881 |
[dcl.init.aggr]: #dcl.init.aggr
|
|
|
|
| 903 |
[dcl.type.class.deduct]: #dcl.type.class.deduct
|
| 904 |
[dcl.type.cv]: #dcl.type.cv
|
| 905 |
[dcl.type.decltype]: #dcl.type.decltype
|
| 906 |
[dcl.type.elab]: #dcl.type.elab
|
| 907 |
[dcl.type.general]: #dcl.type.general
|
| 908 |
+
[dcl.type.pack.index]: #dcl.type.pack.index
|
| 909 |
[dcl.type.simple]: #dcl.type.simple
|
| 910 |
+
[dcl.type.splice]: #dcl.type.splice
|
| 911 |
[dcl.typedef]: #dcl.typedef
|
| 912 |
+
[depr.ellipsis.comma]: future.md#depr.ellipsis.comma
|
| 913 |
[depr.volatile.type]: future.md#depr.volatile.type
|
| 914 |
[enum]: #enum
|
| 915 |
[enum.udecl]: #enum.udecl
|
| 916 |
[except.ctor]: except.md#except.ctor
|
| 917 |
[except.handle]: except.md#except.handle
|
| 918 |
[except.pre]: except.md#except.pre
|
| 919 |
[except.spec]: except.md#except.spec
|
| 920 |
[except.throw]: except.md#except.throw
|
| 921 |
[expr.alignof]: expr.md#expr.alignof
|
| 922 |
+
[expr.assign]: expr.md#expr.assign
|
| 923 |
[expr.await]: expr.md#expr.await
|
| 924 |
[expr.call]: expr.md#expr.call
|
| 925 |
[expr.cast]: expr.md#expr.cast
|
| 926 |
[expr.comma]: expr.md#expr.comma
|
| 927 |
[expr.const]: expr.md#expr.const
|
| 928 |
[expr.const.cast]: expr.md#expr.const.cast
|
| 929 |
[expr.mptr.oper]: expr.md#expr.mptr.oper
|
| 930 |
[expr.new]: expr.md#expr.new
|
| 931 |
[expr.post.incr]: expr.md#expr.post.incr
|
| 932 |
[expr.pre.incr]: expr.md#expr.pre.incr
|
| 933 |
+
[expr.prim.id]: expr.md#expr.prim.id
|
| 934 |
[expr.prim.id.unqual]: expr.md#expr.prim.id.unqual
|
| 935 |
[expr.prim.lambda]: expr.md#expr.prim.lambda
|
| 936 |
+
[expr.prim.lambda.closure]: expr.md#expr.prim.lambda.closure
|
| 937 |
[expr.prim.this]: expr.md#expr.prim.this
|
| 938 |
[expr.prop]: expr.md#expr.prop
|
| 939 |
[expr.ref]: expr.md#expr.ref
|
| 940 |
+
[expr.reflect]: expr.md#expr.reflect
|
| 941 |
[expr.static.cast]: expr.md#expr.static.cast
|
| 942 |
[expr.sub]: expr.md#expr.sub
|
| 943 |
+
[expr.throw]: expr.md#expr.throw
|
| 944 |
[expr.type.conv]: expr.md#expr.type.conv
|
| 945 |
[expr.unary]: expr.md#expr.unary
|
| 946 |
[expr.unary.op]: expr.md#expr.unary.op
|
| 947 |
[expr.yield]: expr.md#expr.yield
|
| 948 |
[initializer.list.syn]: support.md#initializer.list.syn
|
| 949 |
[intro.abstract]: intro.md#intro.abstract
|
|
|
|
| 950 |
[intro.execution]: basic.md#intro.execution
|
|
|
|
| 951 |
[intro.object]: basic.md#intro.object
|
| 952 |
+
[intro.races]: basic.md#intro.races
|
| 953 |
+
[lex.charset]: lex.md#lex.charset
|
| 954 |
[lex.digraph]: lex.md#lex.digraph
|
| 955 |
[lex.key]: lex.md#lex.key
|
| 956 |
[lex.name]: lex.md#lex.name
|
| 957 |
+
[lex.phases]: lex.md#lex.phases
|
| 958 |
[lex.string]: lex.md#lex.string
|
| 959 |
+
[lex.string.uneval]: lex.md#lex.string.uneval
|
| 960 |
+
[meta.reflection.annotation]: meta.md#meta.reflection.annotation
|
| 961 |
[module.interface]: module.md#module.interface
|
| 962 |
[module.reach]: module.md#module.reach
|
| 963 |
[module.unit]: module.md#module.unit
|
| 964 |
[namespace.alias]: #namespace.alias
|
| 965 |
[namespace.def]: #namespace.def
|
|
|
|
| 983 |
[over.match.viable]: over.md#over.match.viable
|
| 984 |
[over.oper]: over.md#over.oper
|
| 985 |
[over.sub]: over.md#over.sub
|
| 986 |
[special]: class.md#special
|
| 987 |
[std.modules]: library.md#std.modules
|
| 988 |
+
[stmt]: stmt.md#stmt
|
| 989 |
[stmt.ambig]: stmt.md#stmt.ambig
|
| 990 |
[stmt.dcl]: stmt.md#stmt.dcl
|
| 991 |
[stmt.expr]: stmt.md#stmt.expr
|
| 992 |
[stmt.if]: stmt.md#stmt.if
|
| 993 |
[stmt.iter]: stmt.md#stmt.iter
|
| 994 |
+
[stmt.label]: stmt.md#stmt.label
|
| 995 |
+
[stmt.pre]: stmt.md#stmt.pre
|
| 996 |
[stmt.return]: stmt.md#stmt.return
|
| 997 |
[stmt.return.coroutine]: stmt.md#stmt.return.coroutine
|
| 998 |
[stmt.select]: stmt.md#stmt.select
|
|
|
|
| 999 |
[stmt.switch]: stmt.md#stmt.switch
|
| 1000 |
[support.runtime]: support.md#support.runtime
|
| 1001 |
+
[temp.arg.nontype]: temp.md#temp.arg.nontype
|
| 1002 |
[temp.arg.type]: temp.md#temp.arg.type
|
| 1003 |
[temp.decls]: temp.md#temp.decls
|
| 1004 |
[temp.deduct]: temp.md#temp.deduct
|
| 1005 |
[temp.deduct.call]: temp.md#temp.deduct.call
|
| 1006 |
[temp.deduct.decl]: temp.md#temp.deduct.decl
|
|
|
|
| 1013 |
[temp.local]: temp.md#temp.local
|
| 1014 |
[temp.names]: temp.md#temp.names
|
| 1015 |
[temp.param]: temp.md#temp.param
|
| 1016 |
[temp.pre]: temp.md#temp.pre
|
| 1017 |
[temp.res]: temp.md#temp.res
|
| 1018 |
+
[temp.res.general]: temp.md#temp.res.general
|
| 1019 |
+
[temp.spec.general]: temp.md#temp.spec.general
|
| 1020 |
[temp.spec.partial]: temp.md#temp.spec.partial
|
| 1021 |
[temp.variadic]: temp.md#temp.variadic
|
| 1022 |
[term.odr.use]: basic.md#term.odr.use
|
| 1023 |
[term.padding.bits]: basic.md#term.padding.bits
|
| 1024 |
[term.scalar.type]: basic.md#term.scalar.type
|