Skip to content

clang places calls to operator delete even for noexcept constructors #67405

@TheShermanTanker

Description

@TheShermanTanker

Unlike gcc, clang always turns compiler placed calls to operator delete for exception handling into hard errors if operator delete was marked deleted. gcc instead simply leaves out the call to operator delete in this situation. Issue of which compiler is conforming to the standard in this case aside, this is a huge problem for clang, because it is unable to see that noexcept constructors will never throw, which means you can't mark a constructor noexcept to prevent clang from putting that call to operator delete in there, which becomes a compilation breaking error if you want to delete operator delete for that class/struct:

#include <new>
#include <cinttypes>

struct Allocation {
    Allocation() noexcept;
    void operator delete(void*) = delete;
    void operator delete(void*, size_t) = delete;
};

int main() {
    Allocation* volatile pointer = new Allocation();
}

clang++ -std=c++14 -emit-llvm -pedantic -c new.cpp

new.cpp:11:40: error: attempt to use a deleted function
Allocation* volatile pointer = new Allocation();
^
new.cpp:6:10: note: 'operator delete' has been explicitly marked deleted here
void operator delete(void*) = delete;
^
1 error generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:codegenIR generation bugs: mangling, exceptions, etc.diverges-from:gccDoes the clang frontend diverge from gcc on this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions