Skip to content

CWG3125 [cpp.cond] Premature and otherwise redundant requirement for "token"s in #if #813

Description

@hubert-reinterpretcast

Full name of submitter (unless configured in github; will be published with the issue): Hubert Tong

Reference (section label): [cpp.cond]

Link to reflector thread (if any): N/A

Issue description:

Consider https://godbolt.org/z/4d7bha7W4:

#define F(X) X
#if __has_include(F(<#.h>))
#endif

https://wg21.link/cpp.cond#8 requires that the preprocessing tokens that appear in #if after "all macro replacements have occurred shall be in the lexical form of a token." https://wg21.link/cpp.cond#10 is clear that the macro replacements occur prior to evaluation (including evaluation of has-include-expression‌s, etc.). This means that the "token" requirement is enforced prior to the formation of header-name‌s from header-name-token‌s. Thus the above is ill-formed due to the # preprocessing token; however, that result seems unintended (and only EDG enforces it).

Paragraph 8 is generally redundant anyway: When the preprocessing tokens are converted into tokens in https://wg21.link/cpp.cond#11, https://wg21.link/lex.pptoken#2 applies.

Suggested resolution:

Strike [cpp.cond] paragraph 8:

Each preprocessing token that remains (in the list of preprocessing tokens that will become the controlling expression) after all macro replacements have occurred shall be in the lexical form of a token.

Activity

  1. jensmaurer commented on Nov 18, 2025

    @jensmaurer
    Member
  2. changed the title [-][cpp.cond] Premature and otherwise redundant requirement for "token"s in `#if`[/-] [+]CWG3125 [cpp.cond] Premature and otherwise redundant requirement for "token"s in `#if`[/+] on Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions