Index: boost/enable_shared_from_this.hpp =================================================================== --- boost/enable_shared_from_this.hpp (revision 44373) +++ boost/enable_shared_from_this.hpp (working copy) @@ -30,7 +30,8 @@ if( !owned() && _internal_shared_this.get() == 0 ) { T * p = dynamic_cast(const_cast(this)); - _internal_shared_this = shared_ptr( p, detail::sp_deleter_wrapper() ); + detail::shared_count c(p, detail::sp_deleter_wrapper()); + shared_ptr(c, p).swap(_internal_shared_this); BOOST_ASSERT(_internal_shared_this.get() == this); _internal_weak_this = _internal_shared_this; } @@ -125,10 +126,6 @@ } } -template< class T, class Y > inline void sp_accept_owner( boost::shared_ptr * /*ptr*/, boost::enable_shared_from_this const * /*pe*/, boost::detail::sp_deleter_wrapper * /*pd*/ ) -{ -} - } // namespace boost #endif // #ifndef BOOST_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED Index: boost/detail/shared_count.hpp =================================================================== --- boost/detail/shared_count.hpp (revision 44373) +++ boost/detail/shared_count.hpp (working copy) @@ -25,7 +25,6 @@ #include #include #include -#include #include #include @@ -46,8 +45,6 @@ #endif -struct sp_nothrow_tag {}; - class weak_count; class shared_count @@ -217,8 +214,7 @@ if( pi_ != 0 ) pi_->add_ref_copy(); } - explicit shared_count(weak_count const & r); // throws bad_weak_ptr when r.use_count() == 0 - shared_count( weak_count const & r, sp_nothrow_tag ); // constructs an empty *this when r.use_count() == 0 + explicit shared_count(weak_count const & r); // nothrow shared_count & operator= (shared_count const & r) // nothrow { @@ -366,17 +362,6 @@ , id_(shared_count_id) #endif { - if( pi_ == 0 || !pi_->add_ref_lock() ) - { - boost::throw_exception( boost::bad_weak_ptr() ); - } -} - -inline shared_count::shared_count( weak_count const & r, sp_nothrow_tag ): pi_( r.pi_ ) -#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) - , id_(shared_count_id) -#endif -{ if( pi_ != 0 && !pi_->add_ref_lock() ) { pi_ = 0; Index: boost/weak_ptr.hpp =================================================================== --- boost/weak_ptr.hpp (revision 44373) +++ boost/weak_ptr.hpp (working copy) @@ -93,7 +93,8 @@ shared_ptr lock() const // never throws { - return shared_ptr( *this, boost::detail::sp_nothrow_tag() ); + detail::shared_count c(pn); + return shared_ptr(c, !c.empty() ? px : 0); } long use_count() const // never throws Index: boost/shared_ptr.hpp =================================================================== --- boost/shared_ptr.hpp (revision 44373) +++ boost/shared_ptr.hpp (working copy) @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -199,19 +200,19 @@ #endif template - explicit shared_ptr(weak_ptr const & r): pn(r.pn) // may throw + explicit shared_ptr(weak_ptr const & r): pn(r.pn) { - // it is now safe to copy r.px, as pn(r.pn) did not throw + if( pn.empty() ) + boost::throw_exception( boost::bad_weak_ptr() ); + + // it is now safe to copy r.px, as pn is not empty px = r.px; } template - shared_ptr( weak_ptr const & r, boost::detail::sp_nothrow_tag ): px( 0 ), pn( r.pn, boost::detail::sp_nothrow_tag() ) // never throws + shared_ptr(detail::shared_count & c, Y * p): px(p) // never throws { - if( !pn.empty() ) - { - px = r.px; - } + pn.swap(c); } template @@ -468,6 +469,11 @@ return pn.get_deleter( ti ); } + detail::shared_count const & _internal_shared_count() const // never throws + { + return pn; + } + // Tasteless as this may seem, making all members public allows member templates // to work in the absence of member template friends. (Matthew Langston)