This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 114b. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-05-06


2726. Alternative tokens appearing as attribute-tokens

Section: 5.5  [lex.digraph]     Status: review     Submitter: Jim X     Date: 2023-03-16     Liaison: EWG

Subclause 5.5 [lex.digraph] paragraph 2 specifies:

In all respects of the language, each alternative token behaves the same, respectively, as its primary token, except for its spelling. [ Footnote: ... ]

However, 9.12.1 [dcl.attr.grammar] paragraph 4 specifies:

... If a keyword (5.11 [lex.key]) or an alternative token (5.5 [lex.digraph]) that satisfies the syntactic requirements of an identifier (5.10 [lex.name]) is contained in an attribute-token, it is considered an identifier. ...

It seems an alternative token (say, or) is treated the same as the operator ||, yet only the alternative token is considered an identifier, not the operator, when appearing in an attribute-token. That seems contradictory.

Proposed resolution (approved by CWG 2023-05-12):

  1. Change in 5.2 [lex.phases] paragraph 2 as follows:

    Whitespace characters separating tokens are no longer significant. Each preprocessing token is converted into a token (5.6 [lex.token]), replacing each alternative token by its corresponding primary token (5.5 [lex.digraph]). The resulting tokens constitute a translation unit and are syntactically and semantically analyzed and translated.
  2. Change in 9.12.1 [dcl.attr.grammar] paragraph 4 as follows:

    ... If a keyword (5.11 [lex.key]) or an alternative token (5.5 [lex.digraph]) that satisfies the syntactic requirements of an identifier (5.10 [lex.name]) is contained in an attribute-token, it is considered an identifier. ...

This resolution also addresses issue 1897.

Additional notes (May, 2023)

During additional discussion on the EWG reflector, Alisdair Meredith expressed that he intends to propose that some alternative tokens be treated as full keywords in phase 7, to prevent and from being used as an rvalue reference and compl from being used for naming destructors. That would reverse the above direction.

Furthermore, an idea was floated to treat all alternative tokens as full keywords in phase 7 and as identifiers in phase 4, amending the grammar productions for expressions as necessary. This removes the special treatment of alternative tokens entirely, however the treatment of examples such as #define and blah would change from ill-formed to well-formed. Some opposition was voiced against changing the phase 4 treatment of alternative tokens.

CWG 2023-06-16

Forwarded to EWG with paper issue #1581.