Skip to content

Preprocessing numbers with dollar signs are rejected when they are accepted in identifiers #171190

@Halalaluyafail3

Description

@Halalaluyafail3

The following program demonstrates the issue:

#define CAT(X,Y,Z)CAT_(X,Y##Z)
#define CAT_(X,Y)X##Y
int main(){
    int CAT(X,0,$);
}

Clang rejects this because it believes 0$ is not a valid preprocessing token. GCC and MSVC accept this code. Considering that the definition of pp-number references identifier-continue, I don't see any reason that this code should be rejected.

This also applies after a digit separator:

#define STR(X)#X
int main(){
    STR(0'$);
}

C23 defines the optional support for dollar signs in identifiers by allowing nondigits to include dollar signs. So the reference to nondigit in pp-number should also allow a dollar sign after a digit separator. MSVC accepts this, GCC doesn't. See also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123057

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partydiverges-from:gccDoes the clang frontend diverge from gcc on this issuediverges-from:msvcDoes the clang frontend diverge from msvc on this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions