- tmp/tmp7pmo_9it/{from.md → to.md} +195 -127
tmp/tmp7pmo_9it/{from.md → to.md}
RENAMED
|
@@ -46,10 +46,11 @@ control-line:
|
|
| 46 |
'# define ' identifier lparen '... )' replacement-list new-line
|
| 47 |
'# define ' identifier lparen identifier-list ', ... )' replacement-list new-line
|
| 48 |
'# undef ' identifier new-line
|
| 49 |
'# line ' pp-tokens new-line
|
| 50 |
'# error ' pp-tokensₒₚₜ new-line
|
|
|
|
| 51 |
'# pragma ' pp-tokensₒₚₜ new-line
|
| 52 |
'# 'new-line
|
| 53 |
```
|
| 54 |
|
| 55 |
``` bnf
|
|
@@ -71,10 +72,12 @@ elif-groups:
|
|
| 71 |
```
|
| 72 |
|
| 73 |
``` bnf
|
| 74 |
elif-group:
|
| 75 |
'# elif ' constant-expression new-line groupₒₚₜ
|
|
|
|
|
|
|
| 76 |
```
|
| 77 |
|
| 78 |
``` bnf
|
| 79 |
else-group:
|
| 80 |
'# else ' new-line groupₒₚₜ
|
|
@@ -95,11 +98,11 @@ conditionally-supported-directive:
|
|
| 95 |
pp-tokens new-line
|
| 96 |
```
|
| 97 |
|
| 98 |
``` bnf
|
| 99 |
lparen:
|
| 100 |
-
a '(' character not immediately preceded by
|
| 101 |
```
|
| 102 |
|
| 103 |
``` bnf
|
| 104 |
identifier-list:
|
| 105 |
identifier
|
|
@@ -187,16 +190,16 @@ At the start of phase 4 of translation, the *group* of a
|
|
| 187 |
|
| 188 |
When in a group that is skipped [[cpp.cond]], the directive syntax is
|
| 189 |
relaxed to allow any sequence of preprocessing tokens to occur between
|
| 190 |
the directive name and the following new-line character.
|
| 191 |
|
| 192 |
-
The only
|
| 193 |
tokens within a preprocessing directive (from just after the
|
| 194 |
directive-introducing token through just before the terminating new-line
|
| 195 |
character) are space and horizontal-tab (including spaces that have
|
| 196 |
-
replaced comments or possibly other
|
| 197 |
-
|
| 198 |
|
| 199 |
The implementation can process and skip sections of source files
|
| 200 |
conditionally, include other source files, import macros from header
|
| 201 |
units, and replace macros. These capabilities are called
|
| 202 |
*preprocessing*, because conceptually they occur before translation of
|
|
@@ -257,12 +260,13 @@ has-attribute-expression:
|
|
| 257 |
'__has_cpp_attribute (' pp-tokens ')'
|
| 258 |
```
|
| 259 |
|
| 260 |
The expression that controls conditional inclusion shall be an integral
|
| 261 |
constant expression except that identifiers (including those lexically
|
| 262 |
-
identical to keywords) are interpreted as described below[^2]
|
| 263 |
-
|
|
|
|
| 264 |
*has-include-expression*s and/or *has-attribute-expression*s as unary
|
| 265 |
operator expressions.
|
| 266 |
|
| 267 |
A *defined-macro-expression* evaluates to `1` if the identifier is
|
| 268 |
currently defined as a macro name (that is, if it is predefined or if it
|
|
@@ -301,10 +305,11 @@ detected by any non-zero result. — *end note*]
|
|
| 301 |
|
| 302 |
**Table: __has_cpp_attribute values** <a id="cpp.cond.ha">[cpp.cond.ha]</a>
|
| 303 |
|
| 304 |
| Attribute | Value |
|
| 305 |
| -------------------- | --------- |
|
|
|
|
| 306 |
| `carries_dependency` | `200809L` |
|
| 307 |
| `deprecated` | `201309L` |
|
| 308 |
| `fallthrough` | `201603L` |
|
| 309 |
| `likely` | `201803L` |
|
| 310 |
| `maybe_unused` | `201603L` |
|
|
@@ -312,15 +317,15 @@ detected by any non-zero result. — *end note*]
|
|
| 312 |
| `nodiscard` | `201907L` |
|
| 313 |
| `noreturn` | `200809L` |
|
| 314 |
| `unlikely` | `201803L` |
|
| 315 |
|
| 316 |
|
| 317 |
-
The `#ifdef`
|
| 318 |
-
inclusion operator, shall treat `__has_include`
|
| 319 |
-
`__has_cpp_attribute` as if they were the names of defined macros.
|
| 320 |
-
identifiers `__has_include` and `__has_cpp_attribute` shall not
|
| 321 |
-
in any context not mentioned in this subclause.
|
| 322 |
|
| 323 |
Each preprocessing token that remains (in the list of preprocessing
|
| 324 |
tokens that will become the controlling expression) after all macro
|
| 325 |
replacements have occurred shall be in the lexical form of a token
|
| 326 |
[[lex.token]].
|
|
@@ -356,53 +361,41 @@ Therefore it is not subject to this replacement. — *end note*]
|
|
| 356 |
The resulting tokens comprise the controlling constant expression which
|
| 357 |
is evaluated according to the rules of [[expr.const]] using arithmetic
|
| 358 |
that has at least the ranges specified in [[support.limits]]. For the
|
| 359 |
purposes of this token conversion and evaluation all signed and unsigned
|
| 360 |
integer types act as if they have the same representation as,
|
| 361 |
-
respectively, `intmax_t` or `uintmax_t` [[cstdint]].
|
| 362 |
|
| 363 |
[*Note 3*: Thus on an implementation where
|
| 364 |
`std::numeric_limits<int>::max()` is `0x7FFF` and
|
| 365 |
`std::numeric_limits<unsigned int>::max()` is `0xFFFF`, the integer
|
| 366 |
literal `0x8000` is signed and positive within a `#if` expression even
|
| 367 |
though it is unsigned in translation phase 7
|
| 368 |
[[lex.phases]]. — *end note*]
|
| 369 |
|
| 370 |
-
This includes interpreting *character-literal*s
|
| 371 |
-
|
| 372 |
-
Whether the numeric value for these *character-literal*s matches the
|
| 373 |
-
value obtained when an identical *character-literal* occurs in an
|
| 374 |
-
expression (other than within a `#if` or `#elif` directive) is
|
| 375 |
-
*implementation-defined*.
|
| 376 |
|
| 377 |
-
[*Note 4*:
|
|
|
|
| 378 |
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
these two contexts:
|
| 382 |
-
|
| 383 |
-
``` cpp
|
| 384 |
-
#if 'z' - 'a' == 25
|
| 385 |
-
if ('z' - 'a' == 25)
|
| 386 |
-
```
|
| 387 |
-
|
| 388 |
-
— *end note*]
|
| 389 |
-
|
| 390 |
-
Also, whether a single-character *character-literal* may have a negative
|
| 391 |
-
value is *implementation-defined*. Each subexpression with type `bool`
|
| 392 |
-
is subjected to integral promotion before processing continues.
|
| 393 |
|
| 394 |
Preprocessing directives of the forms
|
| 395 |
|
| 396 |
``` bnf
|
| 397 |
'# ifdef ' identifier new-line groupₒₚₜ
|
| 398 |
'# ifndef ' identifier new-line groupₒₚₜ
|
|
|
|
|
|
|
| 399 |
```
|
| 400 |
|
| 401 |
check whether the identifier is or is not currently defined as a macro
|
| 402 |
-
name. Their conditions are equivalent to `#if` `defined` *identifier*
|
| 403 |
-
|
|
|
|
| 404 |
|
| 405 |
Each directive’s condition is checked in order. If it evaluates to false
|
| 406 |
(zero), the group that it controls is skipped: directives are processed
|
| 407 |
only through the name that determines the directive in order to keep
|
| 408 |
track of the level of nested conditionals; the rest of the directives’
|
|
@@ -501,14 +494,16 @@ A preprocessing directive of the form
|
|
| 501 |
(that does not match one of the two previous forms) is permitted. The
|
| 502 |
preprocessing tokens after `include` in the directive are processed just
|
| 503 |
as in normal text (i.e., each identifier currently defined as a macro
|
| 504 |
name is replaced by its replacement list of preprocessing tokens). If
|
| 505 |
the directive resulting after all replacements does not match one of the
|
| 506 |
-
two previous forms, the behavior is undefined.[^4]
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
|
|
|
|
|
|
| 510 |
|
| 511 |
The implementation shall provide unique mappings for sequences
|
| 512 |
consisting of one or more *nondigit*s or *digit*s [[lex.name]] followed
|
| 513 |
by a period (`.`) and a single *nondigit*. The first character shall not
|
| 514 |
be a *digit*. The implementation may ignore distinctions of alphabetical
|
|
@@ -527,15 +522,15 @@ directive [[cpp.import]] of the form
|
|
| 527 |
'import' header-name ';' new-line
|
| 528 |
```
|
| 529 |
|
| 530 |
[*Note 1*:
|
| 531 |
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
|
| 538 |
``` cpp
|
| 539 |
#include <stdio.h>
|
| 540 |
#include <unistd.h>
|
| 541 |
#include "usefullib.h"
|
|
@@ -599,74 +594,80 @@ the first token of the *pp-import*) `export` is an identifier defined as
|
|
| 599 |
an object-like macro.
|
| 600 |
|
| 601 |
The preprocessing tokens after the `import` preprocessing token in the
|
| 602 |
`import` *control-line* are processed just as in normal text (i.e., each
|
| 603 |
identifier currently defined as a macro name is replaced by its
|
| 604 |
-
replacement list of preprocessing tokens).
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
*
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 611 |
|
| 612 |
If a *pp-import* is produced by source file inclusion (including by the
|
| 613 |
rewrite produced when a `#include` directive names an importable header)
|
| 614 |
while processing the *group* of a *module-file*, the program is
|
| 615 |
ill-formed.
|
| 616 |
|
| 617 |
In all three forms of *pp-import*, the `import` and `export` (if it
|
| 618 |
exists) preprocessing tokens are replaced by the *import-keyword* and
|
| 619 |
*export-keyword* preprocessing tokens respectively.
|
| 620 |
|
| 621 |
-
[*Note
|
| 622 |
removed at the end of phase 4. — *end note*]
|
| 623 |
|
| 624 |
Additionally, in the second form of *pp-import*, a *header-name* token
|
| 625 |
is formed as if the *header-name-tokens* were the *pp-tokens* of a
|
| 626 |
`#include` directive. The *header-name-tokens* are replaced by the
|
| 627 |
*header-name* token.
|
| 628 |
|
| 629 |
-
[*Note
|
| 630 |
preprocessor and later phases of translation. — *end note*]
|
| 631 |
|
| 632 |
Each `#define` directive encountered when preprocessing each translation
|
| 633 |
unit in a program results in a distinct *macro definition*.
|
| 634 |
|
| 635 |
-
[*Note
|
| 636 |
by a `#define` directive. Implementations providing mechanisms to
|
| 637 |
predefine additional macros are encouraged to not treat them as being
|
| 638 |
introduced by a `#define` directive. — *end note*]
|
| 639 |
|
| 640 |
-
|
| 641 |
-
translation unit
|
| 642 |
-
definition has at most one point of definition in each translation unit
|
| 643 |
-
and at most one point of undefinition, as follows:
|
| 644 |
|
| 645 |
- The *point of definition* of a macro definition within a translation
|
| 646 |
-
unit
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 652 |
- The *point of undefinition* of a macro definition within a translation
|
| 653 |
unit is the first point at which a `#undef` directive naming the macro
|
| 654 |
occurs after its point of definition, or the first point of macro
|
| 655 |
-
import of a
|
| 656 |
-
|
| 657 |
|
| 658 |
A macro directive is *active* at a source location if it has a point of
|
| 659 |
definition in that translation unit preceding the location, and does not
|
| 660 |
have a point of undefinition in that translation unit preceding the
|
| 661 |
location.
|
| 662 |
|
| 663 |
If a macro would be replaced or redefined, and multiple macro
|
| 664 |
definitions are active for that macro name, the active macro definitions
|
| 665 |
shall all be valid redefinitions of the same macro [[cpp.replace]].
|
| 666 |
|
| 667 |
-
[*Note
|
| 668 |
a particular macro definition is active. — *end note*]
|
| 669 |
|
| 670 |
[*Example 1*:
|
| 671 |
|
| 672 |
Importable header \`"a.h"\`
|
|
@@ -694,23 +695,47 @@ Importable header \`"c.h"\`
|
|
| 694 |
```
|
| 695 |
|
| 696 |
Importable header \`"d.h"\`
|
| 697 |
|
| 698 |
``` cpp
|
| 699 |
-
import "a.h"; // point of definition of #1, #2, and #3, point of undefinition of #1 in "d.h"
|
| 700 |
import "c.h"; // point of definition of #4 and #5 in "d.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 701 |
int a = Y; // OK, active macro definitions #2 and #4 are valid redefinitions
|
| 702 |
int c = Z; // error: active macro definitions #3 and #5 are not valid redefinitions of Z
|
| 703 |
```
|
| 704 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 705 |
— *end example*]
|
| 706 |
|
| 707 |
## Macro replacement <a id="cpp.replace">[[cpp.replace]]</a>
|
| 708 |
|
|
|
|
|
|
|
| 709 |
Two replacement lists are identical if and only if the preprocessing
|
| 710 |
-
tokens in both have the same number, ordering, spelling, and
|
| 711 |
-
separation, where all
|
| 712 |
|
| 713 |
An identifier currently defined as an object-like macro (see below) may
|
| 714 |
be redefined by another `#define` preprocessing directive provided that
|
| 715 |
the second definition is an object-like macro definition and the two
|
| 716 |
replacement lists are identical, otherwise the program is ill-formed.
|
|
@@ -742,11 +767,11 @@ But the following redefinitions are invalid:
|
|
| 742 |
#define FUNC_LIKE(b) ( b ) // different parameter spelling
|
| 743 |
```
|
| 744 |
|
| 745 |
— *end example*]
|
| 746 |
|
| 747 |
-
There shall be
|
| 748 |
list in the definition of an object-like macro.
|
| 749 |
|
| 750 |
If the *identifier-list* in the macro definition does not end with an
|
| 751 |
ellipsis, the number of arguments (including those arguments consisting
|
| 752 |
of no preprocessing tokens) in an invocation of a function-like macro
|
|
@@ -761,28 +786,31 @@ notation in the parameters.
|
|
| 761 |
|
| 762 |
A parameter identifier in a function-like macro shall be uniquely
|
| 763 |
declared within its scope.
|
| 764 |
|
| 765 |
The identifier immediately following the `define` is called the *macro
|
| 766 |
-
name*. There is one name space for macro names. Any
|
| 767 |
characters preceding or following the replacement list of preprocessing
|
| 768 |
tokens are not considered part of the replacement list for either form
|
| 769 |
of macro.
|
| 770 |
|
| 771 |
If a `#` preprocessing token, followed by an identifier, occurs
|
| 772 |
-
lexically at the point at which a preprocessing directive
|
| 773 |
-
|
| 774 |
|
| 775 |
A preprocessing directive of the form
|
| 776 |
|
| 777 |
``` bnf
|
| 778 |
'# define' identifier replacement-list new-line
|
| 779 |
```
|
| 780 |
|
| 781 |
defines an *object-like macro* that causes each subsequent instance of
|
| 782 |
-
the macro name[^5]
|
| 783 |
-
|
|
|
|
|
|
|
|
|
|
| 784 |
The replacement list is then rescanned for more macro names as specified
|
| 785 |
below.
|
| 786 |
|
| 787 |
[*Example 2*:
|
| 788 |
|
|
@@ -804,29 +832,29 @@ A preprocessing directive of the form
|
|
| 804 |
'# define' identifier lparen identifier-list ', ...' ')' replacement-list new-line
|
| 805 |
```
|
| 806 |
|
| 807 |
defines a *function-like macro* with parameters, whose use is similar
|
| 808 |
syntactically to a function call. The parameters are specified by the
|
| 809 |
-
optional list of identifiers
|
| 810 |
-
in the identifier list until the new-line character that terminates the
|
| 811 |
-
`#define` preprocessing directive. Each subsequent instance of the
|
| 812 |
function-like macro name followed by a `(` as the next preprocessing
|
| 813 |
token introduces the sequence of preprocessing tokens that is replaced
|
| 814 |
by the replacement list in the definition (an invocation of the macro).
|
| 815 |
The replaced sequence of preprocessing tokens is terminated by the
|
| 816 |
matching `)` preprocessing token, skipping intervening matched pairs of
|
| 817 |
left and right parenthesis preprocessing tokens. Within the sequence of
|
| 818 |
preprocessing tokens making up an invocation of a function-like macro,
|
| 819 |
-
new-line is considered a normal
|
| 820 |
|
| 821 |
The sequence of preprocessing tokens bounded by the outside-most
|
| 822 |
matching parentheses forms the list of arguments for the function-like
|
| 823 |
macro. The individual arguments within the list are separated by comma
|
| 824 |
preprocessing tokens, but comma preprocessing tokens between matching
|
| 825 |
inner parentheses do not separate arguments. If there are sequences of
|
| 826 |
preprocessing tokens within the list of arguments that would otherwise
|
| 827 |
-
act as preprocessing directives,[^7]
|
|
|
|
|
|
|
| 828 |
|
| 829 |
[*Example 3*:
|
| 830 |
|
| 831 |
The following defines a function-like macro whose value is the maximum
|
| 832 |
of its arguments. It has the disadvantages of evaluating one or the
|
|
@@ -922,11 +950,11 @@ would be ill-formed as the replacement list of the current function-like
|
|
| 922 |
macro, the program is ill-formed. A *va-opt-replacement* is treated as
|
| 923 |
if it were a parameter, and the preprocessing token sequence for the
|
| 924 |
corresponding argument is defined as follows. If the substitution of
|
| 925 |
`__VA_ARGS__` as neither an operand of `#` nor `##` consists of no
|
| 926 |
preprocessing tokens, the argument consists of a single placemarker
|
| 927 |
-
preprocessing token
|
| 928 |
argument consists of the results of the expansion of the contained
|
| 929 |
*pp-tokens* as the replacement list of the current function-like macro
|
| 930 |
before removal of placemarker tokens, rescanning, and further
|
| 931 |
replacement.
|
| 932 |
|
|
@@ -1020,13 +1048,20 @@ an argument) is deleted and the preceding preprocessing token is
|
|
| 1020 |
concatenated with the following preprocessing token. Placemarker
|
| 1021 |
preprocessing tokens are handled specially: concatenation of two
|
| 1022 |
placemarkers results in a single placemarker preprocessing token, and
|
| 1023 |
concatenation of a placemarker with a non-placemarker preprocessing
|
| 1024 |
token results in the non-placemarker preprocessing token. If the result
|
| 1025 |
-
|
| 1026 |
-
|
| 1027 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1028 |
|
| 1029 |
[*Example 1*:
|
| 1030 |
|
| 1031 |
The sequence
|
| 1032 |
|
|
@@ -1241,32 +1276,33 @@ in normal text (each identifier currently defined as a macro name is
|
|
| 1241 |
replaced by its replacement list of preprocessing tokens). If the
|
| 1242 |
directive resulting after all replacements does not match one of the two
|
| 1243 |
previous forms, the behavior is undefined; otherwise, the result is
|
| 1244 |
processed as appropriate.
|
| 1245 |
|
| 1246 |
-
##
|
| 1247 |
|
| 1248 |
-
A preprocessing directive of the
|
| 1249 |
|
| 1250 |
``` bnf
|
| 1251 |
'# error' pp-tokensₒₚₜ new-line
|
|
|
|
| 1252 |
```
|
| 1253 |
|
| 1254 |
-
causes the implementation to produce a diagnostic message that
|
| 1255 |
-
the specified sequence of preprocessing tokens
|
| 1256 |
-
ill-formed.
|
| 1257 |
|
| 1258 |
## Pragma directive <a id="cpp.pragma">[[cpp.pragma]]</a>
|
| 1259 |
|
| 1260 |
A preprocessing directive of the form
|
| 1261 |
|
| 1262 |
``` bnf
|
| 1263 |
'# pragma' pp-tokensₒₚₜ new-line
|
| 1264 |
```
|
| 1265 |
|
| 1266 |
causes the implementation to behave in an *implementation-defined*
|
| 1267 |
-
manner. The behavior
|
| 1268 |
translator or the resulting program to behave in a non-conforming
|
| 1269 |
manner. Any pragma that is not recognized by the implementation is
|
| 1270 |
ignored.
|
| 1271 |
|
| 1272 |
## Null directive <a id="cpp.null">[[cpp.null]]</a>
|
|
@@ -1285,13 +1321,20 @@ The following macro names shall be defined by the implementation:
|
|
| 1285 |
|
| 1286 |
- **`__cplusplus`**
|
| 1287 |
|
| 1288 |
The integer literal `202302L`.
|
| 1289 |
|
| 1290 |
-
[*Note 1*:
|
| 1291 |
-
|
| 1292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1293 |
|
| 1294 |
- **`__DATE__`**
|
| 1295 |
|
| 1296 |
The date of translation of the source file: a character string literal
|
| 1297 |
of the form `"Mmm dd yyyy"`, where the names of the months are the same
|
|
@@ -1311,89 +1354,121 @@ The presumed line number (within the current source file) of the current
|
|
| 1311 |
source line (an integer literal).[^10]
|
| 1312 |
|
| 1313 |
- **`__STDC_HOSTED__`**
|
| 1314 |
|
| 1315 |
The integer literal `1` if the implementation is a hosted implementation
|
| 1316 |
-
or the integer literal `0` if it is
|
|
|
|
| 1317 |
|
| 1318 |
- **`__STDCPP_DEFAULT_NEW_ALIGNMENT__`**
|
| 1319 |
|
| 1320 |
An integer literal of type `std::size_t` whose value is the alignment
|
| 1321 |
guaranteed by a call to `operator new(std::size_t)` or
|
| 1322 |
`operator new[](std::size_t)`.
|
| 1323 |
|
| 1324 |
-
[*Note
|
| 1325 |
`operator new(std::size_t, std::align_val_t)`, etc.
|
| 1326 |
[[expr.new]]. — *end note*]
|
| 1327 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1328 |
- **`__TIME__`**
|
| 1329 |
|
| 1330 |
The time of translation of the source file: a character string literal
|
| 1331 |
of the form `"hh:mm:ss"` as in the time generated by the `asctime`
|
| 1332 |
function. If the time of translation is not available, an
|
| 1333 |
*implementation-defined* valid time shall be supplied.
|
| 1334 |
|
| 1335 |
-
- **The names listed in [[cpp.predefined.ft]].**
|
| 1336 |
-
|
| 1337 |
-
The macros defined in [[cpp.predefined.ft]] shall be defined to the
|
| 1338 |
-
corresponding integer literal.
|
| 1339 |
-
|
| 1340 |
-
[*Note 3*: Future versions of this International Standard might replace
|
| 1341 |
-
the values of these macros with greater values. — *end note*]
|
| 1342 |
-
|
| 1343 |
**Table: Feature-test macros** <a id="cpp.predefined.ft">[cpp.predefined.ft]</a>
|
| 1344 |
|
| 1345 |
| Macro name | Value |
|
| 1346 |
| --------------------------------------- | --------- |
|
| 1347 |
| `__cpp_aggregate_bases` | `201603L` |
|
| 1348 |
| `__cpp_aggregate_nsdmi` | `201304L` |
|
| 1349 |
| `__cpp_aggregate_paren_init` | `201902L` |
|
| 1350 |
| `__cpp_alias_templates` | `200704L` |
|
| 1351 |
| `__cpp_aligned_new` | `201606L` |
|
| 1352 |
| `__cpp_attributes` | `200809L` |
|
|
|
|
| 1353 |
| `__cpp_binary_literals` | `201304L` |
|
| 1354 |
| `__cpp_capture_star_this` | `201603L` |
|
| 1355 |
-
| `__cpp_char8_t` | `
|
| 1356 |
-
| `__cpp_concepts` | `
|
| 1357 |
| `__cpp_conditional_explicit` | `201806L` |
|
| 1358 |
-
| `__cpp_constexpr` | `
|
| 1359 |
| `__cpp_constexpr_dynamic_alloc` | `201907L` |
|
| 1360 |
| `__cpp_constexpr_in_decltype` | `201711L` |
|
| 1361 |
-
| `__cpp_consteval` | `
|
| 1362 |
| `__cpp_constinit` | `201907L` |
|
| 1363 |
| `__cpp_decltype` | `200707L` |
|
| 1364 |
| `__cpp_decltype_auto` | `201304L` |
|
| 1365 |
| `__cpp_deduction_guides` | `201907L` |
|
| 1366 |
| `__cpp_delegating_constructors` | `200604L` |
|
| 1367 |
| `__cpp_designated_initializers` | `201707L` |
|
| 1368 |
| `__cpp_enumerator_attributes` | `201411L` |
|
|
|
|
| 1369 |
| `__cpp_fold_expressions` | `201603L` |
|
| 1370 |
| `__cpp_generic_lambdas` | `201707L` |
|
| 1371 |
| `__cpp_guaranteed_copy_elision` | `201606L` |
|
| 1372 |
| `__cpp_hex_float` | `201603L` |
|
|
|
|
| 1373 |
| `__cpp_if_constexpr` | `201606L` |
|
| 1374 |
| `__cpp_impl_coroutine` | `201902L` |
|
| 1375 |
| `__cpp_impl_destroying_delete` | `201806L` |
|
| 1376 |
| `__cpp_impl_three_way_comparison` | `201907L` |
|
|
|
|
| 1377 |
| `__cpp_inheriting_constructors` | `201511L` |
|
| 1378 |
| `__cpp_init_captures` | `201803L` |
|
| 1379 |
| `__cpp_initializer_lists` | `200806L` |
|
| 1380 |
| `__cpp_inline_variables` | `201606L` |
|
| 1381 |
| `__cpp_lambdas` | `200907L` |
|
| 1382 |
| `__cpp_modules` | `201907L` |
|
|
|
|
|
|
|
| 1383 |
| `__cpp_namespace_attributes` | `201411L` |
|
| 1384 |
| `__cpp_noexcept_function_type` | `201510L` |
|
| 1385 |
| `__cpp_nontype_template_args` | `201911L` |
|
| 1386 |
| `__cpp_nontype_template_parameter_auto` | `201606L` |
|
| 1387 |
| `__cpp_nsdmi` | `200809L` |
|
| 1388 |
-
| `__cpp_range_based_for` | `
|
| 1389 |
| `__cpp_raw_strings` | `200710L` |
|
| 1390 |
| `__cpp_ref_qualifiers` | `200710L` |
|
| 1391 |
| `__cpp_return_type_deduction` | `201304L` |
|
| 1392 |
| `__cpp_rvalue_references` | `200610L` |
|
|
|
|
| 1393 |
| `__cpp_sized_deallocation` | `201309L` |
|
| 1394 |
| `__cpp_static_assert` | `201411L` |
|
|
|
|
| 1395 |
| `__cpp_structured_bindings` | `201606L` |
|
| 1396 |
| `__cpp_template_template_args` | `201611L` |
|
| 1397 |
| `__cpp_threadsafe_static_init` | `200806L` |
|
| 1398 |
| `__cpp_unicode_characters` | `200704L` |
|
| 1399 |
| `__cpp_unicode_literals` | `200710L` |
|
|
@@ -1424,22 +1499,13 @@ character literal.
|
|
| 1424 |
Whether \_\_STDC_VERSION\_\_ is predefined and if so, what its value is,
|
| 1425 |
are *implementation-defined*.
|
| 1426 |
|
| 1427 |
- **`__STDC_ISO_10646__`**
|
| 1428 |
|
| 1429 |
-
An integer literal of the form `yyyymmL` (for example, `199712L`).
|
| 1430 |
-
|
| 1431 |
-
|
| 1432 |
-
the code point of that character. The *Unicode required set* consists of
|
| 1433 |
-
all the characters that are defined by ISO/IEC 10646, along with all
|
| 1434 |
-
amendments and technical corrigenda as of the specified year and month.
|
| 1435 |
-
|
| 1436 |
-
- **`__STDCPP_STRICT_POINTER_SAFETY__`**
|
| 1437 |
-
|
| 1438 |
-
Defined, and has the value integer literal 1, if and only if the
|
| 1439 |
-
implementation has strict pointer safety
|
| 1440 |
-
[[basic.stc.dynamic.safety]].
|
| 1441 |
|
| 1442 |
- **`__STDCPP_THREADS__`**
|
| 1443 |
|
| 1444 |
Defined, and has the value integer literal 1, if and only if a program
|
| 1445 |
can have more than one thread of execution [[intro.multithread]].
|
|
@@ -1493,11 +1559,11 @@ LISTING( ..\listing.dir )
|
|
| 1493 |
```
|
| 1494 |
|
| 1495 |
— *end example*]
|
| 1496 |
|
| 1497 |
<!-- Link reference definitions -->
|
| 1498 |
-
[basic.
|
| 1499 |
[cpp]: #cpp
|
| 1500 |
[cpp.concat]: #cpp.concat
|
| 1501 |
[cpp.cond]: #cpp.cond
|
| 1502 |
[cpp.cond.ha]: #cpp.cond.ha
|
| 1503 |
[cpp.error]: #cpp.error
|
|
@@ -1510,25 +1576,27 @@ LISTING( ..\listing.dir )
|
|
| 1510 |
[cpp.pragma.op]: #cpp.pragma.op
|
| 1511 |
[cpp.pre]: #cpp.pre
|
| 1512 |
[cpp.predefined]: #cpp.predefined
|
| 1513 |
[cpp.predefined.ft]: #cpp.predefined.ft
|
| 1514 |
[cpp.replace]: #cpp.replace
|
|
|
|
| 1515 |
[cpp.rescan]: #cpp.rescan
|
| 1516 |
[cpp.scope]: #cpp.scope
|
| 1517 |
[cpp.stringize]: #cpp.stringize
|
| 1518 |
[cpp.subst]: #cpp.subst
|
| 1519 |
-
[cstdint]: support.md#cstdint
|
| 1520 |
[expr.const]: expr.md#expr.const
|
| 1521 |
[expr.new]: expr.md#expr.new
|
|
|
|
| 1522 |
[intro.multithread]: basic.md#intro.multithread
|
|
|
|
| 1523 |
[lex.digraph]: lex.md#lex.digraph
|
| 1524 |
[lex.key]: lex.md#lex.key
|
| 1525 |
[lex.name]: lex.md#lex.name
|
| 1526 |
[lex.phases]: lex.md#lex.phases
|
| 1527 |
[lex.token]: lex.md#lex.token
|
| 1528 |
[module.import]: module.md#module.import
|
| 1529 |
-
[stmt.if]: stmt.md#stmt.if
|
| 1530 |
[support.limits]: support.md#support.limits
|
| 1531 |
|
| 1532 |
[^1]: Thus, preprocessing directives are commonly called “lines”. These
|
| 1533 |
“lines” have no other syntactic significance, as all whitespace is
|
| 1534 |
equivalent except in certain situations during preprocessing (see
|
|
@@ -1537,13 +1605,13 @@ LISTING( ..\listing.dir )
|
|
| 1537 |
|
| 1538 |
[^2]: Because the controlling constant expression is evaluated during
|
| 1539 |
translation phase 4, all identifiers either are or are not macro
|
| 1540 |
names — there simply are no keywords, enumeration constants, etc.
|
| 1541 |
|
| 1542 |
-
[^3]: As indicated by the syntax, a preprocessing token
|
| 1543 |
-
|
| 1544 |
-
character. However, comments
|
| 1545 |
including within a preprocessing directive.
|
| 1546 |
|
| 1547 |
[^4]: Note that adjacent *string-literal*s are not concatenated into a
|
| 1548 |
single *string-literal* (see the translation phases in
|
| 1549 |
[[lex.phases]]); thus, an expansion that results in two
|
|
|
|
| 46 |
'# define ' identifier lparen '... )' replacement-list new-line
|
| 47 |
'# define ' identifier lparen identifier-list ', ... )' replacement-list new-line
|
| 48 |
'# undef ' identifier new-line
|
| 49 |
'# line ' pp-tokens new-line
|
| 50 |
'# error ' pp-tokensₒₚₜ new-line
|
| 51 |
+
'# warning' pp-tokensₒₚₜ new-line
|
| 52 |
'# pragma ' pp-tokensₒₚₜ new-line
|
| 53 |
'# 'new-line
|
| 54 |
```
|
| 55 |
|
| 56 |
``` bnf
|
|
|
|
| 72 |
```
|
| 73 |
|
| 74 |
``` bnf
|
| 75 |
elif-group:
|
| 76 |
'# elif ' constant-expression new-line groupₒₚₜ
|
| 77 |
+
'# elifdef ' identifier new-line groupₒₚₜ
|
| 78 |
+
'# elifndef' identifier new-line groupₒₚₜ
|
| 79 |
```
|
| 80 |
|
| 81 |
``` bnf
|
| 82 |
else-group:
|
| 83 |
'# else ' new-line groupₒₚₜ
|
|
|
|
| 98 |
pp-tokens new-line
|
| 99 |
```
|
| 100 |
|
| 101 |
``` bnf
|
| 102 |
lparen:
|
| 103 |
+
a '(' character not immediately preceded by whitespace
|
| 104 |
```
|
| 105 |
|
| 106 |
``` bnf
|
| 107 |
identifier-list:
|
| 108 |
identifier
|
|
|
|
| 190 |
|
| 191 |
When in a group that is skipped [[cpp.cond]], the directive syntax is
|
| 192 |
relaxed to allow any sequence of preprocessing tokens to occur between
|
| 193 |
the directive name and the following new-line character.
|
| 194 |
|
| 195 |
+
The only whitespace characters that shall appear between preprocessing
|
| 196 |
tokens within a preprocessing directive (from just after the
|
| 197 |
directive-introducing token through just before the terminating new-line
|
| 198 |
character) are space and horizontal-tab (including spaces that have
|
| 199 |
+
replaced comments or possibly other whitespace characters in translation
|
| 200 |
+
phase 3).
|
| 201 |
|
| 202 |
The implementation can process and skip sections of source files
|
| 203 |
conditionally, include other source files, import macros from header
|
| 204 |
units, and replace macros. These capabilities are called
|
| 205 |
*preprocessing*, because conceptually they occur before translation of
|
|
|
|
| 260 |
'__has_cpp_attribute (' pp-tokens ')'
|
| 261 |
```
|
| 262 |
|
| 263 |
The expression that controls conditional inclusion shall be an integral
|
| 264 |
constant expression except that identifiers (including those lexically
|
| 265 |
+
identical to keywords) are interpreted as described below[^2]
|
| 266 |
+
|
| 267 |
+
and it may contain zero or more *defined-macro-expression*s and/or
|
| 268 |
*has-include-expression*s and/or *has-attribute-expression*s as unary
|
| 269 |
operator expressions.
|
| 270 |
|
| 271 |
A *defined-macro-expression* evaluates to `1` if the identifier is
|
| 272 |
currently defined as a macro name (that is, if it is predefined or if it
|
|
|
|
| 305 |
|
| 306 |
**Table: __has_cpp_attribute values** <a id="cpp.cond.ha">[cpp.cond.ha]</a>
|
| 307 |
|
| 308 |
| Attribute | Value |
|
| 309 |
| -------------------- | --------- |
|
| 310 |
+
| `assume` | `202207L` |
|
| 311 |
| `carries_dependency` | `200809L` |
|
| 312 |
| `deprecated` | `201309L` |
|
| 313 |
| `fallthrough` | `201603L` |
|
| 314 |
| `likely` | `201803L` |
|
| 315 |
| `maybe_unused` | `201603L` |
|
|
|
|
| 317 |
| `nodiscard` | `201907L` |
|
| 318 |
| `noreturn` | `200809L` |
|
| 319 |
| `unlikely` | `201803L` |
|
| 320 |
|
| 321 |
|
| 322 |
+
The `#ifdef`, `#ifndef`, `#elifdef`, and `#elifndef` directives, and the
|
| 323 |
+
`defined` conditional inclusion operator, shall treat `__has_include`
|
| 324 |
+
and `__has_cpp_attribute` as if they were the names of defined macros.
|
| 325 |
+
The identifiers `__has_include` and `__has_cpp_attribute` shall not
|
| 326 |
+
appear in any context not mentioned in this subclause.
|
| 327 |
|
| 328 |
Each preprocessing token that remains (in the list of preprocessing
|
| 329 |
tokens that will become the controlling expression) after all macro
|
| 330 |
replacements have occurred shall be in the lexical form of a token
|
| 331 |
[[lex.token]].
|
|
|
|
| 361 |
The resulting tokens comprise the controlling constant expression which
|
| 362 |
is evaluated according to the rules of [[expr.const]] using arithmetic
|
| 363 |
that has at least the ranges specified in [[support.limits]]. For the
|
| 364 |
purposes of this token conversion and evaluation all signed and unsigned
|
| 365 |
integer types act as if they have the same representation as,
|
| 366 |
+
respectively, `intmax_t` or `uintmax_t` [[cstdint.syn]].
|
| 367 |
|
| 368 |
[*Note 3*: Thus on an implementation where
|
| 369 |
`std::numeric_limits<int>::max()` is `0x7FFF` and
|
| 370 |
`std::numeric_limits<unsigned int>::max()` is `0xFFFF`, the integer
|
| 371 |
literal `0x8000` is signed and positive within a `#if` expression even
|
| 372 |
though it is unsigned in translation phase 7
|
| 373 |
[[lex.phases]]. — *end note*]
|
| 374 |
|
| 375 |
+
This includes interpreting *character-literal*s according to the rules
|
| 376 |
+
in [[lex.ccon]].
|
|
|
|
|
|
|
|
|
|
|
|
|
| 377 |
|
| 378 |
+
[*Note 4*: The associated character encodings of literals are the same
|
| 379 |
+
in `#if` and `#elif` directives and in any expression. — *end note*]
|
| 380 |
|
| 381 |
+
Each subexpression with type `bool` is subjected to integral promotion
|
| 382 |
+
before processing continues.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 383 |
|
| 384 |
Preprocessing directives of the forms
|
| 385 |
|
| 386 |
``` bnf
|
| 387 |
'# ifdef ' identifier new-line groupₒₚₜ
|
| 388 |
'# ifndef ' identifier new-line groupₒₚₜ
|
| 389 |
+
'# elifdef ' identifier new-line groupₒₚₜ
|
| 390 |
+
'# elifndef' identifier new-line groupₒₚₜ
|
| 391 |
```
|
| 392 |
|
| 393 |
check whether the identifier is or is not currently defined as a macro
|
| 394 |
+
name. Their conditions are equivalent to `#if` `defined` *identifier*,
|
| 395 |
+
`#if` `!defined` *identifier*, `#elif` `defined` *identifier*, and
|
| 396 |
+
`#elif` `!defined` *identifier*, respectively.
|
| 397 |
|
| 398 |
Each directive’s condition is checked in order. If it evaluates to false
|
| 399 |
(zero), the group that it controls is skipped: directives are processed
|
| 400 |
only through the name that determines the directive in order to keep
|
| 401 |
track of the level of nested conditionals; the rest of the directives’
|
|
|
|
| 494 |
(that does not match one of the two previous forms) is permitted. The
|
| 495 |
preprocessing tokens after `include` in the directive are processed just
|
| 496 |
as in normal text (i.e., each identifier currently defined as a macro
|
| 497 |
name is replaced by its replacement list of preprocessing tokens). If
|
| 498 |
the directive resulting after all replacements does not match one of the
|
| 499 |
+
two previous forms, the behavior is undefined.[^4]
|
| 500 |
+
|
| 501 |
+
The method by which a sequence of preprocessing tokens between a `<` and
|
| 502 |
+
a `>` preprocessing token pair or a pair of `"` characters is combined
|
| 503 |
+
into a single header name preprocessing token is
|
| 504 |
+
*implementation-defined*.
|
| 505 |
|
| 506 |
The implementation shall provide unique mappings for sequences
|
| 507 |
consisting of one or more *nondigit*s or *digit*s [[lex.name]] followed
|
| 508 |
by a period (`.`) and a single *nondigit*. The first character shall not
|
| 509 |
be a *digit*. The implementation may ignore distinctions of alphabetical
|
|
|
|
| 522 |
'import' header-name ';' new-line
|
| 523 |
```
|
| 524 |
|
| 525 |
[*Note 1*:
|
| 526 |
|
| 527 |
+
An implementation can provide a mechanism for making arbitrary source
|
| 528 |
+
files available to the `< >` search. However, using the `< >` form for
|
| 529 |
+
headers provided with the implementation and the `" "` form for sources
|
| 530 |
+
outside the control of the implementation achieves wider portability.
|
| 531 |
+
For instance:
|
| 532 |
|
| 533 |
``` cpp
|
| 534 |
#include <stdio.h>
|
| 535 |
#include <unistd.h>
|
| 536 |
#include "usefullib.h"
|
|
|
|
| 594 |
an object-like macro.
|
| 595 |
|
| 596 |
The preprocessing tokens after the `import` preprocessing token in the
|
| 597 |
`import` *control-line* are processed just as in normal text (i.e., each
|
| 598 |
identifier currently defined as a macro name is replaced by its
|
| 599 |
+
replacement list of preprocessing tokens).
|
| 600 |
+
|
| 601 |
+
[*Note 1*: An `import` directive matching the first two forms of a
|
| 602 |
+
*pp-import* instructs the preprocessor to import macros from the header
|
| 603 |
+
unit [[module.import]] denoted by the *header-name*, as described
|
| 604 |
+
below. — *end note*]
|
| 605 |
+
|
| 606 |
+
The *point of macro import* for the first two forms of *pp-import* is
|
| 607 |
+
immediately after the *new-line* terminating the *pp-import*. The last
|
| 608 |
+
form of *pp-import* is only considered if the first two forms did not
|
| 609 |
+
match, and does not have a point of macro import.
|
| 610 |
|
| 611 |
If a *pp-import* is produced by source file inclusion (including by the
|
| 612 |
rewrite produced when a `#include` directive names an importable header)
|
| 613 |
while processing the *group* of a *module-file*, the program is
|
| 614 |
ill-formed.
|
| 615 |
|
| 616 |
In all three forms of *pp-import*, the `import` and `export` (if it
|
| 617 |
exists) preprocessing tokens are replaced by the *import-keyword* and
|
| 618 |
*export-keyword* preprocessing tokens respectively.
|
| 619 |
|
| 620 |
+
[*Note 2*: This makes the line no longer a directive so it is not
|
| 621 |
removed at the end of phase 4. — *end note*]
|
| 622 |
|
| 623 |
Additionally, in the second form of *pp-import*, a *header-name* token
|
| 624 |
is formed as if the *header-name-tokens* were the *pp-tokens* of a
|
| 625 |
`#include` directive. The *header-name-tokens* are replaced by the
|
| 626 |
*header-name* token.
|
| 627 |
|
| 628 |
+
[*Note 3*: This ensures that imports are treated consistently by the
|
| 629 |
preprocessor and later phases of translation. — *end note*]
|
| 630 |
|
| 631 |
Each `#define` directive encountered when preprocessing each translation
|
| 632 |
unit in a program results in a distinct *macro definition*.
|
| 633 |
|
| 634 |
+
[*Note 4*: A predefined macro name [[cpp.predefined]] is not introduced
|
| 635 |
by a `#define` directive. Implementations providing mechanisms to
|
| 636 |
predefine additional macros are encouraged to not treat them as being
|
| 637 |
introduced by a `#define` directive. — *end note*]
|
| 638 |
|
| 639 |
+
Each macro definition has at most one point of definition in each
|
| 640 |
+
translation unit and at most one point of undefinition, as follows:
|
|
|
|
|
|
|
| 641 |
|
| 642 |
- The *point of definition* of a macro definition within a translation
|
| 643 |
+
unit T is
|
| 644 |
+
- if the `#define` directive of the macro definition occurs within T,
|
| 645 |
+
the point at which that directive occurs, or otherwise,
|
| 646 |
+
- if the macro name is not lexically identical to a keyword
|
| 647 |
+
[[lex.key]] or to the *identifier*s `module` or `import`, the first
|
| 648 |
+
point of macro import in T of a header unit containing a point of
|
| 649 |
+
definition for the macro definition, if any.
|
| 650 |
+
|
| 651 |
+
In the latter case, the macro is said to be *imported* from the header
|
| 652 |
+
unit.
|
| 653 |
- The *point of undefinition* of a macro definition within a translation
|
| 654 |
unit is the first point at which a `#undef` directive naming the macro
|
| 655 |
occurs after its point of definition, or the first point of macro
|
| 656 |
+
import of a header unit containing a point of undefinition for the
|
| 657 |
+
macro definition, whichever (if any) occurs first.
|
| 658 |
|
| 659 |
A macro directive is *active* at a source location if it has a point of
|
| 660 |
definition in that translation unit preceding the location, and does not
|
| 661 |
have a point of undefinition in that translation unit preceding the
|
| 662 |
location.
|
| 663 |
|
| 664 |
If a macro would be replaced or redefined, and multiple macro
|
| 665 |
definitions are active for that macro name, the active macro definitions
|
| 666 |
shall all be valid redefinitions of the same macro [[cpp.replace]].
|
| 667 |
|
| 668 |
+
[*Note 5*: The relative order of *pp-import*s has no bearing on whether
|
| 669 |
a particular macro definition is active. — *end note*]
|
| 670 |
|
| 671 |
[*Example 1*:
|
| 672 |
|
| 673 |
Importable header \`"a.h"\`
|
|
|
|
| 695 |
```
|
| 696 |
|
| 697 |
Importable header \`"d.h"\`
|
| 698 |
|
| 699 |
``` cpp
|
|
|
|
| 700 |
import "c.h"; // point of definition of #4 and #5 in "d.h"
|
| 701 |
+
```
|
| 702 |
+
|
| 703 |
+
Importable header \`"e.h"\`
|
| 704 |
+
|
| 705 |
+
``` cpp
|
| 706 |
+
import "a.h"; // point of definition of #1, #2, and #3, point of undefinition of #1 in "e.h"
|
| 707 |
+
import "d.h"; // point of definition of #4 and #5 in "e.h"
|
| 708 |
int a = Y; // OK, active macro definitions #2 and #4 are valid redefinitions
|
| 709 |
int c = Z; // error: active macro definitions #3 and #5 are not valid redefinitions of Z
|
| 710 |
```
|
| 711 |
|
| 712 |
+
Module unit \`f\`
|
| 713 |
+
|
| 714 |
+
``` cpp
|
| 715 |
+
export module f;
|
| 716 |
+
export import "a.h";
|
| 717 |
+
|
| 718 |
+
int a = Y; // OK
|
| 719 |
+
```
|
| 720 |
+
|
| 721 |
+
Translation unit \`#1\`
|
| 722 |
+
|
| 723 |
+
``` cpp
|
| 724 |
+
import f;
|
| 725 |
+
int x = Y; // error: Y is neither a defined macro nor a declared name
|
| 726 |
+
```
|
| 727 |
+
|
| 728 |
— *end example*]
|
| 729 |
|
| 730 |
## Macro replacement <a id="cpp.replace">[[cpp.replace]]</a>
|
| 731 |
|
| 732 |
+
### General <a id="cpp.replace.general">[[cpp.replace.general]]</a>
|
| 733 |
+
|
| 734 |
Two replacement lists are identical if and only if the preprocessing
|
| 735 |
+
tokens in both have the same number, ordering, spelling, and whitespace
|
| 736 |
+
separation, where all whitespace separations are considered identical.
|
| 737 |
|
| 738 |
An identifier currently defined as an object-like macro (see below) may
|
| 739 |
be redefined by another `#define` preprocessing directive provided that
|
| 740 |
the second definition is an object-like macro definition and the two
|
| 741 |
replacement lists are identical, otherwise the program is ill-formed.
|
|
|
|
| 767 |
#define FUNC_LIKE(b) ( b ) // different parameter spelling
|
| 768 |
```
|
| 769 |
|
| 770 |
— *end example*]
|
| 771 |
|
| 772 |
+
There shall be whitespace between the identifier and the replacement
|
| 773 |
list in the definition of an object-like macro.
|
| 774 |
|
| 775 |
If the *identifier-list* in the macro definition does not end with an
|
| 776 |
ellipsis, the number of arguments (including those arguments consisting
|
| 777 |
of no preprocessing tokens) in an invocation of a function-like macro
|
|
|
|
| 786 |
|
| 787 |
A parameter identifier in a function-like macro shall be uniquely
|
| 788 |
declared within its scope.
|
| 789 |
|
| 790 |
The identifier immediately following the `define` is called the *macro
|
| 791 |
+
name*. There is one name space for macro names. Any whitespace
|
| 792 |
characters preceding or following the replacement list of preprocessing
|
| 793 |
tokens are not considered part of the replacement list for either form
|
| 794 |
of macro.
|
| 795 |
|
| 796 |
If a `#` preprocessing token, followed by an identifier, occurs
|
| 797 |
+
lexically at the point at which a preprocessing directive can begin, the
|
| 798 |
+
identifier is not subject to macro replacement.
|
| 799 |
|
| 800 |
A preprocessing directive of the form
|
| 801 |
|
| 802 |
``` bnf
|
| 803 |
'# define' identifier replacement-list new-line
|
| 804 |
```
|
| 805 |
|
| 806 |
defines an *object-like macro* that causes each subsequent instance of
|
| 807 |
+
the macro name[^5]
|
| 808 |
+
|
| 809 |
+
to be replaced by the replacement list of preprocessing tokens that
|
| 810 |
+
constitute the remainder of the directive.[^6]
|
| 811 |
+
|
| 812 |
The replacement list is then rescanned for more macro names as specified
|
| 813 |
below.
|
| 814 |
|
| 815 |
[*Example 2*:
|
| 816 |
|
|
|
|
| 832 |
'# define' identifier lparen identifier-list ', ...' ')' replacement-list new-line
|
| 833 |
```
|
| 834 |
|
| 835 |
defines a *function-like macro* with parameters, whose use is similar
|
| 836 |
syntactically to a function call. The parameters are specified by the
|
| 837 |
+
optional list of identifiers. Each subsequent instance of the
|
|
|
|
|
|
|
| 838 |
function-like macro name followed by a `(` as the next preprocessing
|
| 839 |
token introduces the sequence of preprocessing tokens that is replaced
|
| 840 |
by the replacement list in the definition (an invocation of the macro).
|
| 841 |
The replaced sequence of preprocessing tokens is terminated by the
|
| 842 |
matching `)` preprocessing token, skipping intervening matched pairs of
|
| 843 |
left and right parenthesis preprocessing tokens. Within the sequence of
|
| 844 |
preprocessing tokens making up an invocation of a function-like macro,
|
| 845 |
+
new-line is considered a normal whitespace character.
|
| 846 |
|
| 847 |
The sequence of preprocessing tokens bounded by the outside-most
|
| 848 |
matching parentheses forms the list of arguments for the function-like
|
| 849 |
macro. The individual arguments within the list are separated by comma
|
| 850 |
preprocessing tokens, but comma preprocessing tokens between matching
|
| 851 |
inner parentheses do not separate arguments. If there are sequences of
|
| 852 |
preprocessing tokens within the list of arguments that would otherwise
|
| 853 |
+
act as preprocessing directives,[^7]
|
| 854 |
+
|
| 855 |
+
the behavior is undefined.
|
| 856 |
|
| 857 |
[*Example 3*:
|
| 858 |
|
| 859 |
The following defines a function-like macro whose value is the maximum
|
| 860 |
of its arguments. It has the disadvantages of evaluating one or the
|
|
|
|
| 950 |
macro, the program is ill-formed. A *va-opt-replacement* is treated as
|
| 951 |
if it were a parameter, and the preprocessing token sequence for the
|
| 952 |
corresponding argument is defined as follows. If the substitution of
|
| 953 |
`__VA_ARGS__` as neither an operand of `#` nor `##` consists of no
|
| 954 |
preprocessing tokens, the argument consists of a single placemarker
|
| 955 |
+
preprocessing token [[cpp.concat]], [[cpp.rescan]]. Otherwise, the
|
| 956 |
argument consists of the results of the expansion of the contained
|
| 957 |
*pp-tokens* as the replacement list of the current function-like macro
|
| 958 |
before removal of placemarker tokens, rescanning, and further
|
| 959 |
replacement.
|
| 960 |
|
|
|
|
| 1048 |
concatenated with the following preprocessing token. Placemarker
|
| 1049 |
preprocessing tokens are handled specially: concatenation of two
|
| 1050 |
placemarkers results in a single placemarker preprocessing token, and
|
| 1051 |
concatenation of a placemarker with a non-placemarker preprocessing
|
| 1052 |
token results in the non-placemarker preprocessing token. If the result
|
| 1053 |
+
begins with a sequence matching the syntax of
|
| 1054 |
+
*universal-character-name*, the behavior is undefined.
|
| 1055 |
+
|
| 1056 |
+
[*Note 1*: This determination does not consider the replacement of
|
| 1057 |
+
*universal-character-name*s in translation phase 3
|
| 1058 |
+
[[lex.phases]]. — *end note*]
|
| 1059 |
+
|
| 1060 |
+
If the result is not a valid preprocessing token, the behavior is
|
| 1061 |
+
undefined. The resulting token is available for further macro
|
| 1062 |
+
replacement. The order of evaluation of `##` operators is unspecified.
|
| 1063 |
|
| 1064 |
[*Example 1*:
|
| 1065 |
|
| 1066 |
The sequence
|
| 1067 |
|
|
|
|
| 1276 |
replaced by its replacement list of preprocessing tokens). If the
|
| 1277 |
directive resulting after all replacements does not match one of the two
|
| 1278 |
previous forms, the behavior is undefined; otherwise, the result is
|
| 1279 |
processed as appropriate.
|
| 1280 |
|
| 1281 |
+
## Diagnostic directives <a id="cpp.error">[[cpp.error]]</a>
|
| 1282 |
|
| 1283 |
+
A preprocessing directive of either of the following forms
|
| 1284 |
|
| 1285 |
``` bnf
|
| 1286 |
'# error' pp-tokensₒₚₜ new-line
|
| 1287 |
+
'# warning' pp-tokensₒₚₜ new-line
|
| 1288 |
```
|
| 1289 |
|
| 1290 |
+
causes the implementation to produce a diagnostic message that should
|
| 1291 |
+
include the specified sequence of preprocessing tokens; the `# error`
|
| 1292 |
+
directive renders the program ill-formed.
|
| 1293 |
|
| 1294 |
## Pragma directive <a id="cpp.pragma">[[cpp.pragma]]</a>
|
| 1295 |
|
| 1296 |
A preprocessing directive of the form
|
| 1297 |
|
| 1298 |
``` bnf
|
| 1299 |
'# pragma' pp-tokensₒₚₜ new-line
|
| 1300 |
```
|
| 1301 |
|
| 1302 |
causes the implementation to behave in an *implementation-defined*
|
| 1303 |
+
manner. The behavior may cause translation to fail or cause the
|
| 1304 |
translator or the resulting program to behave in a non-conforming
|
| 1305 |
manner. Any pragma that is not recognized by the implementation is
|
| 1306 |
ignored.
|
| 1307 |
|
| 1308 |
## Null directive <a id="cpp.null">[[cpp.null]]</a>
|
|
|
|
| 1321 |
|
| 1322 |
- **`__cplusplus`**
|
| 1323 |
|
| 1324 |
The integer literal `202302L`.
|
| 1325 |
|
| 1326 |
+
[*Note 1*: Future revisions of C++ will replace the value of this macro
|
| 1327 |
+
with a greater value. — *end note*]
|
| 1328 |
+
|
| 1329 |
+
- **The names listed in [[cpp.predefined.ft]].**
|
| 1330 |
+
|
| 1331 |
+
The macros defined in [[cpp.predefined.ft]] shall be defined to the
|
| 1332 |
+
corresponding integer literal.
|
| 1333 |
+
|
| 1334 |
+
[*Note 2*: Future revisions of C++ might replace the values of these
|
| 1335 |
+
macros with greater values. — *end note*]
|
| 1336 |
|
| 1337 |
- **`__DATE__`**
|
| 1338 |
|
| 1339 |
The date of translation of the source file: a character string literal
|
| 1340 |
of the form `"Mmm dd yyyy"`, where the names of the months are the same
|
|
|
|
| 1354 |
source line (an integer literal).[^10]
|
| 1355 |
|
| 1356 |
- **`__STDC_HOSTED__`**
|
| 1357 |
|
| 1358 |
The integer literal `1` if the implementation is a hosted implementation
|
| 1359 |
+
or the integer literal `0` if it is a freestanding implementation
|
| 1360 |
+
[[intro.compliance]].
|
| 1361 |
|
| 1362 |
- **`__STDCPP_DEFAULT_NEW_ALIGNMENT__`**
|
| 1363 |
|
| 1364 |
An integer literal of type `std::size_t` whose value is the alignment
|
| 1365 |
guaranteed by a call to `operator new(std::size_t)` or
|
| 1366 |
`operator new[](std::size_t)`.
|
| 1367 |
|
| 1368 |
+
[*Note 3*: Larger alignments will be passed to
|
| 1369 |
`operator new(std::size_t, std::align_val_t)`, etc.
|
| 1370 |
[[expr.new]]. — *end note*]
|
| 1371 |
|
| 1372 |
+
- **`__STDCPP_FLOAT16_T__`**
|
| 1373 |
+
|
| 1374 |
+
Defined as the integer literal `1` if and only if the implementation
|
| 1375 |
+
supports the ISO/IEC/IEEE 60559 floating-point interchange format
|
| 1376 |
+
binary16 as an extended floating-point type [[basic.extended.fp]].
|
| 1377 |
+
|
| 1378 |
+
- **`__STDCPP_FLOAT32_T__`**
|
| 1379 |
+
|
| 1380 |
+
Defined as the integer literal `1` if and only if the implementation
|
| 1381 |
+
supports the ISO/IEC/IEEE 60559 floating-point interchange format
|
| 1382 |
+
binary32 as an extended floating-point type.
|
| 1383 |
+
|
| 1384 |
+
- **`__STDCPP_FLOAT64_T__`**
|
| 1385 |
+
|
| 1386 |
+
Defined as the integer literal `1` if and only if the implementation
|
| 1387 |
+
supports the ISO/IEC/IEEE 60559 floating-point interchange format
|
| 1388 |
+
binary64 as an extended floating-point type.
|
| 1389 |
+
|
| 1390 |
+
- **`__STDCPP_FLOAT128_T__`**
|
| 1391 |
+
|
| 1392 |
+
Defined as the integer literal `1` if and only if the implementation
|
| 1393 |
+
supports the ISO/IEC/IEEE 60559 floating-point interchange format
|
| 1394 |
+
binary128 as an extended floating-point type.
|
| 1395 |
+
|
| 1396 |
+
- **`__STDCPP_BFLOAT16_T__`**
|
| 1397 |
+
|
| 1398 |
+
Defined as the integer literal `1` if and only if the implementation
|
| 1399 |
+
supports an extended floating-point type with the properties of the
|
| 1400 |
+
\*typedef-name\* `std::bfloat16_t` as described in
|
| 1401 |
+
[[basic.extended.fp]].
|
| 1402 |
+
|
| 1403 |
- **`__TIME__`**
|
| 1404 |
|
| 1405 |
The time of translation of the source file: a character string literal
|
| 1406 |
of the form `"hh:mm:ss"` as in the time generated by the `asctime`
|
| 1407 |
function. If the time of translation is not available, an
|
| 1408 |
*implementation-defined* valid time shall be supplied.
|
| 1409 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1410 |
**Table: Feature-test macros** <a id="cpp.predefined.ft">[cpp.predefined.ft]</a>
|
| 1411 |
|
| 1412 |
| Macro name | Value |
|
| 1413 |
| --------------------------------------- | --------- |
|
| 1414 |
| `__cpp_aggregate_bases` | `201603L` |
|
| 1415 |
| `__cpp_aggregate_nsdmi` | `201304L` |
|
| 1416 |
| `__cpp_aggregate_paren_init` | `201902L` |
|
| 1417 |
| `__cpp_alias_templates` | `200704L` |
|
| 1418 |
| `__cpp_aligned_new` | `201606L` |
|
| 1419 |
| `__cpp_attributes` | `200809L` |
|
| 1420 |
+
| `__cpp_auto_cast` | `202110L` |
|
| 1421 |
| `__cpp_binary_literals` | `201304L` |
|
| 1422 |
| `__cpp_capture_star_this` | `201603L` |
|
| 1423 |
+
| `__cpp_char8_t` | `202207L` |
|
| 1424 |
+
| `__cpp_concepts` | `202002L` |
|
| 1425 |
| `__cpp_conditional_explicit` | `201806L` |
|
| 1426 |
+
| `__cpp_constexpr` | `202211L` |
|
| 1427 |
| `__cpp_constexpr_dynamic_alloc` | `201907L` |
|
| 1428 |
| `__cpp_constexpr_in_decltype` | `201711L` |
|
| 1429 |
+
| `__cpp_consteval` | `202211L` |
|
| 1430 |
| `__cpp_constinit` | `201907L` |
|
| 1431 |
| `__cpp_decltype` | `200707L` |
|
| 1432 |
| `__cpp_decltype_auto` | `201304L` |
|
| 1433 |
| `__cpp_deduction_guides` | `201907L` |
|
| 1434 |
| `__cpp_delegating_constructors` | `200604L` |
|
| 1435 |
| `__cpp_designated_initializers` | `201707L` |
|
| 1436 |
| `__cpp_enumerator_attributes` | `201411L` |
|
| 1437 |
+
| `__cpp_explicit_this_parameter` | `202110L` |
|
| 1438 |
| `__cpp_fold_expressions` | `201603L` |
|
| 1439 |
| `__cpp_generic_lambdas` | `201707L` |
|
| 1440 |
| `__cpp_guaranteed_copy_elision` | `201606L` |
|
| 1441 |
| `__cpp_hex_float` | `201603L` |
|
| 1442 |
+
| `__cpp_if_consteval` | `202106L` |
|
| 1443 |
| `__cpp_if_constexpr` | `201606L` |
|
| 1444 |
| `__cpp_impl_coroutine` | `201902L` |
|
| 1445 |
| `__cpp_impl_destroying_delete` | `201806L` |
|
| 1446 |
| `__cpp_impl_three_way_comparison` | `201907L` |
|
| 1447 |
+
| `__cpp_implicit_move` | `202207L` |
|
| 1448 |
| `__cpp_inheriting_constructors` | `201511L` |
|
| 1449 |
| `__cpp_init_captures` | `201803L` |
|
| 1450 |
| `__cpp_initializer_lists` | `200806L` |
|
| 1451 |
| `__cpp_inline_variables` | `201606L` |
|
| 1452 |
| `__cpp_lambdas` | `200907L` |
|
| 1453 |
| `__cpp_modules` | `201907L` |
|
| 1454 |
+
| `__cpp_multidimensional_subscript` | `202211L` |
|
| 1455 |
+
| `__cpp_named_character_escapes` | `202207L` |
|
| 1456 |
| `__cpp_namespace_attributes` | `201411L` |
|
| 1457 |
| `__cpp_noexcept_function_type` | `201510L` |
|
| 1458 |
| `__cpp_nontype_template_args` | `201911L` |
|
| 1459 |
| `__cpp_nontype_template_parameter_auto` | `201606L` |
|
| 1460 |
| `__cpp_nsdmi` | `200809L` |
|
| 1461 |
+
| `__cpp_range_based_for` | `202211L` |
|
| 1462 |
| `__cpp_raw_strings` | `200710L` |
|
| 1463 |
| `__cpp_ref_qualifiers` | `200710L` |
|
| 1464 |
| `__cpp_return_type_deduction` | `201304L` |
|
| 1465 |
| `__cpp_rvalue_references` | `200610L` |
|
| 1466 |
+
| `__cpp_size_t_suffix` | `202011L` |
|
| 1467 |
| `__cpp_sized_deallocation` | `201309L` |
|
| 1468 |
| `__cpp_static_assert` | `201411L` |
|
| 1469 |
+
| `__cpp_static_call_operator` | `202207L` |
|
| 1470 |
| `__cpp_structured_bindings` | `201606L` |
|
| 1471 |
| `__cpp_template_template_args` | `201611L` |
|
| 1472 |
| `__cpp_threadsafe_static_init` | `200806L` |
|
| 1473 |
| `__cpp_unicode_characters` | `200704L` |
|
| 1474 |
| `__cpp_unicode_literals` | `200710L` |
|
|
|
|
| 1499 |
Whether \_\_STDC_VERSION\_\_ is predefined and if so, what its value is,
|
| 1500 |
are *implementation-defined*.
|
| 1501 |
|
| 1502 |
- **`__STDC_ISO_10646__`**
|
| 1503 |
|
| 1504 |
+
An integer literal of the form `yyyymmL` (for example, `199712L`).
|
| 1505 |
+
Whether \_\_STDC_ISO_10646\_\_ is predefined and if so, what its value
|
| 1506 |
+
is, are *implementation-defined*.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1507 |
|
| 1508 |
- **`__STDCPP_THREADS__`**
|
| 1509 |
|
| 1510 |
Defined, and has the value integer literal 1, if and only if a program
|
| 1511 |
can have more than one thread of execution [[intro.multithread]].
|
|
|
|
| 1559 |
```
|
| 1560 |
|
| 1561 |
— *end example*]
|
| 1562 |
|
| 1563 |
<!-- Link reference definitions -->
|
| 1564 |
+
[basic.extended.fp]: basic.md#basic.extended.fp
|
| 1565 |
[cpp]: #cpp
|
| 1566 |
[cpp.concat]: #cpp.concat
|
| 1567 |
[cpp.cond]: #cpp.cond
|
| 1568 |
[cpp.cond.ha]: #cpp.cond.ha
|
| 1569 |
[cpp.error]: #cpp.error
|
|
|
|
| 1576 |
[cpp.pragma.op]: #cpp.pragma.op
|
| 1577 |
[cpp.pre]: #cpp.pre
|
| 1578 |
[cpp.predefined]: #cpp.predefined
|
| 1579 |
[cpp.predefined.ft]: #cpp.predefined.ft
|
| 1580 |
[cpp.replace]: #cpp.replace
|
| 1581 |
+
[cpp.replace.general]: #cpp.replace.general
|
| 1582 |
[cpp.rescan]: #cpp.rescan
|
| 1583 |
[cpp.scope]: #cpp.scope
|
| 1584 |
[cpp.stringize]: #cpp.stringize
|
| 1585 |
[cpp.subst]: #cpp.subst
|
| 1586 |
+
[cstdint.syn]: support.md#cstdint.syn
|
| 1587 |
[expr.const]: expr.md#expr.const
|
| 1588 |
[expr.new]: expr.md#expr.new
|
| 1589 |
+
[intro.compliance]: intro.md#intro.compliance
|
| 1590 |
[intro.multithread]: basic.md#intro.multithread
|
| 1591 |
+
[lex.ccon]: lex.md#lex.ccon
|
| 1592 |
[lex.digraph]: lex.md#lex.digraph
|
| 1593 |
[lex.key]: lex.md#lex.key
|
| 1594 |
[lex.name]: lex.md#lex.name
|
| 1595 |
[lex.phases]: lex.md#lex.phases
|
| 1596 |
[lex.token]: lex.md#lex.token
|
| 1597 |
[module.import]: module.md#module.import
|
|
|
|
| 1598 |
[support.limits]: support.md#support.limits
|
| 1599 |
|
| 1600 |
[^1]: Thus, preprocessing directives are commonly called “lines”. These
|
| 1601 |
“lines” have no other syntactic significance, as all whitespace is
|
| 1602 |
equivalent except in certain situations during preprocessing (see
|
|
|
|
| 1605 |
|
| 1606 |
[^2]: Because the controlling constant expression is evaluated during
|
| 1607 |
translation phase 4, all identifiers either are or are not macro
|
| 1608 |
names — there simply are no keywords, enumeration constants, etc.
|
| 1609 |
|
| 1610 |
+
[^3]: As indicated by the syntax, a preprocessing token cannot follow a
|
| 1611 |
+
`#else` or `#endif` directive before the terminating new-line
|
| 1612 |
+
character. However, comments can appear anywhere in a source file,
|
| 1613 |
including within a preprocessing directive.
|
| 1614 |
|
| 1615 |
[^4]: Note that adjacent *string-literal*s are not concatenated into a
|
| 1616 |
single *string-literal* (see the translation phases in
|
| 1617 |
[[lex.phases]]); thus, an expansion that results in two
|