https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112335
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> --- (In reply to Federico Kircheis from comment #2) > > Well s::~s could touch the reference std::unique_ptr<s> (ps1). > > In both cases, s::~s is called only once. > > Also during the move-assignment no user-provided-code is involved (except > the destruction of ps1, and even case of a user-provided deleter, it is only > called if the pointer is not nullptr. NO. NO. std::unique_ptr<s> t; __thread bool tt; inline s::~s() { if (tt) return; tt = true; t.reset(new s); tt = false; } Is still a valid ~s as far as I can tell. Yes it is odd but so what it is still valid. Now will anyone write code like this, doubt it. Also note clang does not optimize this with either libstdc++ or libc++.