https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61982
--- Comment #11 from hyrosen at mail dot com --- (In reply to Jakub Jelinek from comment #10) > (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. Do you have a reference that demonstrates that?