cplusplus / nbballot

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

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

Closed wg21bot closed 1 year ago

wg21bot 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).

Proposed change: Change the definition of n-char to match the lexing behavior of other delimited character sequences like basic-c-char for character literals and basic-s-char, r-char, and d-char for string literals. 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

See CWG2640

jensmaurer commented 1 year ago

CWG 2022-11-07: Accepted.