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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions