Skip to content

CWG3076 [cpp.include][cpp.cond] Unnecessary IFNDR: _string-literal_ spellings not starting with " as _header-name-tokens_ #768

Description

@hubert-reinterpretcast

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

Reference (section label): [cpp.include], [cpp.cond]

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

Issue description:

The process of forming a header-name preprocessing token from pp-tokens in https://wg21.link/cpp.include#7 is bound to fail when the first such token is a string-literal whose spelling does not start with ". Such a failure is specified to be IFNDR.

As this process is invoked—potentially with such an input—from multiple places in the standard that use the header-name-tokens production (https://wg21.link/cpp.cond#nt:header-name-tokens), and implementations appear to diagnose this case (see https://godbolt.org/z/Y45jdbfeo), it may be prudent to make the case plain ill-formed.

Test case from Compiler Explorer link above:

#include L"hello"

This generates similar errors from GCC, Clang, EDG, and both MSVC preprocessor implementations.

Suggested resolution:

Modify in https://wg21.link/cpp.include#7:

Then, an attempt is made to form a header-name preprocessing token ([lex.header]) from the whitespace and the characters of the spellings of the resulting sequence of preprocessing tokens, which shall start with a string-literal only if its spelling begins with U+0022 QUOTATION MARK; the treatment of whitespace is implementation-defined.

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