https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61982
--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> --- (In reply to hyrosen from comment #9) > The storage for an object can still be accessible after the object is > destroyed. Therefore, writes in the destructor should not be eliminated > unless they are provably inaccessible: > > struct X { int i; ~X() { i = 0; } }; > > void destroy(X &x) { x.~X(); } > > int main() > { > alignas(X) char buf[sizeof(X)], save[sizeof(X)]; > X *x = new (buf) X; > x->i = 1; > memcpy(save, buf, sizeof(X)); > destroy(*x); > assert(memcmp(buf, save, sizeof(X)) != 0); > } No, that invokes UB.