From Jason Turner

[cpp.replace]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmplwrjse7o/{from.md → to.md} +39 -31
tmp/tmplwrjse7o/{from.md → to.md} RENAMED
@@ -62,10 +62,16 @@ The identifier immediately following the `define` is called the *macro
62
  name*. There is one name space for macro names. Any whitespace
63
  characters preceding or following the replacement list of preprocessing
64
  tokens are not considered part of the replacement list for either form
65
  of macro.
66
 
 
 
 
 
 
 
67
  If a `#` preprocessing token, followed by an identifier, occurs
68
  lexically at the point at which a preprocessing directive can begin, the
69
  identifier is not subject to macro replacement.
70
 
71
  A preprocessing directive of the form
@@ -73,17 +79,17 @@ A preprocessing directive of the form
73
  ``` bnf
74
  '# define' identifier replacement-list new-line
75
  ```
76
 
77
  defines an *object-like macro* that causes each subsequent instance of
78
- the macro name[^5]
79
 
80
  to be replaced by the replacement list of preprocessing tokens that
81
- constitute the remainder of the directive.[^6]
82
 
83
  The replacement list is then rescanned for more macro names as specified
84
- below.
85
 
86
  [*Example 2*:
87
 
88
  The simplest use of this facility is to define a “manifest constant”, as
89
  in
@@ -119,13 +125,13 @@ The sequence of preprocessing tokens bounded by the outside-most
119
  matching parentheses forms the list of arguments for the function-like
120
  macro. The individual arguments within the list are separated by comma
121
  preprocessing tokens, but comma preprocessing tokens between matching
122
  inner parentheses do not separate arguments. If there are sequences of
123
  preprocessing tokens within the list of arguments that would otherwise
124
- act as preprocessing directives,[^7]
125
 
126
- the behavior is undefined.
127
 
128
  [*Example 3*:
129
 
130
  The following defines a function-like macro whose value is the maximum
131
  of its arguments. It has the disadvantages of evaluating one or the
@@ -159,22 +165,22 @@ va-opt-replacement:
159
 
160
  After the arguments for the invocation of a function-like macro have
161
  been identified, argument substitution takes place. For each parameter
162
  in the replacement list that is neither preceded by a `#` or `##`
163
  preprocessing token nor followed by a `##` preprocessing token, the
164
- preprocessing tokens naming the parameter are replaced by a token
165
- sequence determined as follows:
166
 
167
  - If the parameter is of the form *va-opt-replacement*, the replacement
168
  preprocessing tokens are the preprocessing token sequence for the
169
  corresponding argument, as specified below.
170
  - Otherwise, the replacement preprocessing tokens are the preprocessing
171
  tokens of corresponding argument after all macros contained therein
172
  have been expanded. The argument’s preprocessing tokens are completely
173
  macro replaced before being substituted as if they formed the rest of
174
- the preprocessing file with no other preprocessing tokens being
175
- available.
176
 
177
  [*Example 1*:
178
 
179
  ``` cpp
180
  #define LPAREN() (
@@ -290,17 +296,21 @@ argument’s preprocessing tokens becomes a single space character in the
290
  character string literal. Whitespace before the first preprocessing
291
  token and after the last preprocessing token comprising the stringizing
292
  argument is deleted. Otherwise, the original spelling of each
293
  preprocessing token in the stringizing argument is retained in the
294
  character string literal, except for special handling for producing the
295
- spelling of *string-literal*s and *character-literal*s: a `\` character
296
- is inserted before each `"` and `\` character of a *character-literal*
297
- or *string-literal* (including the delimiting `"` characters). If the
298
- replacement that results is not a valid character string literal, the
299
- behavior is undefined. The character string literal corresponding to an
300
- empty stringizing argument is `""`. The order of evaluation of `#` and
301
- `##` operators is unspecified.
 
 
 
 
302
 
303
  ### The `##` operator <a id="cpp.concat">[[cpp.concat]]</a>
304
 
305
  A `##` preprocessing token shall not occur at the beginning or at the
306
  end of a replacement list for either form of macro definition.
@@ -308,31 +318,29 @@ end of a replacement list for either form of macro definition.
308
  If, in the replacement list of a function-like macro, a parameter is
309
  immediately preceded or followed by a `##` preprocessing token, the
310
  parameter is replaced by the corresponding argument’s preprocessing
311
  token sequence; however, if an argument consists of no preprocessing
312
  tokens, the parameter is replaced by a placemarker preprocessing token
313
- instead.[^8]
314
 
315
  For both object-like and function-like macro invocations, before the
316
  replacement list is reexamined for more macro names to replace, each
317
  instance of a `##` preprocessing token in the replacement list (not from
318
  an argument) is deleted and the preceding preprocessing token is
319
  concatenated with the following preprocessing token. Placemarker
320
  preprocessing tokens are handled specially: concatenation of two
321
  placemarkers results in a single placemarker preprocessing token, and
322
  concatenation of a placemarker with a non-placemarker preprocessing
323
- token results in the non-placemarker preprocessing token. If the result
324
- begins with a sequence matching the syntax of
325
- *universal-character-name*, the behavior is undefined.
326
 
327
- [*Note 1*: This determination does not consider the replacement of
328
- *universal-character-name*s in translation phase 3
329
- [[lex.phases]]. — *end note*]
330
 
331
- If the result is not a valid preprocessing token, the behavior is
332
- undefined. The resulting token is available for further macro
333
- replacement. The order of evaluation of `##` operators is unspecified.
 
334
 
335
  [*Example 1*:
336
 
337
  The sequence
338
 
@@ -373,12 +381,12 @@ fputs("strncmp(\"abc\\0d\", \"abc\", '\\4') == 0: \@n", s);
373
  #include "vers2.h" (after macro replacement, before file access)
374
  "hello";
375
  "hello, world"
376
  ```
377
 
378
- Space around the `#` and `##` tokens in the macro definition is
379
- optional.
380
 
381
  — *end example*]
382
 
383
  [*Example 2*:
384
 
@@ -400,13 +408,13 @@ in_between(x hash_hash y)
400
  in_between(x ## y)
401
  mkstr(x ## y)
402
  "x ## y"
403
  ```
404
 
405
- In other words, expanding `hash_hash` produces a new token, consisting
406
- of two adjacent sharp signs, but this new token is not the `##`
407
- operator.
408
 
409
  — *end example*]
410
 
411
  [*Example 3*:
412
 
 
62
  name*. There is one name space for macro names. Any whitespace
63
  characters preceding or following the replacement list of preprocessing
64
  tokens are not considered part of the replacement list for either form
65
  of macro.
66
 
67
+ A translation unit shall not `#define` or `#undef` macro names lexically
68
+ identical to keywords, to the identifiers listed in
69
+ [[lex.name.special]], or to the *attribute-token*s described in 
70
+ [[dcl.attr]], except that the macro names `likely` and `unlikely` may be
71
+ defined as function-like macros.
72
+
73
  If a `#` preprocessing token, followed by an identifier, occurs
74
  lexically at the point at which a preprocessing directive can begin, the
75
  identifier is not subject to macro replacement.
76
 
77
  A preprocessing directive of the form
 
79
  ``` bnf
80
  '# define' identifier replacement-list new-line
81
  ```
82
 
83
  defines an *object-like macro* that causes each subsequent instance of
84
+ the macro name[^4]
85
 
86
  to be replaced by the replacement list of preprocessing tokens that
87
+ constitute the remainder of the directive.[^5]
88
 
89
  The replacement list is then rescanned for more macro names as specified
90
+ in [[cpp.rescan]].
91
 
92
  [*Example 2*:
93
 
94
  The simplest use of this facility is to define a “manifest constant”, as
95
  in
 
125
  matching parentheses forms the list of arguments for the function-like
126
  macro. The individual arguments within the list are separated by comma
127
  preprocessing tokens, but comma preprocessing tokens between matching
128
  inner parentheses do not separate arguments. If there are sequences of
129
  preprocessing tokens within the list of arguments that would otherwise
130
+ act as preprocessing directives,[^6]
131
 
132
+ the program is ill-formed.
133
 
134
  [*Example 3*:
135
 
136
  The following defines a function-like macro whose value is the maximum
137
  of its arguments. It has the disadvantages of evaluating one or the
 
165
 
166
  After the arguments for the invocation of a function-like macro have
167
  been identified, argument substitution takes place. For each parameter
168
  in the replacement list that is neither preceded by a `#` or `##`
169
  preprocessing token nor followed by a `##` preprocessing token, the
170
+ preprocessing tokens naming the parameter are replaced by a
171
+ preprocessing token sequence determined as follows:
172
 
173
  - If the parameter is of the form *va-opt-replacement*, the replacement
174
  preprocessing tokens are the preprocessing token sequence for the
175
  corresponding argument, as specified below.
176
  - Otherwise, the replacement preprocessing tokens are the preprocessing
177
  tokens of corresponding argument after all macros contained therein
178
  have been expanded. The argument’s preprocessing tokens are completely
179
  macro replaced before being substituted as if they formed the rest of
180
+ the preprocessing translation unit with no other preprocessing tokens
181
+ being available.
182
 
183
  [*Example 1*:
184
 
185
  ``` cpp
186
  #define LPAREN() (
 
296
  character string literal. Whitespace before the first preprocessing
297
  token and after the last preprocessing token comprising the stringizing
298
  argument is deleted. Otherwise, the original spelling of each
299
  preprocessing token in the stringizing argument is retained in the
300
  character string literal, except for special handling for producing the
301
+ spelling of *header-name*s, *character-literal*s, and *string-literal*s
302
+ (including the delimiting U+0022 (quotation mark) (`"`)) contained
303
+ within the preprocessing token: a U+005c (reverse solidus) character
304
+ (`\`) is inserted before each U+0022 (quotation mark) and
305
+ U+005c (reverse solidus) character of a *header-name*,
306
+ *character-literal*, or *string-literal*, and each new-line character is
307
+ replaced by the two-character sequence `\n`. If the replacement that
308
+ results is not a valid character string literal, the program is
309
+ ill-formed. The character string literal corresponding to an empty
310
+ stringizing argument is `""`. The order of evaluation of `#` and `##`
311
+ operators is unspecified.
312
 
313
  ### The `##` operator <a id="cpp.concat">[[cpp.concat]]</a>
314
 
315
  A `##` preprocessing token shall not occur at the beginning or at the
316
  end of a replacement list for either form of macro definition.
 
318
  If, in the replacement list of a function-like macro, a parameter is
319
  immediately preceded or followed by a `##` preprocessing token, the
320
  parameter is replaced by the corresponding argument’s preprocessing
321
  token sequence; however, if an argument consists of no preprocessing
322
  tokens, the parameter is replaced by a placemarker preprocessing token
323
+ instead.[^7]
324
 
325
  For both object-like and function-like macro invocations, before the
326
  replacement list is reexamined for more macro names to replace, each
327
  instance of a `##` preprocessing token in the replacement list (not from
328
  an argument) is deleted and the preceding preprocessing token is
329
  concatenated with the following preprocessing token. Placemarker
330
  preprocessing tokens are handled specially: concatenation of two
331
  placemarkers results in a single placemarker preprocessing token, and
332
  concatenation of a placemarker with a non-placemarker preprocessing
333
+ token results in the non-placemarker preprocessing token.
 
 
334
 
335
+ [*Note 1*: Concatenation can form a *universal-character-name*
336
+ [[lex.charset]]. *end note*]
 
337
 
338
+ If the result is not a valid preprocessing token, the program is
339
+ ill-formed. The resulting preprocessing token is available for further
340
+ macro replacement. The order of evaluation of `##` operators is
341
+ unspecified.
342
 
343
  [*Example 1*:
344
 
345
  The sequence
346
 
 
381
  #include "vers2.h" (after macro replacement, before file access)
382
  "hello";
383
  "hello, world"
384
  ```
385
 
386
+ Space around the `#` and `##` preprocessing tokens in the macro
387
+ definition is optional.
388
 
389
  — *end example*]
390
 
391
  [*Example 2*:
392
 
 
408
  in_between(x ## y)
409
  mkstr(x ## y)
410
  "x ## y"
411
  ```
412
 
413
+ In other words, expanding `hash_hash` produces a new preprocessing
414
+ token, consisting of two adjacent sharp signs, but this new
415
+ preprocessing token is not the `##` operator.
416
 
417
  — *end example*]
418
 
419
  [*Example 3*:
420