https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106965
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Richard Biener from comment #1) > I think it's undefined to invoke a DTOR twice which is what you do here. > After the DTOR the m_ptr member becomes undefined so re-evaluating that in > the second invocation (when there's no object of type X anymore) is > undefined. Right, and because you can't ever use the m_ptr member after the destructor, there's no point writing the 0 to it. That's a dead store, so the compiler is allowed to eliminate it. A correct program can never observe whether that store happened or not.