https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112480
Ivan Sorokin <vanyacpp at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |vanyacpp at gmail dot com --- Comment #5 from Ivan Sorokin <vanyacpp at gmail dot com> --- Perhaps something like this would do the trick? void _M_reset() { if (_M_engaged) _M_destroy(); else _M_engaged = _M_engaged; } On one hand _M_engaged = _M_engaged allows merging then and else branches without introducing new writes, on the other it can be optimized to no-op if the branches are not merged.