diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 89b8ebb6a4e..60bcb2000ba 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,7 @@ +2005-11-09 Paolo Carlini + + * include/tr1/boost_shared_ptr.h: Trivial formatting fixes. + 2005-11-08 Benjamin Kosnik * testsuite/lib/libstdc++.exp (check_v3_target_debug_mode): Use diff --git a/libstdc++-v3/include/tr1/boost_shared_ptr.h b/libstdc++-v3/include/tr1/boost_shared_ptr.h index 01250aa107c..345e17f8785 100644 --- a/libstdc++-v3/include/tr1/boost_shared_ptr.h +++ b/libstdc++-v3/include/tr1/boost_shared_ptr.h @@ -64,10 +64,9 @@ class bad_weak_ptr : public std::exception { public: - virtual char const* what() const throw() - { - return "tr1::bad_weak_ptr"; - } + virtual char const* + what() const throw() + { return "tr1::bad_weak_ptr"; } }; // Helper for exception objects in @@ -83,7 +82,7 @@ __throw_bad_weak_ptr() } -template +template struct _Sp_deleter { typedef void result_type; @@ -140,22 +139,22 @@ public: { __gnu_cxx::lock lock(_M_mutex); if (__gnu_cxx::__exchange_and_add(&_M_use_count, 1) == 0) - { - _M_use_count = 0; - __throw_bad_weak_ptr(); - } + { + _M_use_count = 0; + __throw_bad_weak_ptr(); + } } void release() // nothrow { if (__gnu_cxx::__exchange_and_add(&_M_use_count, -1) == 1) - { - dispose(); - __glibcxx_mutex_lock(_M_mutex); - __glibcxx_mutex_unlock(_M_mutex); - weak_release(); - } + { + dispose(); + __glibcxx_mutex_lock(_M_mutex); + __glibcxx_mutex_unlock(_M_mutex); + weak_release(); + } } void @@ -168,11 +167,11 @@ public: weak_release() // nothrow { if (__gnu_cxx::__exchange_and_add(&_M_weak_count, -1) == 1) - { - __glibcxx_mutex_lock(_M_mutex); - __glibcxx_mutex_unlock(_M_mutex); - destroy(); - } + { + __glibcxx_mutex_lock(_M_mutex); + __glibcxx_mutex_unlock(_M_mutex); + destroy(); + } } long @@ -184,45 +183,46 @@ public: private: _Sp_counted_base(_Sp_counted_base const&); - _Sp_counted_base& operator= (_Sp_counted_base const&); + _Sp_counted_base& operator=(_Sp_counted_base const&); _Atomic_word _M_use_count; // #shared _Atomic_word _M_weak_count; // #weak + (#shared != 0) __gnu_cxx::mutex_type _M_mutex; }; -template -class _Sp_counted_base_impl : public _Sp_counted_base -{ -public: - - /** - * @brief - * @pre d(p) must not throw. - */ - _Sp_counted_base_impl(_Ptr __p, _Deleter __d) - : _M_ptr(__p), _M_del(__d) - { } - - virtual void - dispose() // nothrow +template + class _Sp_counted_base_impl + : public _Sp_counted_base { - _M_del(_M_ptr); - } + public: - virtual void* - get_deleter(const std::type_info& __ti) - { - return __ti == typeid(_Deleter) ? &_M_del : 0; - } - -private: - _Sp_counted_base_impl(const _Sp_counted_base_impl&); - _Sp_counted_base_impl& operator=(const _Sp_counted_base_impl&); - - _Ptr _M_ptr; // copy constructor must not throw - _Deleter _M_del; // copy constructor must not throw -}; + /** + * @brief + * @pre d(p) must not throw. + */ + _Sp_counted_base_impl(_Ptr __p, _Deleter __d) + : _M_ptr(__p), _M_del(__d) + { } + + virtual void + dispose() // nothrow + { + _M_del(_M_ptr); + } + + virtual void* + get_deleter(const std::type_info& __ti) + { + return __ti == typeid(_Deleter) ? &_M_del : 0; + } + + private: + _Sp_counted_base_impl(const _Sp_counted_base_impl&); + _Sp_counted_base_impl& operator=(const _Sp_counted_base_impl&); + + _Ptr _M_ptr; // copy constructor must not throw + _Deleter _M_del; // copy constructor must not throw + }; class weak_count; @@ -240,28 +240,27 @@ public: : _M_pi(0) // nothrow { } - template + template shared_count(_Ptr __p, _Deleter __d) : _M_pi(0) { try - { - _M_pi = new _Sp_counted_base_impl<_Ptr, _Deleter>(__p, __d); - } + { + _M_pi = new _Sp_counted_base_impl<_Ptr, _Deleter>(__p, __d); + } catch(...) - { - __d(__p); // delete __p - __throw_exception_again; - } + { + __d(__p); // delete __p + __throw_exception_again; + } } // auto_ptr<_Tp> is special cased to provide the strong guarantee - template + template explicit shared_count(std::auto_ptr<_Tp>& __r) - : _M_pi(new _Sp_counted_base_impl<_Tp*,_Sp_deleter<_Tp> >( - __r.get(), _Sp_deleter<_Tp>() - )) + : _M_pi(new _Sp_counted_base_impl<_Tp*, + _Sp_deleter<_Tp> >(__r.get(), _Sp_deleter<_Tp>())) { __r.release(); } // throws bad_weak_ptr when __r.use_count() == 0 @@ -286,13 +285,13 @@ public: _Sp_counted_base* __tmp = __r._M_pi; if(__tmp != _M_pi) - { - if(__tmp != 0) - __tmp->add_ref_copy(); - if(_M_pi != 0) - _M_pi->release(); - _M_pi = __tmp; - } + { + if(__tmp != 0) + __tmp->add_ref_copy(); + if(_M_pi != 0) + _M_pi->release(); + _M_pi = __tmp; + } return *this; } @@ -411,58 +410,52 @@ shared_count::shared_count(const weak_count& __r) : _M_pi(__r._M_pi) { if (_M_pi != 0) - { _M_pi->add_ref_lock(); - } else - { __throw_bad_weak_ptr(); - } } // fwd decls -template class weak_ptr; -template class enable_shared_from_this; +template + class weak_ptr; + +template + class enable_shared_from_this; struct __static_cast_tag {}; struct __const_cast_tag {}; struct __dynamic_cast_tag {}; struct __polymorphic_cast_tag {}; -template struct shared_ptr_traits -{ - typedef _Tp & reference; -}; +template + struct shared_ptr_traits + { typedef _Tp& reference; }; -template<> struct shared_ptr_traits -{ - typedef void reference; -}; +template<> + struct shared_ptr_traits + { typedef void reference; }; -template<> struct shared_ptr_traits -{ - typedef void reference; -}; +template<> + struct shared_ptr_traits + { typedef void reference; }; -template<> struct shared_ptr_traits -{ - typedef void reference; -}; +template<> + struct shared_ptr_traits + { typedef void reference; }; -template<> struct shared_ptr_traits -{ - typedef void reference; -}; +template<> + struct shared_ptr_traits + { typedef void reference; }; // enable_shared_from_this support // friend of enable_shared_from_this -template +template void - __enable_shared_from_this( const shared_count& __pn, - const enable_shared_from_this<_Tp1>* __pe, - const _Tp2* __px ); + __enable_shared_from_this(const shared_count& __pn, + const enable_shared_from_this<_Tp1>* __pe, + const _Tp2* __px ); inline void __enable_shared_from_this(const shared_count&, ...) @@ -476,7 +469,7 @@ __enable_shared_from_this(const shared_count&, ...) * is destroyed or reset. */ -template +template class shared_ptr { typedef typename shared_ptr_traits<_Tp>::reference _Reference; @@ -488,15 +481,16 @@ template /** @brief Construct an empty %shared_ptr. * @post use_count()==0 && get()==0 */ - shared_ptr() : _M_ptr(0), _M_refcount() // never throws + shared_ptr() + : _M_ptr(0), _M_refcount() // never throws { } /** @brief Construct a %shared_ptr that owns the pointer @a p. * @param p A pointer that is convertible to element_type*. - * @post use_count()==1 && get()==p + * @post use_count() == 1 && get() == p * @throw std::bad_alloc, in which case @c delete @a p is called. */ - template + template explicit shared_ptr(_Tp1* __p) : _M_ptr(__p), _M_refcount(__p, _Sp_deleter<_Tp1>()) { @@ -515,10 +509,10 @@ template * and the deleter @a d. * @param p A pointer. * @param d A deleter. - * @post use_count()==1 && get()==p + * @post use_count() == 1 && get() == p * @throw std::bad_alloc, in which case @a d(p) is called. */ - template + template shared_ptr(_Tp1* __p, _Deleter __d) : _M_ptr(__p), _M_refcount(__p, __d) { @@ -533,10 +527,10 @@ template /** @brief If @a r is empty, constructs an empty %shared_ptr; otherwise * construct a %shared_ptr that shares ownership with @a r. * @param r A %shared_ptr. - * @post get()==r.get() && use_count()==r.use_count() + * @post get() == r.get() && use_count() == r.use_count() * @throw std::bad_alloc, in which case */ - template + template shared_ptr(const shared_ptr<_Tp1>& __r) : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) // never throws { @@ -546,11 +540,11 @@ template /** @brief Constructs a %shared_ptr that shares ownership with @a r * and stores a copy of the pointer stored in @a r. * @param r A weak_ptr. - * @post use_count()==r.use_count() + * @post use_count() == r.use_count() * @throw bad_weak_ptr when r.expired(), * in which case the constructor has no effect. */ - template + template explicit shared_ptr(const weak_ptr<_Tp1>& __r) : _M_refcount(__r._M_refcount) // may throw { @@ -561,9 +555,9 @@ template } /** - * @post use_count()==1 and r.get()==0 + * @post use_count() == 1 and r.get() == 0 */ - template + template explicit shared_ptr(std::auto_ptr<_Tp1>& __r) : _M_ptr(__r.get()), _M_refcount() { @@ -575,30 +569,28 @@ template __enable_shared_from_this( _M_refcount, __tmp, __tmp ); } - template + template shared_ptr(const shared_ptr<_Tp1>& __r, __static_cast_tag) - : _M_ptr(static_cast(__r._M_ptr)) - , _M_refcount(__r._M_refcount) + : _M_ptr(static_cast(__r._M_ptr)), + _M_refcount(__r._M_refcount) { } - template + template shared_ptr(const shared_ptr<_Tp1>& __r, __const_cast_tag) - : _M_ptr(const_cast(__r._M_ptr)) - , _M_refcount(__r._M_refcount) + : _M_ptr(const_cast(__r._M_ptr)), + _M_refcount(__r._M_refcount) { } - template + template shared_ptr(const shared_ptr<_Tp1>& __r, __dynamic_cast_tag) - : _M_ptr(dynamic_cast(__r._M_ptr)) - , _M_refcount(__r._M_refcount) + : _M_ptr(dynamic_cast(__r._M_ptr)), + _M_refcount(__r._M_refcount) { if (_M_ptr == 0) // need to allocate new counter -- the cast failed - { _M_refcount = shared_count(); - } } - template + template shared_ptr& operator=(const shared_ptr<_Tp1>& __r) // never throws { @@ -607,7 +599,7 @@ template return *this; } - template + template shared_ptr& operator=(std::auto_ptr<_Tp1>& __r) { @@ -619,15 +611,16 @@ template reset() // never throws { shared_ptr().swap(*this); } - template + template void reset(_Tp1* __p) // _Tp1 must be complete { - _GLIBCXX_DEBUG_ASSERT(__p == 0 || __p != _M_ptr); // catch self-reset errors + _GLIBCXX_DEBUG_ASSERT(__p == 0 || __p != _M_ptr); // catch self-reset + // errors shared_ptr(__p).swap(*this); } - template + template void reset(_Tp1 * __p, _Deleter __d) { shared_ptr(__p, __d).swap(*this); } @@ -679,7 +672,7 @@ template { return _M_refcount.get_deleter(__ti); } private: - template + template bool _M_less(const shared_ptr<_Tp1>& __rhs) const { return _M_refcount < __rhs._M_refcount; } @@ -688,17 +681,17 @@ template template friend class weak_ptr; // friends injected into enclosing namespace and found by ADL: - template + template friend inline bool operator==(const shared_ptr& __a, const shared_ptr<_Tp1>& __b) { return __a.get() == __b.get(); } - template + template friend inline bool operator!=(const shared_ptr& __a, const shared_ptr<_Tp1>& __b) { return __a.get() != __b.get(); } - template + template friend inline bool operator<(const shared_ptr& __a, const shared_ptr<_Tp1>& __b) { return __a._M_less(__b); } @@ -714,7 +707,7 @@ template * will eventually result in undefined behaviour, * attempting to delete the same object twice. */ -template +template shared_ptr<_Tp> static_pointer_cast(const shared_ptr<_Tp1>& __r) { @@ -726,7 +719,7 @@ template * will eventually result in undefined behaviour, * attempting to delete the same object twice. */ -template +template shared_ptr<_Tp> const_pointer_cast(const shared_ptr<_Tp1>& __r) { @@ -738,7 +731,7 @@ template * will eventually result in undefined behaviour, * attempting to delete the same object twice. */ -template +template shared_ptr<_Tp> dynamic_pointer_cast(const shared_ptr<_Tp1>& __r) { @@ -746,7 +739,7 @@ template } // 2.2.3.7 shared_ptr I/O -template +template std::basic_ostream<_Ch, _Tr>& operator<<(std::basic_ostream<_Ch, _Tr>& __os, const shared_ptr<_Tp>& __p) { @@ -755,13 +748,13 @@ template } // 2.2.3.10 shared_ptr get_deleter (experimental) -template +template inline _Del* get_deleter(const shared_ptr<_Tp>& __p) { return static_cast<_Del*>(__p._M_get_deleter(typeid(_Del))); } -template +template class weak_ptr { public: @@ -772,26 +765,26 @@ template : _M_ptr(0), _M_refcount() // never throws { } - // generated copy constructor, assignment, destructor are fine + // generated copy constructor, assignment, destructor are fine - // - // The "obvious" converting constructor implementation: - // - // template - // weak_ptr(weak_ptr const & r): _M_ptr(r._M_ptr), _M_refcount(r._M_refcount) // never throws - // { - // } - // - // has a serious problem. - // - // r._M_ptr may already have been invalidated. The _M_ptr(r._M_ptr) - // conversion may require access to *r._M_ptr (virtual inheritance). - // - // It is not possible to avoid spurious access violations since - // in multithreaded programs r._M_ptr may be invalidated at any point. - // + // + // The "obvious" converting constructor implementation: + // + // template + // weak_ptr(weak_ptr const & r) + // : _M_ptr(r._M_ptr), _M_refcount(r._M_refcount) // never throws + // { } + // + // has a serious problem. + // + // r._M_ptr may already have been invalidated. The _M_ptr(r._M_ptr) + // conversion may require access to *r._M_ptr (virtual inheritance). + // + // It is not possible to avoid spurious access violations since + // in multithreaded programs r._M_ptr may be invalidated at any point. + // - template + template weak_ptr(const weak_ptr<_Tp1>& r) : _M_refcount(r._M_refcount) // never throws { @@ -799,14 +792,14 @@ template _M_ptr = r.lock().get(); } - template + template weak_ptr(const shared_ptr<_Tp1>& r) : _M_ptr(r._M_ptr), _M_refcount(r._M_refcount) // never throws { __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) } - template + template weak_ptr& operator=(const weak_ptr<_Tp1>& r) // never throws { @@ -815,7 +808,7 @@ template return *this; } - template + template weak_ptr& operator=(const shared_ptr<_Tp1>& r) // never throws { @@ -831,25 +824,25 @@ template // optimization: avoid throw overhead if (expired()) - { - return shared_ptr(); - } - + return shared_ptr(); + try - { - return shared_ptr(*this); - } + { + return shared_ptr(*this); + } catch (const bad_weak_ptr&) - { - // Q: how can we get here? - // A: another thread may have invalidated r after the use_count test above. - return shared_ptr(); - } + { + // Q: how can we get here? + // A: another thread may have invalidated r after the + // use_count test above. + return shared_ptr(); + } #else // optimization: avoid try/catch overhead when single threaded - return expired() ? shared_ptr() : shared_ptr(*this); + return expired() ? shared_ptr() + : shared_ptr(*this); #endif } // XXX MT @@ -876,7 +869,7 @@ template private: - template + template bool _M_less(const weak_ptr<_Tp1>& __rhs) const { return _M_refcount < __rhs._M_refcount; } @@ -891,13 +884,13 @@ template // friend injected into namespace and found by ADL - template + template friend inline bool operator<(const weak_ptr& __lhs, const weak_ptr<_Tp1>& __rhs) { return __lhs._M_less(__rhs); } - template friend class weak_ptr; - template friend class shared_ptr; + template friend class weak_ptr; + template friend class shared_ptr; friend class enable_shared_from_this<_Tp>; _Tp* _M_ptr; // contained pointer @@ -906,8 +899,7 @@ template }; // weak_ptr - -template +template class enable_shared_from_this { protected: @@ -930,26 +922,28 @@ template shared_ptr<_Tp> shared_from_this() { - shared_ptr<_Tp> p(this->_M_weak_this); - return p; + shared_ptr<_Tp> __p(this->_M_weak_this); + return __p; } shared_ptr shared_from_this() const { - shared_ptr p(this->_M_weak_this); - return p; + shared_ptr __p(this->_M_weak_this); + return __p; } private: - template + template void _M_weak_assign(_Tp1* __p, const shared_count& __n) const { _M_weak_this._M_assign(__p, __n); } - template + template friend void - __enable_shared_from_this( const shared_count& __pn, const enable_shared_from_this* __pe, const _Tp1* __px) + __enable_shared_from_this(const shared_count& __pn, + const enable_shared_from_this* __pe, + const _Tp1* __px) { if(__pe != 0) __pe->_M_weak_assign(const_cast<_Tp1*>(__px), __pn); @@ -964,7 +958,7 @@ template * @brief std::swap() specialisation for shared_ptr. * @relates shared_ptr. */ -template +template inline void swap(tr1::shared_ptr<_Tp>& __a, tr1::shared_ptr<_Tp>& __b) { @@ -975,7 +969,7 @@ template * @brief std::swap() specialisation for weak_ptr. * @relates weak_ptr. */ -template +template void swap(tr1::weak_ptr<_Tp>& __a, tr1::weak_ptr<_Tp>& __b) {