[Bug c++/97647] New: Accepts undefined delete expression in constant expression
leni536 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Fri Oct 30 19:06:14 GMT 2020
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.
More information about the Gcc-bugs
mailing list