From Jason Turner

[cpp]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpow8v1lfx/{from.md → to.md} +788 -301
tmp/tmpow8v1lfx/{from.md → to.md} RENAMED
@@ -1,21 +1,28 @@
1
  # Preprocessing directives <a id="cpp">[[cpp]]</a>
2
 
3
- A *preprocessing directive* consists of a sequence of preprocessing
4
- tokens that satisfies the following constraints: The first token in the
5
- sequence is a `#` preprocessing token that (at the start of translation
6
- phase 4) is either the first character in the source file (optionally
7
- after white space containing no new-line characters) or that follows
8
- white space containing at least one new-line character. The last token
9
- in the sequence is the first new-line character that follows the first
10
- token in the sequence.[^1] A new-line character ends the preprocessing
11
- directive even if it occurs within what would otherwise be an invocation
12
- of a function-like macro.
13
 
14
  ``` bnf
15
  preprocessing-file:
16
  groupₒₚₜ
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  ```
18
 
19
  ``` bnf
20
  group:
21
  group-part
@@ -28,21 +35,58 @@ group-part:
28
  if-section
29
  text-line
30
  '#' conditionally-supported-directive
31
  ```
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  ``` bnf
34
  if-section:
35
  if-group elif-groupsₒₚₜ else-groupₒₚₜ endif-line
36
  ```
37
 
 
 
 
 
 
 
 
38
  ``` bnf
39
  elif-groups:
40
  elif-group
41
  elif-groups elif-group
42
  ```
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  ``` bnf
45
  text-line:
46
  pp-tokensₒₚₜ new-line
47
  ```
48
 
@@ -76,36 +120,94 @@ pp-tokens:
76
  ``` bnf
77
  new-line:
78
  the new-line character
79
  ```
80
 
81
- A text line shall not begin with a `#` preprocessing token. A
82
- *conditionally-supported-directive* shall not begin with any of the
83
- directive names appearing in the syntax. A
84
- *conditionally-supported-directive* is conditionally-supported with
85
- *implementation-defined* semantics.
 
 
86
 
87
- When in a group that is skipped ([[cpp.cond]]), the directive syntax is
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  relaxed to allow any sequence of preprocessing tokens to occur between
89
  the directive name and the following new-line character.
90
 
91
  The only white-space characters that shall appear between preprocessing
92
- tokens within a preprocessing directive (from just after the introducing
93
- `#` preprocessing token through just before the terminating new-line
94
  character) are space and horizontal-tab (including spaces that have
95
  replaced comments or possibly other white-space characters in
96
  translation phase 3).
97
 
98
  The implementation can process and skip sections of source files
99
- conditionally, include other source files, and replace macros. These
100
- capabilities are called *preprocessing*, because conceptually they occur
101
- before translation of the resulting translation unit.
 
102
 
103
  The preprocessing tokens within a preprocessing directive are not
104
  subject to macro expansion unless otherwise stated.
105
 
106
- [*Example 1*:
107
 
108
  In:
109
 
110
  ``` cpp
111
  #define EMPTY
@@ -136,55 +238,102 @@ h-preprocessing-token:
136
  h-pp-tokens:
137
  h-preprocessing-token
138
  h-pp-tokens h-preprocessing-token
139
  ```
140
 
 
 
 
 
 
 
141
  ``` bnf
142
  has-include-expression:
143
- '__has_include ( <' h-char-sequence '> )'
144
- '__has_include ( "' q-char-sequence '" )'
145
- '__has_include (' string-literal ')'
146
- '__has_include ( <' h-pp-tokens '> )'
 
 
 
147
  ```
148
 
149
  The expression that controls conditional inclusion shall be an integral
150
  constant expression except that identifiers (including those lexically
151
  identical to keywords) are interpreted as described below[^2] and it may
152
  contain zero or more *defined-macro-expression*s and/or
153
- *has-include-expression*s as unary operator expressions.
 
154
 
155
  A *defined-macro-expression* evaluates to `1` if the identifier is
156
  currently defined as a macro name (that is, if it is predefined or if it
157
- has been the subject of a `#define` preprocessing directive without an
158
- intervening `#undef` directive with the same subject identifier), `0` if
159
- it is not.
 
160
 
161
- The third and fourth forms of *has-include-expression* are considered
162
- only if neither of the first or second forms matches, in which case the
163
- preprocessing tokens are processed just as in normal text.
164
 
165
  The header or source file identified by the parenthesized preprocessing
166
  token sequence in each contained *has-include-expression* is searched
167
  for as if that preprocessing token sequence were the *pp-tokens* in a
168
  `#include` directive, except that no further macro expansion is
169
  performed. If such a directive would not satisfy the syntactic
170
  requirements of a `#include` directive, the program is ill-formed. The
171
  *has-include-expression* evaluates to `1` if the search for the source
172
  file succeeds, and to `0` if the search fails.
173
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
  The `#ifdef` and `#ifndef` directives, and the `defined` conditional
175
- inclusion operator, shall treat `__has_include` as if it were the name
176
- of a defined macro. The identifier `__has_include` shall not appear in
177
- any context not mentioned in this section.
 
178
 
179
  Each preprocessing token that remains (in the list of preprocessing
180
  tokens that will become the controlling expression) after all macro
181
- replacements have occurred shall be in the lexical form of a token (
182
- [[lex.token]]).
183
 
184
  Preprocessing directives of the forms
185
 
 
 
 
 
 
186
  check whether the controlling constant expression evaluates to nonzero.
187
 
188
  Prior to evaluation, macro invocations in the list of preprocessing
189
  tokens that will become the controlling constant expression are replaced
190
  (except for those macro names modified by the `defined` unary operator),
@@ -192,60 +341,65 @@ just as in normal text. If the token `defined` is generated as a result
192
  of this replacement process or use of the `defined` unary operator does
193
  not match one of the two specified forms prior to macro replacement, the
194
  behavior is undefined.
195
 
196
  After all replacements due to macro expansion and evaluations of
197
- *defined-macro-expression*s and *has-include-expression*s have been
198
- performed, all remaining identifiers and keywords, except for `true` and
199
- `false`, are replaced with the *pp-number* `0`, and then each
200
- preprocessing token is converted into a token.
 
201
 
202
- [*Note 1*: An alternative token ([[lex.digraph]]) is not an
203
- identifier, even when its spelling consists entirely of letters and
204
- underscores. Therefore it is not subject to this
205
- replacement. — *end note*]
206
 
207
  The resulting tokens comprise the controlling constant expression which
208
  is evaluated according to the rules of  [[expr.const]] using arithmetic
209
  that has at least the ranges specified in  [[support.limits]]. For the
210
  purposes of this token conversion and evaluation all signed and unsigned
211
  integer types act as if they have the same representation as,
212
- respectively, `intmax_t` or `uintmax_t` ([[cstdint]]).
213
 
214
- [*Note 2*: Thus on an implementation where
215
  `std::numeric_limits<int>::max()` is `0x7FFF` and
216
  `std::numeric_limits<unsigned int>::max()` is `0xFFFF`, the integer
217
  literal `0x8000` is signed and positive within a `#if` expression even
218
- though it is unsigned in translation phase 7 (
219
- [[lex.phases]]). — *end note*]
220
 
221
- This includes interpreting character literals, which may involve
222
  converting escape sequences into execution character set members.
223
- Whether the numeric value for these character literals matches the value
224
- obtained when an identical character literal occurs in an expression
225
- (other than within a `#if` or `#elif` directive) is
226
  *implementation-defined*.
227
 
228
- [*Note 3*:
229
 
230
  Thus, the constant expression in the following `#if` directive and `if`
231
- statement is not guaranteed to evaluate to the same value in these two
232
- contexts:
233
 
234
  ``` cpp
235
  #if 'z' - 'a' == 25
236
  if ('z' - 'a' == 25)
237
  ```
238
 
239
  — *end note*]
240
 
241
- Also, whether a single-character character literal may have a negative
242
  value is *implementation-defined*. Each subexpression with type `bool`
243
  is subjected to integral promotion before processing continues.
244
 
245
  Preprocessing directives of the forms
246
 
 
 
 
 
 
247
  check whether the identifier is or is not currently defined as a macro
248
  name. Their conditions are equivalent to `#if` `defined` *identifier*
249
  and `#if` `!defined` *identifier* respectively.
250
 
251
  Each directive’s condition is checked in order. If it evaluates to false
@@ -267,22 +421,43 @@ This demonstrates a way to include a library `optional` facility only if
267
  it is available:
268
 
269
  ``` cpp
270
  #if __has_include(<optional>)
271
  # include <optional>
 
272
  # define have_optional 1
 
273
  #elif __has_include(<experimental/optional>)
274
  # include <experimental/optional>
 
275
  # define have_optional 1
276
  # define experimental_optional 1
277
- #else
 
 
278
  # define have_optional 0
279
  #endif
280
  ```
281
 
282
  — *end example*]
283
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  ## Source file inclusion <a id="cpp.include">[[cpp.include]]</a>
285
 
286
  A `#include` directive shall identify a header or source file that can
287
  be processed by the implementation.
288
 
@@ -332,19 +507,28 @@ two previous forms, the behavior is undefined.[^4] The method by which a
332
  sequence of preprocessing tokens between a `<` and a `>` preprocessing
333
  token pair or a pair of `"` characters is combined into a single header
334
  name preprocessing token is *implementation-defined*.
335
 
336
  The implementation shall provide unique mappings for sequences
337
- consisting of one or more *nondigit*s or *digit*s ([[lex.name]])
338
- followed by a period (`.`) and a single *nondigit*. The first character
339
- shall not be a *digit*. The implementation may ignore distinctions of
340
- alphabetical case.
341
 
342
  A `#include` preprocessing directive may appear in a source file that
343
  has been read because of a `#include` directive in another file, up to
344
  an *implementation-defined* nesting limit.
345
 
 
 
 
 
 
 
 
 
 
346
  [*Note 1*:
347
 
348
  Although an implementation may provide a mechanism for making arbitrary
349
  source files available to the `< >` search, in general programmers
350
  should use the `< >` form for headers provided with the implementation,
@@ -375,10 +559,153 @@ This illustrates macro-replaced `#include` directives:
375
  #include INCFILE
376
  ```
377
 
378
  — *end example*]
379
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
380
  ## Macro replacement <a id="cpp.replace">[[cpp.replace]]</a>
381
 
382
  Two replacement lists are identical if and only if the preprocessing
383
  tokens in both have the same number, ordering, spelling, and white-space
384
  separation, where all white-space separations are considered identical.
@@ -391,24 +718,48 @@ Likewise, an identifier currently defined as a function-like macro (see
391
  below) may be redefined by another `#define` preprocessing directive
392
  provided that the second definition is a function-like macro definition
393
  that has the same number and spelling of parameters, and the two
394
  replacement lists are identical, otherwise the program is ill-formed.
395
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
396
  There shall be white-space between the identifier and the replacement
397
  list in the definition of an object-like macro.
398
 
399
  If the *identifier-list* in the macro definition does not end with an
400
  ellipsis, the number of arguments (including those arguments consisting
401
  of no preprocessing tokens) in an invocation of a function-like macro
402
  shall equal the number of parameters in the macro definition. Otherwise,
403
- there shall be more arguments in the invocation than there are
404
  parameters in the macro definition (excluding the `...`). There shall
405
  exist a `)` preprocessing token that terminates the invocation.
406
 
407
- The identifier `__VA_ARGS__` shall occur only in the *replacement-list*
408
- of a function-like macro that uses the ellipsis notation in the
409
- parameters.
410
 
411
  A parameter identifier in a function-like macro shall be uniquely
412
  declared within its scope.
413
 
414
  The identifier immediately following the `define` is called the *macro
@@ -431,10 +782,22 @@ defines an *object-like macro* that causes each subsequent instance of
431
  the macro name[^5] to be replaced by the replacement list of
432
  preprocessing tokens that constitute the remainder of the directive.[^6]
433
  The replacement list is then rescanned for more macro names as specified
434
  below.
435
 
 
 
 
 
 
 
 
 
 
 
 
 
436
  A preprocessing directive of the form
437
 
438
  ``` bnf
439
  '# define' identifier lparen identifier-listₒₚₜ ')' replacement-list new-line
440
  '# define' identifier lparen '...' ')' replacement-list new-line
@@ -461,56 +824,184 @@ macro. The individual arguments within the list are separated by comma
461
  preprocessing tokens, but comma preprocessing tokens between matching
462
  inner parentheses do not separate arguments. If there are sequences of
463
  preprocessing tokens within the list of arguments that would otherwise
464
  act as preprocessing directives,[^7] the behavior is undefined.
465
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
466
  If there is a `...` immediately preceding the `)` in the function-like
467
- macro definition, then the trailing arguments, including any separating
468
- comma preprocessing tokens, are merged to form a single item: the
469
- *variable arguments*. The number of arguments so combined is such that,
470
- following merger, the number of arguments is one more than the number of
471
- parameters in the macro definition (excluding the `...`).
 
472
 
473
  ### Argument substitution <a id="cpp.subst">[[cpp.subst]]</a>
474
 
 
 
 
 
 
475
  After the arguments for the invocation of a function-like macro have
476
- been identified, argument substitution takes place. A parameter in the
477
- replacement list, unless preceded by a `#` or `##` preprocessing token
478
- or followed by a `##` preprocessing token (see below), is replaced by
479
- the corresponding argument after all macros contained therein have been
480
- expanded. Before being substituted, each argument’s preprocessing tokens
481
- are completely macro replaced as if they formed the rest of the
482
- preprocessing file; no other preprocessing tokens are available.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
483
 
484
  An identifier `__VA_ARGS__` that occurs in the replacement list shall be
485
  treated as if it were a parameter, and the variable arguments shall form
486
  the preprocessing tokens used to replace it.
487
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
488
  ### The `#` operator <a id="cpp.stringize">[[cpp.stringize]]</a>
489
 
490
  Each `#` preprocessing token in the replacement list for a function-like
491
  macro shall be followed by a parameter as the next preprocessing token
492
  in the replacement list.
493
 
494
  A *character string literal* is a *string-literal* with no prefix. If,
495
  in the replacement list, a parameter is immediately preceded by a `#`
496
  preprocessing token, both are replaced by a single character string
497
  literal preprocessing token that contains the spelling of the
498
- preprocessing token sequence for the corresponding argument. Each
499
- occurrence of white space between the argument’s preprocessing tokens
500
- becomes a single space character in the character string literal. White
501
- space before the first preprocessing token and after the last
502
- preprocessing token comprising the argument is deleted. Otherwise, the
503
- original spelling of each preprocessing token in the argument is
504
- retained in the character string literal, except for special handling
505
- for producing the spelling of string literals and character literals: a
506
- `\` character is inserted before each `"` and `\` character of a
507
- character literal or string literal (including the delimiting `"`
508
- characters). If the replacement that results is not a valid character
509
- string literal, the behavior is undefined. The character string literal
510
- corresponding to an empty argument is `""`. The order of evaluation of
511
- `#` and `##` operators is unspecified.
 
 
 
512
 
513
  ### The `##` operator <a id="cpp.concat">[[cpp.concat]]</a>
514
 
515
  A `##` preprocessing token shall not occur at the beginning or at the
516
  end of a replacement list for either form of macro definition.
@@ -535,10 +1026,58 @@ is not a valid preprocessing token, the behavior is undefined. The
535
  resulting token is available for further macro replacement. The order of
536
  evaluation of `##` operators is unspecified.
537
 
538
  [*Example 1*:
539
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
540
  In the following fragment:
541
 
542
  ``` cpp
543
  #define hash_hash # ## #
544
  #define mkstr(a) # a
@@ -561,83 +1100,41 @@ In other words, expanding `hash_hash` produces a new token, consisting
561
  of two adjacent sharp signs, but this new token is not the `##`
562
  operator.
563
 
564
  — *end example*]
565
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
566
  ### Rescanning and further replacement <a id="cpp.rescan">[[cpp.rescan]]</a>
567
 
568
  After all parameters in the replacement list have been substituted and
569
  `#` and `##` processing has taken place, all placemarker preprocessing
570
  tokens are removed. Then the resulting preprocessing token sequence is
571
  rescanned, along with all subsequent preprocessing tokens of the source
572
  file, for more macro names to replace.
573
 
574
- If the name of the macro being replaced is found during this scan of the
575
- replacement list (not including the rest of the source file’s
576
- preprocessing tokens), it is not replaced. Furthermore, if any nested
577
- replacements encounter the name of the macro being replaced, it is not
578
- replaced. These nonreplaced macro name preprocessing tokens are no
579
- longer available for further replacement even if they are later
580
- (re)examined in contexts in which that macro name preprocessing token
581
- would otherwise have been replaced.
582
-
583
- The resulting completely macro-replaced preprocessing token sequence is
584
- not processed as a preprocessing directive even if it resembles one, but
585
- all pragma unary operator expressions within it are then processed as
586
- specified in  [[cpp.pragma.op]] below.
587
-
588
- ### Scope of macro definitions <a id="cpp.scope">[[cpp.scope]]</a>
589
-
590
- A macro definition lasts (independent of block structure) until a
591
- corresponding `#undef` directive is encountered or (if none is
592
- encountered) until the end of the translation unit. Macro definitions
593
- have no significance after translation phase 4.
594
-
595
- A preprocessing directive of the form
596
-
597
- ``` bnf
598
- '# undef' identifier new-line
599
- ```
600
-
601
- causes the specified identifier no longer to be defined as a macro name.
602
- It is ignored if the specified identifier is not currently defined as a
603
- macro name.
604
-
605
  [*Example 1*:
606
 
607
- The simplest use of this facility is to define a “manifest constant”, as
608
- in
609
-
610
- ``` cpp
611
- #define TABSIZE 100
612
- int table[TABSIZE];
613
- ```
614
-
615
- — *end example*]
616
-
617
- [*Example 2*:
618
-
619
- The following defines a function-like macro whose value is the maximum
620
- of its arguments. It has the advantages of working for any compatible
621
- types of the arguments and of generating in-line code without the
622
- overhead of function calling. It has the disadvantages of evaluating one
623
- or the other of its arguments a second time (including side effects) and
624
- generating more code than a function if invoked several times. It also
625
- cannot have its address taken, as it has none.
626
-
627
- ``` cpp
628
- #define max(a, b) ((a) > (b) ? (a) : (b))
629
- ```
630
-
631
- The parentheses ensure that the arguments and the resulting expression
632
- are bound properly.
633
-
634
- — *end example*]
635
-
636
- [*Example 3*:
637
-
638
- To illustrate the rules for redefinition and reexamination, the sequence
639
 
640
  ``` cpp
641
  #define x 3
642
  #define f(a) f(x * (a))
643
  #undef x
@@ -669,137 +1166,49 @@ int i[] = { 1, 23, 4, 5, };
669
  char c[2][6] = { "hello", "" };
670
  ```
671
 
672
  — *end example*]
673
 
674
- [*Example 4*:
 
 
 
 
 
 
 
675
 
676
- To illustrate the rules for creating character string literals and
677
- concatenating tokens, the sequence
 
 
678
 
679
- ``` cpp
680
- #define str(s) # s
681
- #define xstr(s) str(s)
682
- #define debug(s, t) printf("x" # s "= %d, x" # t "= %s", \
683
- x ## s, x ## t)
684
- #define INCFILE(n) vers ## n
685
- #define glue(a, b) a ## b
686
- #define xglue(a, b) glue(a, b)
687
- #define HIGHLOW "hello"
688
- #define LOW LOW ", world"
689
 
690
- debug(1, 2);
691
- fputs(str(strncmp("abc\0d", "abc", '\4') // this goes away
692
- == 0) str(: \@n), s);
693
- #include xstr(INCFILE(2).h)
694
- glue(HIGH, LOW);
695
- xglue(HIGH, LOW)
696
- ```
697
-
698
- results in
699
-
700
- ``` cpp
701
- printf("x" "1" "= %d, x" "2" "= %s", x1, x2);
702
- fputs("strncmp(\"abc\\0d\", \"abc\", '\\4') == 0" ": \@n", s);
703
- #include "vers2.h" (after macro replacement, before file access)
704
- "hello";
705
- "hello" ", world"
706
- ```
707
-
708
- or, after concatenation of the character string literals,
709
-
710
- ``` cpp
711
- printf("x1= %d, x2= %s", x1, x2);
712
- fputs("strncmp(\"abc\\0d\", \"abc\", '\\4') == 0: \@n", s);
713
- #include "vers2.h" (after macro replacement, before file access)
714
- "hello";
715
- "hello, world"
716
- ```
717
-
718
- Space around the `#` and `##` tokens in the macro definition is
719
- optional.
720
-
721
- — *end example*]
722
-
723
- [*Example 5*:
724
-
725
- To illustrate the rules for placemarker preprocessing tokens, the
726
- sequence
727
-
728
- ``` cpp
729
- #define t(x,y,z) x ## y ## z
730
- int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,),
731
- t(10,,), t(,11,), t(,,12), t(,,) };
732
- ```
733
-
734
- results in
735
-
736
- ``` cpp
737
- int j[] = { 123, 45, 67, 89,
738
- 10, 11, 12, };
739
- ```
740
-
741
- — *end example*]
742
-
743
- [*Example 6*:
744
-
745
- To demonstrate the redefinition rules, the following sequence is valid.
746
-
747
- ``` cpp
748
- #define OBJ_LIKE (1-1)
749
- #define OBJ_LIKE /* white space */ (1-1) /* other */
750
- #define FUNC_LIKE(a) ( a )
751
- #define FUNC_LIKE( a )( /* note the white space */ \
752
- a /* other stuff on this line
753
- */ )
754
- ```
755
-
756
- But the following redefinitions are invalid:
757
-
758
- ``` cpp
759
- #define OBJ_LIKE (0) // different token sequence
760
- #define OBJ_LIKE (1 - 1) // different white space
761
- #define FUNC_LIKE(b) ( a ) // different parameter usage
762
- #define FUNC_LIKE(b) ( b ) // different parameter spelling
763
- ```
764
-
765
- — *end example*]
766
-
767
- [*Example 7*:
768
-
769
- Finally, to show the variable argument list macro facilities:
770
-
771
- ``` cpp
772
- #define debug(...) fprintf(stderr, __VA_ARGS__)
773
- #define showlist(...) puts(#__VA_ARGS__)
774
- #define report(test, ...) ((test) ? puts(#test) : printf(__VA_ARGS__))
775
- debug("Flag");
776
- debug("X = %d\n", x);
777
- showlist(The first, second, and third items.);
778
- report(x>y, "x is %d but y is %d", x, y);
779
- ```
780
 
781
- results in
782
 
783
- ``` cpp
784
- fprintf(stderr, "Flag");
785
- fprintf(stderr, "X = %d\n", x);
786
- puts("The first, second, and third items.");
787
- ((x>y) ? puts("x>y") : printf("x is %d but y is %d", x, y));
788
  ```
789
 
790
- *end example*]
 
 
791
 
792
  ## Line control <a id="cpp.line">[[cpp.line]]</a>
793
 
794
- The string literal of a `#line` directive, if present, shall be a
795
  character string literal.
796
 
797
  The *line number* of the current source line is one greater than the
798
- number of new-line characters read or introduced in translation phase
799
- 1 ([[lex.phases]]) while processing the source file to the current
800
- token.
801
 
802
  A preprocessing directive of the form
803
 
804
  ``` bnf
805
  '# line' digit-sequence new-line
@@ -874,11 +1283,15 @@ has no effect.
874
 
875
  The following macro names shall be defined by the implementation:
876
 
877
  - **`__cplusplus`**
878
 
879
- The integer literal `202302L`.[^9]
 
 
 
 
880
 
881
  - **`__DATE__`**
882
 
883
  The date of translation of the source file: a character string literal
884
  of the form `"Mmm dd yyyy"`, where the names of the months are the same
@@ -888,16 +1301,16 @@ translation is not available, an *implementation-defined* valid date
888
  shall be supplied.
889
 
890
  - **`__FILE__`**
891
 
892
  The presumed name of the current source file (a character string
893
- literal). [^10]
894
 
895
  - **`__LINE__`**
896
 
897
  The presumed line number (within the current source file) of the current
898
- source line (an integer literal). [^11]
899
 
900
  - **`__STDC_HOSTED__`**
901
 
902
  The integer literal `1` if the implementation is a hosted implementation
903
  or the integer literal `0` if it is not.
@@ -906,21 +1319,93 @@ or the integer literal `0` if it is not.
906
 
907
  An integer literal of type `std::size_t` whose value is the alignment
908
  guaranteed by a call to `operator new(std::size_t)` or
909
  `operator new[](std::size_t)`.
910
 
911
- [*Note 1*: Larger alignments will be passed to
912
- `operator new(std::size_t, std::align_val_t)`, etc. (
913
- [[expr.new]]). — *end note*]
914
 
915
  - **`__TIME__`**
916
 
917
  The time of translation of the source file: a character string literal
918
  of the form `"hh:mm:ss"` as in the time generated by the `asctime`
919
  function. If the time of translation is not available, an
920
  *implementation-defined* valid time shall be supplied.
921
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
922
  The following macro names are conditionally defined by the
923
  implementation:
924
 
925
  - **`__STDC__`**
926
 
@@ -942,25 +1427,24 @@ are *implementation-defined*.
942
  - **`__STDC_ISO_10646__`**
943
 
944
  An integer literal of the form `yyyymmL` (for example, `199712L`). If
945
  this symbol is defined, then every character in the Unicode required
946
  set, when stored in an object of type `wchar_t`, has the same value as
947
- the short identifier of that character. The *Unicode required set*
948
- consists of all the characters that are defined by ISO/IEC 10646, along
949
- with all amendments and technical corrigenda as of the specified year
950
- and month.
951
 
952
  - **`__STDCPP_STRICT_POINTER_SAFETY__`**
953
 
954
  Defined, and has the value integer literal 1, if and only if the
955
- implementation has strict pointer safety (
956
- [[basic.stc.dynamic.safety]]).
957
 
958
  - **`__STDCPP_THREADS__`**
959
 
960
  Defined, and has the value integer literal 1, if and only if a program
961
- can have more than one thread of execution ([[intro.multithread]]).
962
 
963
  The values of the predefined macros (except for `__FILE__` and
964
  `__LINE__`) remain constant throughout the translation unit.
965
 
966
  If any of the pre-defined macro names in this subclause, or the
@@ -975,11 +1459,11 @@ A unary operator expression of the form:
975
 
976
  ``` bnf
977
  '_Pragma' '(' string-literal ')'
978
  ```
979
 
980
- is processed as follows: The string literal is *destringized* by
981
  deleting the `L` prefix, if present, deleting the leading and trailing
982
  double-quotes, replacing each escape sequence `\"` by a double-quote,
983
  and replacing each escape sequence `\\` by a single backslash. The
984
  resulting sequence of characters is processed through translation phase
985
  3 to produce preprocessing tokens that are executed as if they were the
@@ -1013,31 +1497,39 @@ LISTING( ..\listing.dir )
1013
  <!-- Link reference definitions -->
1014
  [basic.stc.dynamic.safety]: basic.md#basic.stc.dynamic.safety
1015
  [cpp]: #cpp
1016
  [cpp.concat]: #cpp.concat
1017
  [cpp.cond]: #cpp.cond
 
1018
  [cpp.error]: #cpp.error
 
1019
  [cpp.include]: #cpp.include
1020
  [cpp.line]: #cpp.line
 
1021
  [cpp.null]: #cpp.null
1022
  [cpp.pragma]: #cpp.pragma
1023
  [cpp.pragma.op]: #cpp.pragma.op
 
1024
  [cpp.predefined]: #cpp.predefined
 
1025
  [cpp.replace]: #cpp.replace
1026
  [cpp.rescan]: #cpp.rescan
1027
  [cpp.scope]: #cpp.scope
1028
  [cpp.stringize]: #cpp.stringize
1029
  [cpp.subst]: #cpp.subst
1030
- [cstdint]: language.md#cstdint
1031
  [expr.const]: expr.md#expr.const
1032
  [expr.new]: expr.md#expr.new
1033
- [intro.multithread]: intro.md#intro.multithread
1034
  [lex.digraph]: lex.md#lex.digraph
 
1035
  [lex.name]: lex.md#lex.name
1036
  [lex.phases]: lex.md#lex.phases
1037
  [lex.token]: lex.md#lex.token
1038
- [support.limits]: language.md#support.limits
 
 
1039
 
1040
  [^1]: Thus, preprocessing directives are commonly called “lines”. These
1041
  “lines” have no other syntactic significance, as all white space is
1042
  equivalent except in certain situations during preprocessing (see
1043
  the `#` character string literal creation operator in 
@@ -1050,22 +1542,22 @@ LISTING( ..\listing.dir )
1050
  [^3]: As indicated by the syntax, a preprocessing token shall not follow
1051
  a `#else` or `#endif` directive before the terminating new-line
1052
  character. However, comments may appear anywhere in a source file,
1053
  including within a preprocessing directive.
1054
 
1055
- [^4]: Note that adjacent string literals are not concatenated into a
1056
- single string literal (see the translation phases in 
1057
- [[lex.phases]]); thus, an expansion that results in two string
1058
- literals is an invalid directive.
1059
 
1060
- [^5]: Since, by macro-replacement time, all character literals and
1061
- string literals are preprocessing tokens, not sequences possibly
1062
  containing identifier-like subsequences (see [[lex.phases]],
1063
  translation phases), they are never scanned for macro names or
1064
  parameters.
1065
 
1066
- [^6]: An alternative token ([[lex.digraph]]) is not an identifier, even
1067
  when its spelling consists entirely of letters and underscores.
1068
  Therefore it is not possible to define a macro whose name is the
1069
  same as that of an alternative token.
1070
 
1071
  [^7]: A *conditionally-supported-directive* is a preprocessing directive
@@ -1073,14 +1565,9 @@ LISTING( ..\listing.dir )
1073
 
1074
  [^8]: Placemarker preprocessing tokens do not appear in the syntax
1075
  because they are temporary entities that exist only within
1076
  translation phase 4.
1077
 
1078
- [^9]: It is intended that future versions of this International Standard
1079
- will replace the value of this macro with a greater value.
1080
- Non-conforming compilers should use a value with at most five
1081
- decimal digits.
1082
-
1083
- [^10]: The presumed source file name can be changed by the `#line`
1084
  directive.
1085
 
1086
- [^11]: The presumed line number can be changed by the `#line` directive.
 
1
  # Preprocessing directives <a id="cpp">[[cpp]]</a>
2
 
3
+ ## Preamble <a id="cpp.pre">[[cpp.pre]]</a>
 
 
 
 
 
 
 
 
 
4
 
5
  ``` bnf
6
  preprocessing-file:
7
  groupₒₚₜ
8
+ module-file
9
+ ```
10
+
11
+ ``` bnf
12
+ module-file:
13
+ pp-global-module-fragmentₒₚₜ pp-module groupₒₚₜ pp-private-module-fragmentₒₚₜ
14
+ ```
15
+
16
+ ``` bnf
17
+ pp-global-module-fragment:
18
+ module ';' new-line groupₒₚₜ
19
+ ```
20
+
21
+ ``` bnf
22
+ pp-private-module-fragment:
23
+ module ':' private ';' new-line groupₒₚₜ
24
  ```
25
 
26
  ``` bnf
27
  group:
28
  group-part
 
35
  if-section
36
  text-line
37
  '#' conditionally-supported-directive
38
  ```
39
 
40
+ ``` bnf
41
+ control-line:
42
+ '# include' pp-tokens new-line
43
+ pp-import
44
+ '# define ' identifier replacement-list new-line
45
+ '# define ' identifier lparen identifier-listₒₚₜ ')' replacement-list new-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
56
  if-section:
57
  if-group elif-groupsₒₚₜ else-groupₒₚₜ endif-line
58
  ```
59
 
60
+ ``` bnf
61
+ if-group:
62
+ '# if ' constant-expression new-line groupₒₚₜ
63
+ '# ifdef ' identifier new-line groupₒₚₜ
64
+ '# ifndef ' identifier new-line groupₒₚₜ
65
+ ```
66
+
67
  ``` bnf
68
  elif-groups:
69
  elif-group
70
  elif-groups elif-group
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ₒₚₜ
81
+ ```
82
+
83
+ ``` bnf
84
+ endif-line:
85
+ '# endif ' new-line
86
+ ```
87
+
88
  ``` bnf
89
  text-line:
90
  pp-tokensₒₚₜ new-line
91
  ```
92
 
 
120
  ``` bnf
121
  new-line:
122
  the new-line character
123
  ```
124
 
125
+ A *preprocessing directive* consists of a sequence of preprocessing
126
+ tokens that satisfies the following constraints: At the start of
127
+ translation phase 4, the first token in the sequence, referred to as a
128
+ *directive-introducing token*, begins with the first character in the
129
+ source file (optionally after white space containing no new-line
130
+ characters) or follows white space containing at least one new-line
131
+ character, and is
132
 
133
+ - a `#` preprocessing token, or
134
+ - an `import` preprocessing token immediately followed on the same
135
+ logical line by a *header-name*, `<`, *identifier*, *string-literal*,
136
+ or `:` preprocessing token, or
137
+ - a `module` preprocessing token immediately followed on the same
138
+ logical line by an *identifier*, `:`, or `;` preprocessing token, or
139
+ - an `export` preprocessing token immediately followed on the same
140
+ logical line by one of the two preceding forms.
141
+
142
+ The last token in the sequence is the first token within the sequence
143
+ that is immediately followed by whitespace containing a new-line
144
+ character. [^1]
145
+
146
+ [*Note 1*: A new-line character ends the preprocessing directive even
147
+ if it occurs within what would otherwise be an invocation of a
148
+ function-like macro. — *end note*]
149
+
150
+ [*Example 1*:
151
+
152
+ ``` cpp
153
+ # // preprocessing directive
154
+ module ; // preprocessing directive
155
+ export module leftpad; // preprocessing directive
156
+ import <string>; // preprocessing directive
157
+ export import "squee"; // preprocessing directive
158
+ import rightpad; // preprocessing directive
159
+ import :part; // preprocessing directive
160
+
161
+ module // not a preprocessing directive
162
+ ; // not a preprocessing directive
163
+
164
+ export // not a preprocessing directive
165
+ import // not a preprocessing directive
166
+ foo; // not a preprocessing directive
167
+
168
+ export // not a preprocessing directive
169
+ import foo; // preprocessing directive (ill-formed at phase 7)
170
+
171
+ import :: // not a preprocessing directive
172
+ import -> // not a preprocessing directive
173
+ ```
174
+
175
+ — *end example*]
176
+
177
+ A sequence of preprocessing tokens is only a *text-line* if it does not
178
+ begin with a directive-introducing token. A sequence of preprocessing
179
+ tokens is only a *conditionally-supported-directive* if it does not
180
+ begin with any of the directive names appearing after a `#` in the
181
+ syntax. A *conditionally-supported-directive* is conditionally-supported
182
+ with *implementation-defined* semantics.
183
+
184
+ At the start of phase 4 of translation, the *group* of a
185
+ *pp-global-module-fragment* shall contain neither a *text-line* nor a
186
+ *pp-import*.
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 white-space characters that shall appear between preprocessing
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 white-space characters in
197
  translation phase 3).
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
203
+ the resulting translation unit.
204
 
205
  The preprocessing tokens within a preprocessing directive are not
206
  subject to macro expansion unless otherwise stated.
207
 
208
+ [*Example 2*:
209
 
210
  In:
211
 
212
  ``` cpp
213
  #define EMPTY
 
238
  h-pp-tokens:
239
  h-preprocessing-token
240
  h-pp-tokens h-preprocessing-token
241
  ```
242
 
243
+ ``` bnf
244
+ header-name-tokens:
245
+ string-literal
246
+ '<' h-pp-tokens '>'
247
+ ```
248
+
249
  ``` bnf
250
  has-include-expression:
251
+ '__has_include' '(' header-name ')'
252
+ '__has_include' '(' header-name-tokens ')'
253
+ ```
254
+
255
+ ``` bnf
256
+ 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] and it may
263
  contain zero or more *defined-macro-expression*s and/or
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
269
+ has one or more active macro definitions [[cpp.import]], for example
270
+ because it has been the subject of a `#define` preprocessing directive
271
+ without an intervening `#undef` directive with the same subject
272
+ identifier), `0` if it is not.
273
 
274
+ The second form of *has-include-expression* is considered only if the
275
+ first form does not match, in which case the preprocessing tokens are
276
+ processed just as in normal text.
277
 
278
  The header or source file identified by the parenthesized preprocessing
279
  token sequence in each contained *has-include-expression* is searched
280
  for as if that preprocessing token sequence were the *pp-tokens* in a
281
  `#include` directive, except that no further macro expansion is
282
  performed. If such a directive would not satisfy the syntactic
283
  requirements of a `#include` directive, the program is ill-formed. The
284
  *has-include-expression* evaluates to `1` if the search for the source
285
  file succeeds, and to `0` if the search fails.
286
 
287
+ Each *has-attribute-expression* is replaced by a non-zero *pp-number*
288
+ matching the form of an *integer-literal* if the implementation supports
289
+ an attribute with the name specified by interpreting the *pp-tokens*,
290
+ after macro expansion, as an *attribute-token*, and by `0` otherwise.
291
+ The program is ill-formed if the *pp-tokens* do not match the form of an
292
+ *attribute-token*.
293
+
294
+ For an attribute specified in this document, the value of the
295
+ *has-attribute-expression* is given by [[cpp.cond.ha]]. For other
296
+ attributes recognized by the implementation, the value is
297
+ *implementation-defined*.
298
+
299
+ [*Note 1*: It is expected that the availability of an attribute can be
300
+ 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` |
311
+ | `no_unique_address` | `201803L` |
312
+ | `nodiscard` | `201907L` |
313
+ | `noreturn` | `200809L` |
314
+ | `unlikely` | `201803L` |
315
+
316
+
317
  The `#ifdef` and `#ifndef` directives, and the `defined` conditional
318
+ inclusion operator, shall treat `__has_include` and
319
+ `__has_cpp_attribute` as if they were the names of defined macros. The
320
+ identifiers `__has_include` and `__has_cpp_attribute` shall not appear
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]].
327
 
328
  Preprocessing directives of the forms
329
 
330
+ ``` bnf
331
+ '# if ' constant-expression new-line groupₒₚₜ
332
+ '# elif ' constant-expression new-line groupₒₚₜ
333
+ ```
334
+
335
  check whether the controlling constant expression evaluates to nonzero.
336
 
337
  Prior to evaluation, macro invocations in the list of preprocessing
338
  tokens that will become the controlling constant expression are replaced
339
  (except for those macro names modified by the `defined` unary operator),
 
341
  of this replacement process or use of the `defined` unary operator does
342
  not match one of the two specified forms prior to macro replacement, the
343
  behavior is undefined.
344
 
345
  After all replacements due to macro expansion and evaluations of
346
+ *defined-macro-expression*s, *has-include-expression*s, and
347
+ *has-attribute-expression*s have been performed, all remaining
348
+ identifiers and keywords, except for `true` and `false`, are replaced
349
+ with the *pp-number* `0`, and then each preprocessing token is converted
350
+ into a token.
351
 
352
+ [*Note 2*: An alternative token [[lex.digraph]] is not an identifier,
353
+ even when its spelling consists entirely of letters and underscores.
354
+ Therefore it is not subject to this replacement. — *end note*]
 
355
 
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, which may involve
371
  converting escape sequences into execution character set members.
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
  Thus, the constant expression in the following `#if` directive and `if`
380
+ statement [[stmt.if]] is not guaranteed to evaluate to the same value in
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
  and `#if` `!defined` *identifier* respectively.
404
 
405
  Each directive’s condition is checked in order. If it evaluates to false
 
421
  it is available:
422
 
423
  ``` cpp
424
  #if __has_include(<optional>)
425
  # include <optional>
426
+ # if __cpp_lib_optional >= 201603
427
  # define have_optional 1
428
+ # endif
429
  #elif __has_include(<experimental/optional>)
430
  # include <experimental/optional>
431
+ # if __cpp_lib_experimental_optional >= 201411
432
  # define have_optional 1
433
  # define experimental_optional 1
434
+ # endif
435
+ #endif
436
+ #ifndef have_optional
437
  # define have_optional 0
438
  #endif
439
  ```
440
 
441
  — *end example*]
442
 
443
+ [*Example 2*:
444
+
445
+ This demonstrates a way to use the attribute `[[acme::deprecated]]` only
446
+ if it is available.
447
+
448
+ ``` cpp
449
+ #if __has_cpp_attribute(acme::deprecated)
450
+ # define ATTR_DEPRECATED(msg) [[acme::deprecated(msg)]]
451
+ #else
452
+ # define ATTR_DEPRECATED(msg) [[deprecated(msg)]]
453
+ #endif
454
+ ATTR_DEPRECATED("This function is deprecated") void anvil();
455
+ ```
456
+
457
+ — *end example*]
458
+
459
  ## Source file inclusion <a id="cpp.include">[[cpp.include]]</a>
460
 
461
  A `#include` directive shall identify a header or source file that can
462
  be processed by the implementation.
463
 
 
507
  sequence of preprocessing tokens between a `<` and a `>` preprocessing
508
  token pair or a pair of `"` characters is combined into a single header
509
  name preprocessing token is *implementation-defined*.
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
515
+ case.
516
 
517
  A `#include` preprocessing directive may appear in a source file that
518
  has been read because of a `#include` directive in another file, up to
519
  an *implementation-defined* nesting limit.
520
 
521
+ If the header identified by the *header-name* denotes an importable
522
+ header [[module.import]], it is *implementation-defined* whether the
523
+ `#include` preprocessing directive is instead replaced by an `import`
524
+ directive [[cpp.import]] of the form
525
+
526
+ ``` bnf
527
+ 'import' header-name ';' new-line
528
+ ```
529
+
530
  [*Note 1*:
531
 
532
  Although an implementation may provide a mechanism for making arbitrary
533
  source files available to the `< >` search, in general programmers
534
  should use the `< >` form for headers provided with the implementation,
 
559
  #include INCFILE
560
  ```
561
 
562
  — *end example*]
563
 
564
+ ## Module directive <a id="cpp.module">[[cpp.module]]</a>
565
+
566
+ ``` bnf
567
+ pp-module:
568
+ exportₒₚₜ module pp-tokensₒₚₜ ';' new-line
569
+ ```
570
+
571
+ A *pp-module* shall not appear in a context where `module` or (if it is
572
+ the first token of the *pp-module*) `export` is an identifier defined as
573
+ an object-like macro.
574
+
575
+ Any preprocessing tokens after the `module` preprocessing token in the
576
+ `module` directive are processed just as in normal text.
577
+
578
+ [*Note 1*: Each identifier currently defined as a macro name is
579
+ replaced by its replacement list of preprocessing tokens. — *end note*]
580
+
581
+ The `module` and `export` (if it exists) preprocessing tokens are
582
+ replaced by the *module-keyword* and *export-keyword* preprocessing
583
+ tokens respectively.
584
+
585
+ [*Note 2*: This makes the line no longer a directive so it is not
586
+ removed at the end of phase 4. — *end note*]
587
+
588
+ ## Header unit importation <a id="cpp.import">[[cpp.import]]</a>
589
+
590
+ ``` bnf
591
+ pp-import:
592
+ exportₒₚₜ import header-name pp-tokensₒₚₜ ';' new-line
593
+ exportₒₚₜ import header-name-tokens pp-tokensₒₚₜ ';' new-line
594
+ exportₒₚₜ import pp-tokens ';' new-line
595
+ ```
596
+
597
+ A *pp-import* shall not appear in a context where `import` or (if it is
598
+ 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). An `import` directive
605
+ matching the first two forms of a *pp-import* instructs the preprocessor
606
+ to import macros from the header unit [[module.import]] denoted by the
607
+ *header-name*. The *point of macro import* for the first two forms of
608
+ *pp-import* is immediately after the *new-line* terminating the
609
+ *pp-import*. The last form of *pp-import* is only considered if the
610
+ first two forms did not match.
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 1*: This makes the line no longer a directive so it is not
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 2*: This ensures that imports are treated consistently by the
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 3*: A predefined macro name [[cpp.predefined]] is not introduced
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
+ Importing macros from a header unit makes macro definitions from a
641
+ translation unit visible in other translation units. Each macro
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 is the point at which its `#define` directive occurs (in the
647
+ translation unit containing the `#define` directive), or, if the macro
648
+ name is not lexically identical to a keyword [[lex.key]] or to the
649
+ *identifier*s `module` or `import`, the first point of macro import of
650
+ a translation unit containing a point of definition for the macro
651
+ definition, if any (in any other translation unit).
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 translation unit containing a point of undefinition for
656
+ the macro definition, whichever (if any) occurs first.
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 4*: The relative order of *pp-import*s has no bearing on whether
668
+ a particular macro definition is active. — *end note*]
669
+
670
+ [*Example 1*:
671
+
672
+ Importable header \`"a.h"\`
673
+
674
+ ``` cpp
675
+ #define X 123 // #1
676
+ #define Y 45 // #2
677
+ #define Z a // #3
678
+ #undef X // point of undefinition of #1 in "a.h"
679
+ ```
680
+
681
+ Importable header \`"b.h"\`
682
+
683
+ ``` cpp
684
+ import "a.h"; // point of definition of #1, #2, and #3, point of undefinition of #1 in "b.h"
685
+ #define X 456 // OK, #1 is not active
686
+ #define Y 6 // error: #2 is active
687
+ ```
688
+
689
+ Importable header \`"c.h"\`
690
+
691
+ ``` cpp
692
+ #define Y 45 // #4
693
+ #define Z c // #5
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 white-space
711
  separation, where all white-space separations are considered identical.
 
718
  below) may be redefined by another `#define` preprocessing directive
719
  provided that the second definition is a function-like macro definition
720
  that has the same number and spelling of parameters, and the two
721
  replacement lists are identical, otherwise the program is ill-formed.
722
 
723
+ [*Example 1*:
724
+
725
+ The following sequence is valid:
726
+
727
+ ``` cpp
728
+ #define OBJ_LIKE (1-1)
729
+ #define OBJ_LIKE /* white space */ (1-1) /* other */
730
+ #define FUNC_LIKE(a) ( a )
731
+ #define FUNC_LIKE( a )( /* note the white space */ \
732
+ a /* other stuff on this line
733
+ */ )
734
+ ```
735
+
736
+ But the following redefinitions are invalid:
737
+
738
+ ``` cpp
739
+ #define OBJ_LIKE (0) // different token sequence
740
+ #define OBJ_LIKE (1 - 1) // different white space
741
+ #define FUNC_LIKE(b) ( a ) // different parameter usage
742
+ #define FUNC_LIKE(b) ( b ) // different parameter spelling
743
+ ```
744
+
745
+ — *end example*]
746
+
747
  There shall be white-space between the identifier and the replacement
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
753
  shall equal the number of parameters in the macro definition. Otherwise,
754
+ there shall be at least as many arguments in the invocation as there are
755
  parameters in the macro definition (excluding the `...`). There shall
756
  exist a `)` preprocessing token that terminates the invocation.
757
 
758
+ The identifiers `__VA_ARGS__` and `__VA_OPT__` shall occur only in the
759
+ *replacement-list* of a function-like macro that uses the ellipsis
760
+ 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
 
782
  the macro name[^5] to be replaced by the replacement list of
783
  preprocessing tokens that constitute the remainder of the directive.[^6]
784
  The replacement list is then rescanned for more macro names as specified
785
  below.
786
 
787
+ [*Example 2*:
788
+
789
+ The simplest use of this facility is to define a “manifest constant”, as
790
+ in
791
+
792
+ ``` cpp
793
+ #define TABSIZE 100
794
+ int table[TABSIZE];
795
+ ```
796
+
797
+ — *end example*]
798
+
799
  A preprocessing directive of the form
800
 
801
  ``` bnf
802
  '# define' identifier lparen identifier-listₒₚₜ ')' replacement-list new-line
803
  '# define' identifier lparen '...' ')' replacement-list new-line
 
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] the behavior is undefined.
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
833
+ other of its arguments a second time (including side effects) and
834
+ generating more code than a function if invoked several times. It also
835
+ cannot have its address taken, as it has none.
836
+
837
+ ``` cpp
838
+ #define max(a, b) ((a) > (b) ? (a) : (b))
839
+ ```
840
+
841
+ The parentheses ensure that the arguments and the resulting expression
842
+ are bound properly.
843
+
844
+ — *end example*]
845
+
846
  If there is a `...` immediately preceding the `)` in the function-like
847
+ macro definition, then the trailing arguments (if any), including any
848
+ separating comma preprocessing tokens, are merged to form a single item:
849
+ the *variable arguments*. The number of arguments so combined is such
850
+ that, following merger, the number of arguments is either equal to or
851
+ one more than the number of parameters in the macro definition
852
+ (excluding the `...`).
853
 
854
  ### Argument substitution <a id="cpp.subst">[[cpp.subst]]</a>
855
 
856
+ ``` bnf
857
+ va-opt-replacement:
858
+ '__VA_OPT__ (' pp-tokensₒₚₜ ')'
859
+ ```
860
+
861
  After the arguments for the invocation of a function-like macro have
862
+ been identified, argument substitution takes place. For each parameter
863
+ in the replacement list that is neither preceded by a `#` or `##`
864
+ preprocessing token nor followed by a `##` preprocessing token, the
865
+ preprocessing tokens naming the parameter are replaced by a token
866
+ sequence determined as follows:
867
+
868
+ - If the parameter is of the form *va-opt-replacement*, the replacement
869
+ preprocessing tokens are the preprocessing token sequence for the
870
+ corresponding argument, as specified below.
871
+ - Otherwise, the replacement preprocessing tokens are the preprocessing
872
+ tokens of corresponding argument after all macros contained therein
873
+ have been expanded. The argument’s preprocessing tokens are completely
874
+ macro replaced before being substituted as if they formed the rest of
875
+ the preprocessing file with no other preprocessing tokens being
876
+ available.
877
+
878
+ [*Example 1*:
879
+
880
+ ``` cpp
881
+ #define LPAREN() (
882
+ #define G(Q) 42
883
+ #define F(R, X, ...) __VA_OPT__(G R X) )
884
+ int x = F(LPAREN(), 0, <:-); // replaced by int x = 42;
885
+ ```
886
+
887
+ — *end example*]
888
 
889
  An identifier `__VA_ARGS__` that occurs in the replacement list shall be
890
  treated as if it were a parameter, and the variable arguments shall form
891
  the preprocessing tokens used to replace it.
892
 
893
+ [*Example 2*:
894
+
895
+ ``` cpp
896
+ #define debug(...) fprintf(stderr, __VA_ARGS__)
897
+ #define showlist(...) puts(#__VA_ARGS__)
898
+ #define report(test, ...) ((test) ? puts(#test) : printf(__VA_ARGS__))
899
+ debug("Flag");
900
+ debug("X = %d\n", x);
901
+ showlist(The first, second, and third items.);
902
+ report(x>y, "x is %d but y is %d", x, y);
903
+ ```
904
+
905
+ results in
906
+
907
+ ``` cpp
908
+ fprintf(stderr, "Flag");
909
+ fprintf(stderr, "X = %d\n", x);
910
+ puts("The first, second, and third items.");
911
+ ((x>y) ? puts("x>y") : printf("x is %d but y is %d", x, y));
912
+ ```
913
+
914
+ — *end example*]
915
+
916
+ The identifier `__VA_OPT__` shall always occur as part of the
917
+ preprocessing token sequence *va-opt-replacement*; its closing `)` is
918
+ determined by skipping intervening pairs of matching left and right
919
+ parentheses in its *pp-tokens*. The *pp-tokens* of a
920
+ *va-opt-replacement* shall not contain `__VA_OPT__`. If the *pp-tokens*
921
+ 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 ([[cpp.concat]], [[cpp.rescan]]). Otherwise, the
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
+
933
+ [*Note 1*: The placemarker tokens are removed before stringization
934
+ [[cpp.stringize]], and can be removed by rescanning and further
935
+ replacement [[cpp.rescan]]. — *end note*]
936
+
937
+ [*Example 3*:
938
+
939
+ ``` cpp
940
+ #define F(...) f(0 __VA_OPT__(,) __VA_ARGS__)
941
+ #define G(X, ...) f(0, X __VA_OPT__(,) __VA_ARGS__)
942
+ #define SDEF(sname, ...) S sname __VA_OPT__(= { __VA_ARGS__ })
943
+ #define EMP
944
+
945
+ F(a, b, c) // replaced by f(0, a, b, c)
946
+ F() // replaced by f(0)
947
+ F(EMP) // replaced by f(0)
948
+
949
+ G(a, b, c) // replaced by f(0, a, b, c)
950
+ G(a, ) // replaced by f(0, a)
951
+ G(a) // replaced by f(0, a)
952
+
953
+ SDEF(foo); // replaced by S foo;
954
+ SDEF(bar, 1, 2); // replaced by S bar = { 1, 2 }
955
+
956
+ #define H1(X, ...) X __VA_OPT__(##) __VA_ARGS__ // error: ## may not appear at
957
+ // the beginning of a replacement list[cpp.concat]
958
+
959
+ #define H2(X, Y, ...) __VA_OPT__(X ## Y,) __VA_ARGS__
960
+ H2(a, b, c, d) // replaced by ab, c, d
961
+
962
+ #define H3(X, ...) #__VA_OPT__(X##X X##X)
963
+ H3(, 0) // replaced by ""
964
+
965
+ #define H4(X, ...) __VA_OPT__(a X ## X) ## b
966
+ H4(, 1) // replaced by a b
967
+
968
+ #define H5A(...) __VA_OPT__()/**/__VA_OPT__()
969
+ #define H5B(X) a ## X ## b
970
+ #define H5C(X) H5B(X)
971
+ H5C(H5A()) // replaced by ab
972
+ ```
973
+
974
+ — *end example*]
975
+
976
  ### The `#` operator <a id="cpp.stringize">[[cpp.stringize]]</a>
977
 
978
  Each `#` preprocessing token in the replacement list for a function-like
979
  macro shall be followed by a parameter as the next preprocessing token
980
  in the replacement list.
981
 
982
  A *character string literal* is a *string-literal* with no prefix. If,
983
  in the replacement list, a parameter is immediately preceded by a `#`
984
  preprocessing token, both are replaced by a single character string
985
  literal preprocessing token that contains the spelling of the
986
+ preprocessing token sequence for the corresponding argument (excluding
987
+ placemarker tokens). Let the *stringizing argument* be the preprocessing
988
+ token sequence for the corresponding argument with placemarker tokens
989
+ removed. Each occurrence of white space between the stringizing
990
+ argument’s preprocessing tokens becomes a single space character in the
991
+ character string literal. White space before the first preprocessing
992
+ token and after the last preprocessing token comprising the stringizing
993
+ argument is deleted. Otherwise, the original spelling of each
994
+ preprocessing token in the stringizing argument is retained in the
995
+ character string literal, except for special handling for producing the
996
+ spelling of *string-literal*s and *character-literal*s: a `\` character
997
+ is inserted before each `"` and `\` character of a *character-literal*
998
+ or *string-literal* (including the delimiting `"` characters). If the
999
+ replacement that results is not a valid character string literal, the
1000
+ behavior is undefined. The character string literal corresponding to an
1001
+ empty stringizing argument is `""`. The order of evaluation of `#` and
1002
+ `##` operators is unspecified.
1003
 
1004
  ### The `##` operator <a id="cpp.concat">[[cpp.concat]]</a>
1005
 
1006
  A `##` preprocessing token shall not occur at the beginning or at the
1007
  end of a replacement list for either form of macro definition.
 
1026
  resulting token is available for further macro replacement. The order of
1027
  evaluation of `##` operators is unspecified.
1028
 
1029
  [*Example 1*:
1030
 
1031
+ The sequence
1032
+
1033
+ ``` cpp
1034
+ #define str(s) # s
1035
+ #define xstr(s) str(s)
1036
+ #define debug(s, t) printf("x" # s "= %d, x" # t "= %s", \
1037
+ x ## s, x ## t)
1038
+ #define INCFILE(n) vers ## n
1039
+ #define glue(a, b) a ## b
1040
+ #define xglue(a, b) glue(a, b)
1041
+ #define HIGHLOW "hello"
1042
+ #define LOW LOW ", world"
1043
+
1044
+ debug(1, 2);
1045
+ fputs(str(strncmp("abc\0d", "abc", '\4') // this goes away
1046
+ == 0) str(: \@n), s);
1047
+ #include xstr(INCFILE(2).h)
1048
+ glue(HIGH, LOW);
1049
+ xglue(HIGH, LOW)
1050
+ ```
1051
+
1052
+ results in
1053
+
1054
+ ``` cpp
1055
+ printf("x" "1" "= %d, x" "2" "= %s", x1, x2);
1056
+ fputs("strncmp(\"abc\\0d\", \"abc\", '\\4') == 0" ": \@n", s);
1057
+ #include "vers2.h" (after macro replacement, before file access)
1058
+ "hello";
1059
+ "hello" ", world"
1060
+ ```
1061
+
1062
+ or, after concatenation of the character string literals,
1063
+
1064
+ ``` cpp
1065
+ printf("x1= %d, x2= %s", x1, x2);
1066
+ fputs("strncmp(\"abc\\0d\", \"abc\", '\\4') == 0: \@n", s);
1067
+ #include "vers2.h" (after macro replacement, before file access)
1068
+ "hello";
1069
+ "hello, world"
1070
+ ```
1071
+
1072
+ Space around the `#` and `##` tokens in the macro definition is
1073
+ optional.
1074
+
1075
+ — *end example*]
1076
+
1077
+ [*Example 2*:
1078
+
1079
  In the following fragment:
1080
 
1081
  ``` cpp
1082
  #define hash_hash # ## #
1083
  #define mkstr(a) # a
 
1100
  of two adjacent sharp signs, but this new token is not the `##`
1101
  operator.
1102
 
1103
  — *end example*]
1104
 
1105
+ [*Example 3*:
1106
+
1107
+ To illustrate the rules for placemarker preprocessing tokens, the
1108
+ sequence
1109
+
1110
+ ``` cpp
1111
+ #define t(x,y,z) x ## y ## z
1112
+ int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,),
1113
+ t(10,,), t(,11,), t(,,12), t(,,) };
1114
+ ```
1115
+
1116
+ results in
1117
+
1118
+ ``` cpp
1119
+ int j[] = { 123, 45, 67, 89,
1120
+ 10, 11, 12, };
1121
+ ```
1122
+
1123
+ — *end example*]
1124
+
1125
  ### Rescanning and further replacement <a id="cpp.rescan">[[cpp.rescan]]</a>
1126
 
1127
  After all parameters in the replacement list have been substituted and
1128
  `#` and `##` processing has taken place, all placemarker preprocessing
1129
  tokens are removed. Then the resulting preprocessing token sequence is
1130
  rescanned, along with all subsequent preprocessing tokens of the source
1131
  file, for more macro names to replace.
1132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1133
  [*Example 1*:
1134
 
1135
+ The sequence
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1136
 
1137
  ``` cpp
1138
  #define x 3
1139
  #define f(a) f(x * (a))
1140
  #undef x
 
1166
  char c[2][6] = { "hello", "" };
1167
  ```
1168
 
1169
  — *end example*]
1170
 
1171
+ If the name of the macro being replaced is found during this scan of the
1172
+ replacement list (not including the rest of the source file’s
1173
+ preprocessing tokens), it is not replaced. Furthermore, if any nested
1174
+ replacements encounter the name of the macro being replaced, it is not
1175
+ replaced. These nonreplaced macro name preprocessing tokens are no
1176
+ longer available for further replacement even if they are later
1177
+ (re)examined in contexts in which that macro name preprocessing token
1178
+ would otherwise have been replaced.
1179
 
1180
+ The resulting completely macro-replaced preprocessing token sequence is
1181
+ not processed as a preprocessing directive even if it resembles one, but
1182
+ all pragma unary operator expressions within it are then processed as
1183
+ specified in  [[cpp.pragma.op]] below.
1184
 
1185
+ ### Scope of macro definitions <a id="cpp.scope">[[cpp.scope]]</a>
 
 
 
 
 
 
 
 
 
1186
 
1187
+ A macro definition lasts (independent of block structure) until a
1188
+ corresponding `#undef` directive is encountered or (if none is
1189
+ encountered) until the end of the translation unit. Macro definitions
1190
+ have no significance after translation phase 4.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1191
 
1192
+ A preprocessing directive of the form
1193
 
1194
+ ``` bnf
1195
+ '# undef' identifier new-line
 
 
 
1196
  ```
1197
 
1198
+ causes the specified identifier no longer to be defined as a macro name.
1199
+ It is ignored if the specified identifier is not currently defined as a
1200
+ macro name.
1201
 
1202
  ## Line control <a id="cpp.line">[[cpp.line]]</a>
1203
 
1204
+ The *string-literal* of a `#line` directive, if present, shall be a
1205
  character string literal.
1206
 
1207
  The *line number* of the current source line is one greater than the
1208
+ number of new-line characters read or introduced in translation phase 1
1209
+ [[lex.phases]] while processing the source file to the current token.
 
1210
 
1211
  A preprocessing directive of the form
1212
 
1213
  ``` bnf
1214
  '# line' digit-sequence new-line
 
1283
 
1284
  The following macro names shall be defined by the implementation:
1285
 
1286
  - **`__cplusplus`**
1287
 
1288
+ The integer literal `202302L`.
1289
+
1290
+ [*Note 1*: It is intended that future versions of this International
1291
+ Standard will replace the value of this macro with a greater
1292
+ value. — *end note*]
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
 
1301
  shall be supplied.
1302
 
1303
  - **`__FILE__`**
1304
 
1305
  The presumed name of the current source file (a character string
1306
+ literal). [^9]
1307
 
1308
  - **`__LINE__`**
1309
 
1310
  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 not.
 
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 2*: Larger alignments will be passed to
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` | `201811L` |
1356
+ | `__cpp_concepts` | `201907L` |
1357
+ | `__cpp_conditional_explicit` | `201806L` |
1358
+ | `__cpp_constexpr` | `201907L` |
1359
+ | `__cpp_constexpr_dynamic_alloc` | `201907L` |
1360
+ | `__cpp_constexpr_in_decltype` | `201711L` |
1361
+ | `__cpp_consteval` | `201811L` |
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` | `201603L` |
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` |
1400
+ | `__cpp_user_defined_literals` | `200809L` |
1401
+ | `__cpp_using_enum` | `201907L` |
1402
+ | `__cpp_variable_templates` | `201304L` |
1403
+ | `__cpp_variadic_templates` | `200704L` |
1404
+ | `__cpp_variadic_using` | `201611L` |
1405
+
1406
+
1407
  The following macro names are conditionally defined by the
1408
  implementation:
1409
 
1410
  - **`__STDC__`**
1411
 
 
1427
  - **`__STDC_ISO_10646__`**
1428
 
1429
  An integer literal of the form `yyyymmL` (for example, `199712L`). If
1430
  this symbol is defined, then every character in the Unicode required
1431
  set, when stored in an object of type `wchar_t`, has the same value as
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]].
1446
 
1447
  The values of the predefined macros (except for `__FILE__` and
1448
  `__LINE__`) remain constant throughout the translation unit.
1449
 
1450
  If any of the pre-defined macro names in this subclause, or the
 
1459
 
1460
  ``` bnf
1461
  '_Pragma' '(' string-literal ')'
1462
  ```
1463
 
1464
+ is processed as follows: The *string-literal* is *destringized* by
1465
  deleting the `L` prefix, if present, deleting the leading and trailing
1466
  double-quotes, replacing each escape sequence `\"` by a double-quote,
1467
  and replacing each escape sequence `\\` by a single backslash. The
1468
  resulting sequence of characters is processed through translation phase
1469
  3 to produce preprocessing tokens that are executed as if they were the
 
1497
  <!-- Link reference definitions -->
1498
  [basic.stc.dynamic.safety]: basic.md#basic.stc.dynamic.safety
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
1504
+ [cpp.import]: #cpp.import
1505
  [cpp.include]: #cpp.include
1506
  [cpp.line]: #cpp.line
1507
+ [cpp.module]: #cpp.module
1508
  [cpp.null]: #cpp.null
1509
  [cpp.pragma]: #cpp.pragma
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 white space is
1534
  equivalent except in certain situations during preprocessing (see
1535
  the `#` character string literal creation operator in 
 
1542
  [^3]: As indicated by the syntax, a preprocessing token shall not follow
1543
  a `#else` or `#endif` directive before the terminating new-line
1544
  character. However, comments may appear anywhere in a source file,
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
1550
+ *string-literal*s is an invalid directive.
1551
 
1552
+ [^5]: Since, by macro-replacement time, all *character-literal*s and
1553
+ *string-literal*s are preprocessing tokens, not sequences possibly
1554
  containing identifier-like subsequences (see [[lex.phases]],
1555
  translation phases), they are never scanned for macro names or
1556
  parameters.
1557
 
1558
+ [^6]: An alternative token [[lex.digraph]] is not an identifier, even
1559
  when its spelling consists entirely of letters and underscores.
1560
  Therefore it is not possible to define a macro whose name is the
1561
  same as that of an alternative token.
1562
 
1563
  [^7]: A *conditionally-supported-directive* is a preprocessing directive
 
1565
 
1566
  [^8]: Placemarker preprocessing tokens do not appear in the syntax
1567
  because they are temporary entities that exist only within
1568
  translation phase 4.
1569
 
1570
+ [^9]: The presumed source file name can be changed by the `#line`
 
 
 
 
 
1571
  directive.
1572
 
1573
+ [^10]: The presumed line number can be changed by the `#line` directive.