[Bug c++/95514] constexpr dynamic memory allocation compile error with inheritance and the this pointer
pkeir at outlook dot com
gcc-bugzilla@gcc.gnu.org
Fri Aug 14 09:25:03 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95514
Paul Keir <pkeir at outlook dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #2 from Paul Keir <pkeir at outlook dot com> ---
Here is a reduced test case which removes prior use of static_cast and a
pointer reference parameter.
struct FooBase {
constexpr FooBase* get_this() { return this; }
int x;
};
struct Foo : FooBase {};
constexpr bool test()
{
Foo* pf = new Foo;
delete pf->get_this();
return true;
}
constexpr bool b = test();
--- Comment #3 from Paul Keir <pkeir at outlook dot com> ---
The code invokes undefined behaviour; as it tries to delete the object through
pointer to base.
More information about the Gcc-bugs
mailing list