From d9555c659e69fd334c71df6c2abceb176799a789 Mon Sep 17 00:00:00 2001 From: Alisdair Meredith Date: Sun, 22 Jun 2025 17:29:34 +0300 Subject: [PATCH] P2843R3 Preprocessing is never undefined Editorial notes: * [cpp.replace] Removed circular reference * Wording reconciled with resolution of CWG3015 --- source/lex.tex | 5 +---- source/lib-intro.tex | 10 ---------- source/preprocessor.tex | 43 +++++++++++++++++++++++++++-------------- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/source/lex.tex b/source/lex.tex index 4cc651a14d..1ed432dda3 100644 --- a/source/lex.tex +++ b/source/lex.tex @@ -521,10 +521,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 diff --git a/source/lib-intro.tex b/source/lib-intro.tex index 89fe033eae..76157ac902 100644 --- a/source/lib-intro.tex +++ b/source/lib-intro.tex @@ -3296,16 +3296,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 diff --git a/source/preprocessor.tex b/source/preprocessor.tex index 0c959e7b5d..9dad935146 100644 --- a/source/preprocessor.tex +++ b/source/preprocessor.tex @@ -543,7 +543,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 @@ -764,7 +764,7 @@ is \impldef{treatment of whitespace when processing a \tcode{\#include} directive}. If the attempt succeeds, the directive with the so-formed \grammarterm{header-name} is processed as specified for the previous form. -Otherwise, the behavior is undefined. +Otherwise, the program is ill-formed, no diagnostic required. \begin{note} Adjacent \grammarterm{string-literal}s are not concatenated into a single \grammarterm{string-literal} @@ -1529,6 +1529,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} @@ -1618,7 +1628,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} @@ -1813,16 +1823,21 @@ stringizing argument is retained in the character string literal, except for special handling for producing the spelling of \grammarterm{header-name}s, -\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}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 of a \grammarterm{header-name}, \grammarterm{character-literal}, -or \grammarterm{string-literal} -(including the delimiting \tcode{"} characters). +or \grammarterm{string-literal}, +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{\#} @@ -1871,7 +1886,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{\#\#} @@ -2082,7 +2097,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 @@ -2106,7 +2121,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}% @@ -2450,7 +2465,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.