cplusplus / nbballot

Handling of NB comments in response to ballots
14 stars 4 forks source link

US 4-032 5.3p3 [lex.charset] Allow more characters in an n-char sequence #476

Closed jensmaurer closed 1 year ago

jensmaurer commented 1 year ago

The n-char grammar term is defined to match only the Latin uppercase, Latin digit, hyphen and space characters. This results in \N{ABC} matching named-universal-character while \N{abc} does not. This leads to programs like the following being unexpectedly well-formed because the \N{abc} sequence is lexed as the preprocessing token sequence \, N, {, abc, }. The expansion of macro a then leads to the token sequence being passed as an argument to macro z where it is discarded.

#define z(x) 0
#define a z(
int x = a\N{abc});

Changes to make the above program ill-formed would provide two benefits:

  1. Implementations could diagnose the \N{abc} sequence as an ill-formed named-universal-character regardless of where it appears in a program. The \N{…} syntax space would be reserved for expansion (e.g., for extensions or future support of UAX44-LM2 loose matching schemes).

Change the definition of n-char to match the lexing behavior of other delimited character sequence like basic-c-char for character literals and basic-s- char, r-char, and d-char for string literals. This will suffice to ensure that all \N{…} sequences are recognized as named-universal-characters (thereby making a program ill-formed per [lex.charset]p5 if the delimited character sequence does not specify a recognized name).

n-char:
  any member of the translation character set except the U+007D RIGHT CURLY BRACKET or new-line character
jensmaurer commented 1 year ago

Duplicate of #473 US 1-028 5.3p3 [lex.charset] Allow more characters in an n-char sequence.

jensmaurer commented 1 year ago

CWG2640