Skip to content

Clang considers destructor in noexcept expression that should call destroying delete #118660

@AlisdairM

Description

@AlisdairM

When a destroying delete function is called, the pointed-to object's destructor is not run --- it is the responsibility of the destroying delete function to run any destructors. However, when querying the noexcept operator for such a delete expression, Clang is considering the exception specification of the destructor, even though at runtime it clearly performs the right code.

#include <cstdio>
#include <new>

struct Explicit {
    ~Explicit() noexcept(false) { puts("should not be called");}

    void operator delete(Explicit*, std::destroying_delete_t) noexcept {
        std::puts("destroyed explicit");
    }
};

// #define  SHOW_BUGS
#if defined(SHOW_BUGS)

Explicit * qn = nullptr;
static_assert( noexcept(delete(qn)));

#endif

int main() {
    Explicit *q = new Explicit();
    delete q;
}

Here us a Compiler Explorer link to a more complete test, that passed on EDG even with the SHOW_BUGS macro defined:
https://godbolt.org/z/YaaeT8W17

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions