https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89303
--- Comment #17 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #13)
> So if the two bugs have the same root cause, it seems to be a problem in
> __weak_count::_M_assign, failing to set _M_pi here:
>
> __weak_count&
> operator=(const __shared_count<_Lp>& __r) noexcept
> {
> _Sp_counted_base<_Lp>* __tmp = __r._M_pi;
> if (__tmp != nullptr)
> __tmp->_M_weak_add_ref();
> if (_M_pi != nullptr)
> _M_pi->_M_weak_release();
> _M_pi = __tmp;
> return *this;
> }
This ends up inlined into:
std::__shared_ptr<blob, 0>::__shared_ptr<std::allocator<blob> > (struct
__shared_ptr * const this, struct _Sp_alloc_shared_tag __tag)
and the GIMPLE dumps for -O1 -fno-tree-pta and -O1 do look significantly
different, explaining why _M_weak_this._M_refcount._M_pi doesn't get set.