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

            Bug ID: 97647
           Summary: Accepts undefined delete expression in constant
                    expression
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: leni536 at gmail dot com
  Target Milestone: ---

version: g++ (Compiler-Explorer-Build) 11.0.0 20201029 (experimental)
options: -std=c++20 -O2 -pedantic-errors

g++ accepts the following program:

struct Base {};
struct Derived : Base{
    int i = 0;
};

constexpr int foo() {
    Base* ptr = new Derived{};
    delete ptr; //UB
    return 0;
}

constexpr int x = foo();

https://godbolt.org/z/MEnbM6

Deleting a Derived object through Base* is undefined behaviour.

Reply via email to