Skip to content

Problems in token pasting #132535

Open
Open
@kyuupichan

Description

@kyuupichan

The token pasting code gets several tricky cases wrong. Consider the following for c++23:

#define concat1 \ ## Udeadbeef
concat1
#define concat2 R ## "averylongdelimiter()averylongdelimiter"
concat2
#define concat3 __VA_ARGS_ ## _
concat3
#define concat4 L'b' ## ud_suffix
concat4
#define concat5 R ## "aわ()aわ"
concat5

concat1 is invalid because the UCN is not a valid codepoint. Clang accepts it.
concat2 should diagnose the long raw literal delimiter. Clang does not.
concat3 should complain about an invalid use of __VA_ARGS__. Clang does not.
concat4 is a wide character literal with a user-defined suffix, clang rejects it saying a space is required. I believe it is valid.
concat5 contains an invalid character in the raw string delimiter, clang accepts it.

I used clang -E --std=c++23

$ clang --version
Apple clang version 16.0.0 (clang-1600.0.26.6)
Target: arm64-apple-darwin24.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions