Skip to content

Commit b484f9d

Browse files
committed
P2843R3 Preprocessing is never undefined
Fixes #7937 Fixes cplusplus/papers#1548
1 parent 2e12f5e commit b484f9d

File tree

3 files changed

+27
-34
lines changed

3 files changed

+27
-34
lines changed

source/lex.tex

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,7 @@
480480
characters \tcode{*/}. These comments do not nest.
481481
\indextext{comment!\tcode{//}}%
482482
The characters \tcode{//} start a comment, which terminates immediately before the
483-
next new-line character. If there is a form-feed or a vertical-tab
484-
character in such a comment, only whitespace characters shall appear
485-
between it and the new-line that terminates the comment; no diagnostic
486-
is required.
483+
next new-line character.
487484
\begin{note}
488485
The comment characters \tcode{//}, \tcode{/*},
489486
and \tcode{*/} have no special meaning within a \tcode{//} comment and

source/lib-intro.tex

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3269,16 +3269,6 @@
32693269
\tcode{\#define} or \tcode{\#undef} names declared in any standard
32703270
library header.
32713271

3272-
\pnum
3273-
\indextext{unit!translation}%
3274-
A translation unit shall not \tcode{\#define} or \tcode{\#undef}
3275-
names lexically identical
3276-
to keywords,
3277-
to the identifiers listed in \tref{lex.name.special}, or
3278-
to the \grammarterm{attribute-token}{s} described in~\ref{dcl.attr},
3279-
except that the names \tcode{likely} and \tcode{unlikely} may be
3280-
defined as function-like macros~\iref{cpp.replace}.
3281-
32823272
\rSec4[extern.names]{External linkage}
32833273

32843274
\pnum

source/preprocessor.tex

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@
532532
\tcode{defined}
533533
unary operator does not match one of the two specified forms
534534
prior to macro replacement,
535-
the behavior is undefined.
535+
the program is ill-formed, no diagnostic required.
536536

537537
\pnum
538538
After all replacements due to macro expansion and
@@ -746,8 +746,8 @@
746746
(i.e., each identifier currently defined as a macro name is replaced by its
747747
replacement list of preprocessing tokens).
748748
If the directive resulting after all replacements does not match
749-
one of the two previous forms, the behavior is
750-
undefined.
749+
one of the two previous forms, the program is ill-formed, no diagnostic required.
750+
751751
\begin{note}
752752
Adjacent \grammarterm{string-literal}s are not concatenated into
753753
a single \grammarterm{string-literal}
@@ -1500,6 +1500,16 @@
15001500
replacement list of preprocessing tokens are not considered
15011501
part of the replacement list for either form of macro.
15021502

1503+
\pnum
1504+
\indextext{unit!translation}%
1505+
A translation unit shall not \tcode{\#define} or \tcode{\#undef}
1506+
names lexically identical
1507+
to keywords,
1508+
to the identifiers listed in \tref{lex.name.special}, or
1509+
to the \grammarterm{attribute-token}{s} described in~\ref{dcl.attr},
1510+
except that the names \tcode{likely} and \tcode{unlikely} may be
1511+
defined as function-like macros.
1512+
15031513
\pnum
15041514
If a
15051515
\indextext{\#\#0 operator@\tcode{\#} operator}
@@ -1589,7 +1599,7 @@
15891599
\begin{footnote}
15901600
A \grammarterm{conditionally-supported-directive} is a preprocessing directive regardless of whether the implementation supports it.
15911601
\end{footnote}
1592-
the behavior is undefined.
1602+
the program is ill-formed.
15931603

15941604
\pnum
15951605
\begin{example}
@@ -1783,19 +1793,15 @@
17831793
Otherwise, the original spelling of each preprocessing token in the
17841794
stringizing argument is retained in the character string literal,
17851795
except for special handling for producing the spelling of
1786-
\grammarterm{string-literal}s and \grammarterm{character-literal}s:
1787-
a
1788-
\tcode{\textbackslash}
1789-
character is inserted before each
1790-
\tcode{"}
1791-
and
1792-
\tcode{\textbackslash}
1793-
character of a \grammarterm{character-literal} or \grammarterm{string-literal}
1794-
(including the delimiting
1795-
\tcode{"}
1796-
characters).
1796+
\grammarterm{character-literal}s and \grammarterm{string-literal}s
1797+
(including the delimiting \unicode{0022}{quotation mark} (\tcode{"}))
1798+
contained within the preprocessing token:
1799+
a \unicode{005c}{reverse solidus} character (\tcode{\textbackslash})
1800+
is inserted before each \unicode{0022}{quotation mark} and
1801+
\unicode{005c}{reverse solidus} character and each new-line character is
1802+
replaced by the two-character sequence \tcode{\textbackslash n}.
17971803
If the replacement that results is not a valid character string literal,
1798-
the behavior is undefined. The character string literal corresponding to
1804+
the program is ill-formed. The character string literal corresponding to
17991805
an empty stringizing argument is \tcode{""}.
18001806
The order of evaluation of
18011807
\tcode{\#}
@@ -1844,7 +1850,7 @@
18441850
a \grammarterm{universal-character-name}\iref{lex.charset}.
18451851
\end{note}
18461852
If the result is not a valid preprocessing token,
1847-
the behavior is undefined.
1853+
the program is ill-formed.
18481854
The resulting preprocessing token is available for further macro replacement.
18491855
The order of evaluation of
18501856
\tcode{\#\#}
@@ -2055,7 +2061,7 @@
20552061
by the digit sequence (interpreted as a decimal integer).
20562062
If the digit sequence specifies zero
20572063
or a number greater than 2147483647,
2058-
the behavior is undefined.
2064+
the program is ill-formed.
20592065

20602066
\pnum
20612067
A preprocessing directive of the form
@@ -2079,7 +2085,7 @@
20792085
(each identifier currently defined as a macro name is replaced by its
20802086
replacement list of preprocessing tokens).
20812087
If the directive resulting after all replacements does not match
2082-
one of the two previous forms, the behavior is undefined;
2088+
one of the two previous forms, the program is ill-formed;
20832089
otherwise, the result is processed as appropriate.
20842090

20852091
\rSec1[cpp.error]{Diagnostic directives}%
@@ -2420,7 +2426,7 @@
24202426
or a
24212427
\tcode{\#undef}
24222428
preprocessing directive,
2423-
the behavior is undefined.
2429+
the program is ill-formed.
24242430
Any other predefined macro names shall begin with a
24252431
leading underscore followed by an uppercase letter or a second
24262432
underscore.

0 commit comments

Comments
 (0)