Skip to content

P2843R3 Preprocessing is never undefined #7981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions source/lex.tex
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,7 @@
characters \tcode{*/}. These comments do not nest.
\indextext{comment!\tcode{//}}%
The characters \tcode{//} start a comment, which terminates immediately before the
next new-line character. If there is a form-feed or a vertical-tab
character in such a comment, only whitespace characters shall appear
between it and the new-line that terminates the comment; no diagnostic
is required.
next new-line character.
\begin{note}
The comment characters \tcode{//}, \tcode{/*},
and \tcode{*/} have no special meaning within a \tcode{//} comment and
Expand Down
10 changes: 0 additions & 10 deletions source/lib-intro.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3269,16 +3269,6 @@
\tcode{\#define} or \tcode{\#undef} names declared in any standard
library header.

\pnum
\indextext{unit!translation}%
A translation unit shall not \tcode{\#define} or \tcode{\#undef}
names lexically identical
to keywords,
to the identifiers listed in \tref{lex.name.special}, or
to the \grammarterm{attribute-token}{s} described in~\ref{dcl.attr},
except that the names \tcode{likely} and \tcode{unlikely} may be
defined as function-like macros~\iref{cpp.replace}.

\rSec4[extern.names]{External linkage}

\pnum
Expand Down
48 changes: 28 additions & 20 deletions source/preprocessor.tex
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@
\tcode{defined}
unary operator does not match one of the two specified forms
prior to macro replacement,
the behavior is undefined.
the program is ill-formed, no diagnostic required.

\pnum
After all replacements due to macro expansion and
Expand Down Expand Up @@ -746,8 +746,8 @@
(i.e., each identifier currently defined as a macro name is replaced by its
replacement list of preprocessing tokens).
If the directive resulting after all replacements does not match
one of the two previous forms, the behavior is
undefined.
one of the two previous forms, the program is ill-formed, no diagnostic required.

\begin{note}
Adjacent \grammarterm{string-literal}s are not concatenated into
a single \grammarterm{string-literal}
Expand Down Expand Up @@ -1500,6 +1500,16 @@
replacement list of preprocessing tokens are not considered
part of the replacement list for either form of macro.

\pnum
\indextext{unit!translation}%
A translation unit shall not \tcode{\#define} or \tcode{\#undef}
names lexically identical
to keywords,
to the identifiers listed in \tref{lex.name.special}, or
to the \grammarterm{attribute-token}{s} described in~\ref{dcl.attr},
except that the names \tcode{likely} and \tcode{unlikely} may be
defined as function-like macros.

\pnum
If a
\indextext{\#\#0 operator@\tcode{\#} operator}
Expand Down Expand Up @@ -1589,7 +1599,7 @@
\begin{footnote}
A \grammarterm{conditionally-supported-directive} is a preprocessing directive regardless of whether the implementation supports it.
\end{footnote}
the behavior is undefined.
the program is ill-formed.

\pnum
\begin{example}
Expand Down Expand Up @@ -1783,19 +1793,17 @@
Otherwise, the original spelling of each preprocessing token in the
stringizing argument is retained in the character string literal,
except for special handling for producing the spelling of
\grammarterm{string-literal}s and \grammarterm{character-literal}s:
a
\tcode{\textbackslash}
character is inserted before each
\tcode{"}
and
\tcode{\textbackslash}
character of a \grammarterm{character-literal} or \grammarterm{string-literal}
(including the delimiting
\tcode{"}
characters).
\grammarterm{character-literal}s and \grammarterm{string-literal}s
(including the delimiting \unicode{0022}{quotation mark} (\tcode{"}))
contained within the preprocessing token:
a \unicode{005c}{reverse solidus} character (\tcode{\textbackslash})
is inserted before each \unicode{0022}{quotation mark} and
\unicode{005c}{reverse solidus} character,
and each new-line character is
replaced by the two-character sequence \tcode{\textbackslash n}.
If the replacement that results is not a valid character string literal,
the behavior is undefined. The character string literal corresponding to
the program is ill-formed.
The character string literal corresponding to
an empty stringizing argument is \tcode{""}.
The order of evaluation of
\tcode{\#}
Expand Down Expand Up @@ -1844,7 +1852,7 @@
a \grammarterm{universal-character-name}\iref{lex.charset}.
\end{note}
If the result is not a valid preprocessing token,
the behavior is undefined.
the program is ill-formed.
The resulting preprocessing token is available for further macro replacement.
The order of evaluation of
\tcode{\#\#}
Expand Down Expand Up @@ -2055,7 +2063,7 @@
by the digit sequence (interpreted as a decimal integer).
If the digit sequence specifies zero
or a number greater than 2147483647,
the behavior is undefined.
the program is ill-formed.

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

\rSec1[cpp.error]{Diagnostic directives}%
Expand Down Expand Up @@ -2420,7 +2428,7 @@
or a
\tcode{\#undef}
preprocessing directive,
the behavior is undefined.
the program is ill-formed.
Any other predefined macro names shall begin with a
leading underscore followed by an uppercase letter or a second
underscore.
Expand Down