https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112480
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> --- I think I prefer: --- a/libstdc++-v3/include/std/optional +++ b/libstdc++-v3/include/std/optional @@ -311,6 +311,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { if (this->_M_engaged) _M_destroy(); + + // The following seems redundant but improves codegen, see PR 112480. + if constexpr (is_trivially_destructible_v<_Tp>) + this->_M_engaged = false; } };