From 2648f0b8a58eec0f2d906bf09fa3422ccfcf28f6 Mon Sep 17 00:00:00 2001 From: Alisdair Meredith Date: Sat, 25 Oct 2025 12:59:06 -0400 Subject: [PATCH 1/2] [cpp.line] Address string-literal vs s-char-sequence The text of this specification places a restriction on a string-literal that is not present in the grammar, although the grammar is an exact match for a string-literal with that restriction. The restricted term is also used when specifying the effects of the line directive with a string, so prefer to move string-literal into the grammar rather than strike that paragraph and adjust the effects. Added a cross-reference to where character string literal is defined as it may not be obvious to all readers that this is a term of power, even though it is defined as a term and has an index entry. --- source/preprocessor.tex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/preprocessor.tex b/source/preprocessor.tex index 5b82675e1d..543c2e270e 100644 --- a/source/preprocessor.tex +++ b/source/preprocessor.tex @@ -2074,7 +2074,7 @@ The \grammarterm{string-literal} of a \tcode{\#line} directive, if present, -shall be a character string literal. +shall be a character string literal\iref{cpp.stringize}. \pnum The @@ -2102,7 +2102,7 @@ \pnum A preprocessing directive of the form \begin{ncsimplebnf} -\terminal{\# line} digit-sequence \terminal{"} \opt{s-char-sequence} \terminal{"} new-line +\terminal{\# line} digit-sequence \terminal{"} \opt{string-literal} \terminal{"} new-line \end{ncsimplebnf} sets the presumed line number similarly and changes the presumed name of the source file to be the contents From 51c435756f6b48c67a7ca1bd46f5212c63d31db4 Mon Sep 17 00:00:00 2001 From: Alisdair Meredith Date: Sat, 25 Oct 2025 14:30:55 -0400 Subject: [PATCH 2/2] [lex.string] Adopt plain-string-literal grammar to simplify string literals There are several places in the grammar where we want to refer to a plain character string literal without a prefix and that is not raw. Introduce _character-string_ into the grammar to replace a quoted _s-char-sequence_ in a number of places, and move the `R` of a raw string literal into the _raw-string_ grammar so that _raw-string_ and _character-string_ are used consistently where they appear. --- source/lex.tex | 19 +++++++++++-------- source/preprocessor.tex | 12 +++--------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/source/lex.tex b/source/lex.tex index 8005b33374..0385a92363 100644 --- a/source/lex.tex +++ b/source/lex.tex @@ -613,7 +613,7 @@ parenthesis is identified. The raw string literal is defined as the shortest sequence of characters that matches the raw-string pattern \begin{ncbnf} -\opt{encoding-prefix} \terminal{R} raw-string +\opt{encoding-prefix} raw-string \end{ncbnf} \item Otherwise, if the next three characters are \tcode{<::} and the subsequent character @@ -1799,8 +1799,13 @@ \indextext{literal!string}% \begin{bnf} \nontermdef{string-literal}\br - \opt{encoding-prefix} \terminal{"} \opt{s-char-sequence} \terminal{"}\br - \opt{encoding-prefix} \terminal{R} raw-string + \opt{encoding-prefix} plain-string-literal\br + \opt{encoding-prefix} raw-string +\end{bnf} + +\begin{bnf} +\nontermdef{plain-string-literal}\br + \terminal{"} \opt{s-char-sequence} \terminal{"} \end{bnf} \begin{bnf} @@ -1823,7 +1828,7 @@ \begin{bnf} \nontermdef{raw-string}\br - \terminal{"} \opt{d-char-sequence} \terminal{(} \opt{r-char-sequence} \terminal{)} \opt{d-char-sequence} \terminal{"} + \terminal{R} \terminal{"} \opt{d-char-sequence} \terminal{(} \opt{r-char-sequence} \terminal{)} \opt{d-char-sequence} \terminal{"} \end{bnf} \begin{bnf} @@ -2110,12 +2115,10 @@ \begin{bnf} \nontermdef{unevaluated-string}\br - string-literal + plain-string-literal\br + raw-string \end{bnf} -\pnum -An \grammarterm{unevaluated-string} shall have no \grammarterm{encoding-prefix}. - \pnum Each \grammarterm{universal-character-name} and each \grammarterm{simple-escape-sequence} in an \grammarterm{unevaluated-string} is replaced by the member of the translation character set it denotes. diff --git a/source/preprocessor.tex b/source/preprocessor.tex index 543c2e270e..50af810187 100644 --- a/source/preprocessor.tex +++ b/source/preprocessor.tex @@ -1805,7 +1805,7 @@ token in the replacement list. \pnum -A \defn{character string literal} is a \grammarterm{string-literal} with no prefix. +A \defn{character string literal} is a \grammarterm{plain-string-literal}. If, in the replacement list, a parameter is immediately preceded by a \tcode{\#} @@ -2070,12 +2070,6 @@ \indextext{preprocessing directive!line control}% \indextext{\idxcode{\#line}|see{preprocessing directive, line control}} -\pnum -The \grammarterm{string-literal} of a -\tcode{\#line} -directive, if present, -shall be a character string literal\iref{cpp.stringize}. - \pnum The \defn{line number} @@ -2102,11 +2096,11 @@ \pnum A preprocessing directive of the form \begin{ncsimplebnf} -\terminal{\# line} digit-sequence \terminal{"} \opt{string-literal} \terminal{"} new-line +\terminal{\# line} digit-sequence plain-string-literal new-line \end{ncsimplebnf} sets the presumed line number similarly and changes the presumed name of the source file to be the contents -of the character string literal. +of the \grammarterm{plain-string-literal}. \pnum A preprocessing directive of the form