Skip to content

[Clang] Clang and GCC diverge on parsing new (std::nothrow_t()) #151468

@Xniao

Description

@Xniao

Description:

I'm seeking clarification on whether the following code is well-formed C++.
GCC accepts it, but Clang rejects it with:
error: cannot allocate function type 'std::nothrow_t ()' with new

Program

#include <new>

int main() {
    char* p = new (std::nothrow_t()) char[1];
    return 0;
}

Is this a parsing difference, or is one compiler incorrect?
Repro: https://godbolt.org/z/17zfedxds

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"diverges-from:gccDoes the clang frontend diverge from gcc on this issuegenerated by fuzzerquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions