https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91859
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
Status|RESOLVED |NEW
Last reconfirmed| |2019-09-23
Resolution|INVALID |---
Ever confirmed|0 |1
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The original report is invalid but the DSE optimization is **not** valid when
using C++20 destroying delete:
#include <stdio.h>
#include <stdlib.h>
#include <new>
struct Expression {
int i = 0;
void *operator new(size_t);
void operator delete(Expression *, std::destroying_delete_t);
};
void * Expression::operator new(size_t sz)
{
return malloc(sz);
}
void Expression::operator delete(Expression *p, std::destroying_delete_t)
{
Expression * e = p;
printf("%p : %d\n", e, e->i);
p->~Expression();
free(p);
}
int main()
{
auto p = new Expression();
p->i = 1;
delete p;
}
With this feature the compiler doesn't automatically invoke the destructor, so
the store to p->i is not dead, and must not be eliminated.
Not a regression though, because destroying delete wasn't supported before GCC
9.