https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122336

            Bug ID: 122336
           Summary: Deleting object of abstract class type which has
                    non-virtual destructor is permitted in constant
                    evaluated expressions
           Product: gcc
           Version: 15.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: clement.metz-gcc.8dpx4 at simplelogin dot com
  Target Milestone: ---

The following code introduces an undefined behavior. Thus, it should not
compile when evaluated in a constant expression.

However, gcc-15.2 and gcc-trunk both compile this code without errors.

Note that the warning -Wdelete-non-virtual-dtor is correctly raised.

https://godbolt.org/z/a1rxjTEh4


struct Base {
    ~Base() = default;
    virtual void foo() = 0;
};

struct Derived: Base {
    void foo() override {}
};

constexpr bool test() {
    Base * base = new Derived();
    delete base;  // (1)
    return true;
}

// This should not compile, because of (1)
static_assert(test());

Reply via email to