diff options
-rw-r--r-- | libstdc++-v3/ChangeLog | 8 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/shared_ptr.h | 52 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/shared_ptr_base.h | 198 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc | 4 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc | 6 |
5 files changed, 141 insertions, 127 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index e399b2b..3b56f06 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,13 @@ 2011-05-18 Jonathan Wakely <jwakely.gcc@gmail.com> + * include/bits/shared_ptr_base.h: Use noexcept. Define special member + functions as defaulted/deleted. + * include/bits/shared_ptr.h: Use noexcept. + * 20_util/shared_ptr/cons/43820_neg.cc: Adjust dg-error line numbers. + * 20_util/weak_ptr/comparison/cmp_neg.cc: Likewise. + +2011-05-18 Jonathan Wakely <jwakely.gcc@gmail.com> + * doc/xml/manual/bitmap_allocator.xml: Fix typos. 2011-05-18 Paolo Carlini <paolo.carlini@oracle.com> diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h index 490810c..2158de6 100644 --- a/libstdc++-v3/include/bits/shared_ptr.h +++ b/libstdc++-v3/include/bits/shared_ptr.h @@ -73,7 +73,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// 2.2.3.10 shared_ptr get_deleter (experimental) template<typename _Del, typename _Tp, _Lock_policy _Lp> inline _Del* - get_deleter(const __shared_ptr<_Tp, _Lp>& __p) + get_deleter(const __shared_ptr<_Tp, _Lp>& __p) noexcept { #ifdef __GXX_RTTI return static_cast<_Del*>(__p._M_get_deleter(typeid(_Del))); @@ -97,7 +97,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @brief Construct an empty %shared_ptr. * @post use_count()==0 && get()==0 */ - constexpr shared_ptr() + constexpr shared_ptr() noexcept : __shared_ptr<_Tp>() { } /** @@ -201,7 +201,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @endcode */ template<typename _Tp1> - shared_ptr(const shared_ptr<_Tp1>& __r, _Tp* __p) + shared_ptr(const shared_ptr<_Tp1>& __r, _Tp* __p) noexcept : __shared_ptr<_Tp>(__r, __p) { } /** @@ -213,7 +213,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ template<typename _Tp1, typename = typename std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type> - shared_ptr(const shared_ptr<_Tp1>& __r) + shared_ptr(const shared_ptr<_Tp1>& __r) noexcept : __shared_ptr<_Tp>(__r) { } /** @@ -221,7 +221,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __r A %shared_ptr rvalue. * @post *this contains the old value of @a __r, @a __r is empty. */ - shared_ptr(shared_ptr&& __r) + shared_ptr(shared_ptr&& __r) noexcept : __shared_ptr<_Tp>(std::move(__r)) { } /** @@ -231,7 +231,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ template<typename _Tp1, typename = typename std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type> - shared_ptr(shared_ptr<_Tp1>&& __r) + shared_ptr(shared_ptr<_Tp1>&& __r) noexcept : __shared_ptr<_Tp>(std::move(__r)) { } /** @@ -261,12 +261,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __p A null pointer constant. * @post use_count() == 0 && get() == nullptr */ - constexpr shared_ptr(nullptr_t __p) + constexpr shared_ptr(nullptr_t __p) noexcept : __shared_ptr<_Tp>(__p) { } template<typename _Tp1> shared_ptr& - operator=(const shared_ptr<_Tp1>& __r) // never throws + operator=(const shared_ptr<_Tp1>& __r) noexcept { this->__shared_ptr<_Tp>::operator=(__r); return *this; @@ -283,7 +283,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif shared_ptr& - operator=(shared_ptr&& __r) + operator=(shared_ptr&& __r) noexcept { this->__shared_ptr<_Tp>::operator=(std::move(__r)); return *this; @@ -291,7 +291,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<class _Tp1> shared_ptr& - operator=(shared_ptr<_Tp1>&& __r) + operator=(shared_ptr<_Tp1>&& __r) noexcept { this->__shared_ptr<_Tp>::operator=(std::move(__r)); return *this; @@ -425,23 +425,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // 20.8.13.2.9 shared_ptr specialized algorithms. template<typename _Tp> inline void - swap(shared_ptr<_Tp>& __a, shared_ptr<_Tp>& __b) + swap(shared_ptr<_Tp>& __a, shared_ptr<_Tp>& __b) noexcept { __a.swap(__b); } // 20.8.13.2.10 shared_ptr casts. template<typename _Tp, typename _Tp1> inline shared_ptr<_Tp> - static_pointer_cast(const shared_ptr<_Tp1>& __r) + static_pointer_cast(const shared_ptr<_Tp1>& __r) noexcept { return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get())); } template<typename _Tp, typename _Tp1> inline shared_ptr<_Tp> - const_pointer_cast(const shared_ptr<_Tp1>& __r) + const_pointer_cast(const shared_ptr<_Tp1>& __r) noexcept { return shared_ptr<_Tp>(__r, const_cast<_Tp*>(__r.get())); } template<typename _Tp, typename _Tp1> inline shared_ptr<_Tp> - dynamic_pointer_cast(const shared_ptr<_Tp1>& __r) + dynamic_pointer_cast(const shared_ptr<_Tp1>& __r) noexcept { if (_Tp* __p = dynamic_cast<_Tp*>(__r.get())) return shared_ptr<_Tp>(__r, __p); @@ -458,22 +458,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION class weak_ptr : public __weak_ptr<_Tp> { public: - constexpr weak_ptr() + constexpr weak_ptr() noexcept : __weak_ptr<_Tp>() { } template<typename _Tp1, typename = typename std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type> - weak_ptr(const weak_ptr<_Tp1>& __r) + weak_ptr(const weak_ptr<_Tp1>& __r) noexcept : __weak_ptr<_Tp>(__r) { } template<typename _Tp1, typename = typename std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type> - weak_ptr(const shared_ptr<_Tp1>& __r) + weak_ptr(const shared_ptr<_Tp1>& __r) noexcept : __weak_ptr<_Tp>(__r) { } template<typename _Tp1> weak_ptr& - operator=(const weak_ptr<_Tp1>& __r) // never throws + operator=(const weak_ptr<_Tp1>& __r) noexcept { this->__weak_ptr<_Tp>::operator=(__r); return *this; @@ -481,14 +481,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _Tp1> weak_ptr& - operator=(const shared_ptr<_Tp1>& __r) // never throws + operator=(const shared_ptr<_Tp1>& __r) noexcept { this->__weak_ptr<_Tp>::operator=(__r); return *this; } shared_ptr<_Tp> - lock() const // never throws + lock() const noexcept { #ifdef __GTHREADS if (this->expired()) @@ -511,7 +511,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // 20.8.13.3.7 weak_ptr specialized algorithms. template<typename _Tp> inline void - swap(weak_ptr<_Tp>& __a, weak_ptr<_Tp>& __b) + swap(weak_ptr<_Tp>& __a, weak_ptr<_Tp>& __b) noexcept { __a.swap(__b); } @@ -538,12 +538,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION class enable_shared_from_this { protected: - constexpr enable_shared_from_this() { } + constexpr enable_shared_from_this() noexcept { } - enable_shared_from_this(const enable_shared_from_this&) { } + enable_shared_from_this(const enable_shared_from_this&) noexcept { } enable_shared_from_this& - operator=(const enable_shared_from_this&) + operator=(const enable_shared_from_this&) noexcept { return *this; } ~enable_shared_from_this() { } @@ -560,14 +560,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION private: template<typename _Tp1> void - _M_weak_assign(_Tp1* __p, const __shared_count<>& __n) const + _M_weak_assign(_Tp1* __p, const __shared_count<>& __n) const noexcept { _M_weak_this._M_assign(__p, __n); } template<typename _Tp1> friend void __enable_shared_from_this_helper(const __shared_count<>& __pn, const enable_shared_from_this* __pe, - const _Tp1* __px) + const _Tp1* __px) noexcept { if (__pe != 0) __pe->_M_weak_assign(const_cast<_Tp1*>(__px), __pn); diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index 937e4f4..0a84b3c 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -61,7 +61,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { public: virtual char const* - what() const throw(); + what() const noexcept; virtual ~bad_weak_ptr() throw(); }; @@ -108,21 +108,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public _Mutex_base<_Lp> { public: - _Sp_counted_base() + _Sp_counted_base() noexcept : _M_use_count(1), _M_weak_count(1) { } virtual - ~_Sp_counted_base() // nothrow + ~_Sp_counted_base() noexcept { } // Called when _M_use_count drops to zero, to release the resources // managed by *this. virtual void - _M_dispose() = 0; // nothrow + _M_dispose() noexcept = 0; // Called when _M_weak_count drops to zero. virtual void - _M_destroy() // nothrow + _M_destroy() noexcept { delete this; } virtual void* @@ -136,7 +136,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _M_add_ref_lock(); void - _M_release() // nothrow + _M_release() noexcept { // Be race-detector-friendly. For more info see bits/c++config. _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_use_count); @@ -166,11 +166,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } void - _M_weak_add_ref() // nothrow + _M_weak_add_ref() noexcept { __gnu_cxx::__atomic_add_dispatch(&_M_weak_count, 1); } void - _M_weak_release() // nothrow + _M_weak_release() noexcept { // Be race-detector-friendly. For more info see bits/c++config. _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_weak_count); @@ -189,7 +189,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } long - _M_get_use_count() const // nothrow + _M_get_use_count() const noexcept { // No memory barrier is used here so there is no synchronization // with other threads. @@ -197,8 +197,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } private: - _Sp_counted_base(_Sp_counted_base const&); - _Sp_counted_base& operator=(_Sp_counted_base const&); + _Sp_counted_base(_Sp_counted_base const&) = delete; + _Sp_counted_base& operator=(_Sp_counted_base const&) = delete; _Atomic_word _M_use_count; // #shared _Atomic_word _M_weak_count; // #weak + (#shared != 0) @@ -289,11 +289,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _M_ptr(__p) { } virtual void - _M_dispose() // nothrow + _M_dispose() noexcept { delete _M_ptr; } virtual void - _M_destroy() // nothrow + _M_destroy() noexcept { delete this; } virtual void* @@ -309,15 +309,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<> inline void - _Sp_counted_ptr<nullptr_t, _S_single>::_M_dispose() { } + _Sp_counted_ptr<nullptr_t, _S_single>::_M_dispose() noexcept { } template<> inline void - _Sp_counted_ptr<nullptr_t, _S_mutex>::_M_dispose() { } + _Sp_counted_ptr<nullptr_t, _S_mutex>::_M_dispose() noexcept { } template<> inline void - _Sp_counted_ptr<nullptr_t, _S_atomic>::_M_dispose() { } + _Sp_counted_ptr<nullptr_t, _S_atomic>::_M_dispose() noexcept { } // Support for custom deleter and/or allocator template<typename _Ptr, typename _Deleter, typename _Alloc, _Lock_policy _Lp> @@ -347,11 +347,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _M_ptr(__p), _M_del(__d, __a) { } virtual void - _M_dispose() // nothrow + _M_dispose() noexcept { _M_del._M_del(_M_ptr); } virtual void - _M_destroy() // nothrow + _M_destroy() noexcept { _My_alloc_type __a(_M_del); this->~_Sp_counted_deleter(); @@ -413,7 +413,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Override because the allocator needs to know the dynamic type virtual void - _M_destroy() // nothrow + _M_destroy() noexcept { typedef typename _Alloc::template rebind<_Sp_counted_ptr_inplace>::other _My_alloc_type; @@ -424,7 +424,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Sneaky trick so __shared_ptr can get the managed pointer virtual void* - _M_get_deleter(const std::type_info& __ti) + _M_get_deleter(const std::type_info& __ti) noexcept { #ifdef __GXX_RTTI return __ti == typeid(_Sp_make_shared_tag) @@ -444,7 +444,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION class __shared_count { public: - constexpr __shared_count() : _M_pi(0) // nothrow + constexpr __shared_count() noexcept : _M_pi(0) { } template<typename _Ptr> @@ -545,21 +545,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Throw bad_weak_ptr when __r._M_get_use_count() == 0. explicit __shared_count(const __weak_count<_Lp>& __r); - ~__shared_count() // nothrow + ~__shared_count() noexcept { if (_M_pi != 0) _M_pi->_M_release(); } - __shared_count(const __shared_count& __r) - : _M_pi(__r._M_pi) // nothrow + __shared_count(const __shared_count& __r) noexcept + : _M_pi(__r._M_pi) { if (_M_pi != 0) _M_pi->_M_add_ref_copy(); } __shared_count& - operator=(const __shared_count& __r) // nothrow + operator=(const __shared_count& __r) noexcept { _Sp_counted_base<_Lp>* __tmp = __r._M_pi; if (__tmp != _M_pi) @@ -574,7 +574,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } void - _M_swap(__shared_count& __r) // nothrow + _M_swap(__shared_count& __r) noexcept { _Sp_counted_base<_Lp>* __tmp = __r._M_pi; __r._M_pi = _M_pi; @@ -582,28 +582,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } long - _M_get_use_count() const // nothrow + _M_get_use_count() const noexcept { return _M_pi != 0 ? _M_pi->_M_get_use_count() : 0; } bool - _M_unique() const // nothrow + _M_unique() const noexcept { return this->_M_get_use_count() == 1; } void* - _M_get_deleter(const std::type_info& __ti) const + _M_get_deleter(const std::type_info& __ti) const noexcept { return _M_pi ? _M_pi->_M_get_deleter(__ti) : 0; } bool - _M_less(const __shared_count& __rhs) const + _M_less(const __shared_count& __rhs) const noexcept { return std::less<_Sp_counted_base<_Lp>*>()(this->_M_pi, __rhs._M_pi); } bool - _M_less(const __weak_count<_Lp>& __rhs) const + _M_less(const __weak_count<_Lp>& __rhs) const noexcept { return std::less<_Sp_counted_base<_Lp>*>()(this->_M_pi, __rhs._M_pi); } // Friend function injected into enclosing namespace and found by ADL friend inline bool - operator==(const __shared_count& __a, const __shared_count& __b) + operator==(const __shared_count& __a, const __shared_count& __b) noexcept { return __a._M_pi == __b._M_pi; } private: @@ -637,29 +637,31 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION class __weak_count { public: - constexpr __weak_count() : _M_pi(0) // nothrow + constexpr __weak_count() noexcept : _M_pi(0) { } - __weak_count(const __shared_count<_Lp>& __r) : _M_pi(__r._M_pi) // nothrow + __weak_count(const __shared_count<_Lp>& __r) noexcept + : _M_pi(__r._M_pi) { if (_M_pi != 0) _M_pi->_M_weak_add_ref(); } - __weak_count(const __weak_count<_Lp>& __r) : _M_pi(__r._M_pi) // nothrow + __weak_count(const __weak_count<_Lp>& __r) noexcept + : _M_pi(__r._M_pi) { if (_M_pi != 0) _M_pi->_M_weak_add_ref(); } - ~__weak_count() // nothrow + ~__weak_count() noexcept { if (_M_pi != 0) _M_pi->_M_weak_release(); } __weak_count<_Lp>& - operator=(const __shared_count<_Lp>& __r) // nothrow + operator=(const __shared_count<_Lp>& __r) noexcept { _Sp_counted_base<_Lp>* __tmp = __r._M_pi; if (__tmp != 0) @@ -671,7 +673,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } __weak_count<_Lp>& - operator=(const __weak_count<_Lp>& __r) // nothrow + operator=(const __weak_count<_Lp>& __r) noexcept { _Sp_counted_base<_Lp>* __tmp = __r._M_pi; if (__tmp != 0) @@ -683,7 +685,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } void - _M_swap(__weak_count<_Lp>& __r) // nothrow + _M_swap(__weak_count<_Lp>& __r) noexcept { _Sp_counted_base<_Lp>* __tmp = __r._M_pi; __r._M_pi = _M_pi; @@ -691,20 +693,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } long - _M_get_use_count() const // nothrow + _M_get_use_count() const noexcept { return _M_pi != 0 ? _M_pi->_M_get_use_count() : 0; } bool - _M_less(const __weak_count& __rhs) const + _M_less(const __weak_count& __rhs) const noexcept { return std::less<_Sp_counted_base<_Lp>*>()(this->_M_pi, __rhs._M_pi); } bool - _M_less(const __shared_count<_Lp>& __rhs) const + _M_less(const __shared_count<_Lp>& __rhs) const noexcept { return std::less<_Sp_counted_base<_Lp>*>()(this->_M_pi, __rhs._M_pi); } // Friend function injected into enclosing namespace and found by ADL friend inline bool - operator==(const __weak_count& __a, const __weak_count& __b) + operator==(const __weak_count& __a, const __weak_count& __b) noexcept { return __a._M_pi == __b._M_pi; } private: @@ -732,18 +734,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION void __enable_shared_from_this_helper(const __shared_count<_Lp>&, const __enable_shared_from_this<_Tp1, - _Lp>*, const _Tp2*); + _Lp>*, const _Tp2*) noexcept; // Friend of enable_shared_from_this. template<typename _Tp1, typename _Tp2> void __enable_shared_from_this_helper(const __shared_count<>&, const enable_shared_from_this<_Tp1>*, - const _Tp2*); + const _Tp2*) noexcept; template<_Lock_policy _Lp> inline void - __enable_shared_from_this_helper(const __shared_count<_Lp>&, ...) + __enable_shared_from_this_helper(const __shared_count<_Lp>&, ...) noexcept { } @@ -753,8 +755,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION public: typedef _Tp element_type; - constexpr __shared_ptr() - : _M_ptr(0), _M_refcount() // never throws + constexpr __shared_ptr() noexcept + : _M_ptr(0), _M_refcount() { } template<typename _Tp1> @@ -795,20 +797,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { } template<typename _Tp1> - __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r, _Tp* __p) + __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r, _Tp* __p) noexcept : _M_ptr(__p), _M_refcount(__r._M_refcount) // never throws { } - // generated copy constructor, assignment, destructor are fine. + __shared_ptr(const __shared_ptr&) noexcept = default; + __shared_ptr& operator=(const __shared_ptr&) noexcept = default; + ~__shared_ptr() = default; template<typename _Tp1, typename = typename std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type> - __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r) - : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) // never throws + __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r) noexcept + : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) { } - __shared_ptr(__shared_ptr&& __r) - : _M_ptr(__r._M_ptr), _M_refcount() // never throws + __shared_ptr(__shared_ptr&& __r) noexcept + : _M_ptr(__r._M_ptr), _M_refcount() { _M_refcount._M_swap(__r._M_refcount); __r._M_ptr = 0; @@ -816,8 +820,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _Tp1, typename = typename std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type> - __shared_ptr(__shared_ptr<_Tp1, _Lp>&& __r) - : _M_ptr(__r._M_ptr), _M_refcount() // never throws + __shared_ptr(__shared_ptr<_Tp1, _Lp>&& __r) noexcept + : _M_ptr(__r._M_ptr), _M_refcount() { _M_refcount._M_swap(__r._M_refcount); __r._M_ptr = 0; @@ -860,13 +864,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /* TODO: use delegating constructor */ - constexpr __shared_ptr(nullptr_t) - : _M_ptr(0), _M_refcount() // never throws + constexpr __shared_ptr(nullptr_t) noexcept + : _M_ptr(0), _M_refcount() { } template<typename _Tp1> __shared_ptr& - operator=(const __shared_ptr<_Tp1, _Lp>& __r) // never throws + operator=(const __shared_ptr<_Tp1, _Lp>& __r) noexcept { _M_ptr = __r._M_ptr; _M_refcount = __r._M_refcount; // __shared_count::op= doesn't throw @@ -884,7 +888,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif __shared_ptr& - operator=(__shared_ptr&& __r) + operator=(__shared_ptr&& __r) noexcept { __shared_ptr(std::move(__r)).swap(*this); return *this; @@ -892,7 +896,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<class _Tp1> __shared_ptr& - operator=(__shared_ptr<_Tp1, _Lp>&& __r) + operator=(__shared_ptr<_Tp1, _Lp>&& __r) noexcept { __shared_ptr(std::move(__r)).swap(*this); return *this; @@ -907,7 +911,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } void - reset() // never throws + reset() noexcept { __shared_ptr().swap(*this); } template<typename _Tp1> @@ -931,36 +935,36 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Allow class instantiation when _Tp is [cv-qual] void. typename std::add_lvalue_reference<_Tp>::type - operator*() const // never throws + operator*() const noexcept { _GLIBCXX_DEBUG_ASSERT(_M_ptr != 0); return *_M_ptr; } _Tp* - operator->() const // never throws + operator->() const noexcept { _GLIBCXX_DEBUG_ASSERT(_M_ptr != 0); return _M_ptr; } _Tp* - get() const // never throws + get() const noexcept { return _M_ptr; } explicit operator bool() const // never throws { return _M_ptr == 0 ? false : true; } bool - unique() const // never throws + unique() const noexcept { return _M_refcount._M_unique(); } long - use_count() const // never throws + use_count() const noexcept { return _M_refcount._M_get_use_count(); } void - swap(__shared_ptr<_Tp, _Lp>& __other) // never throws + swap(__shared_ptr<_Tp, _Lp>& __other) noexcept { std::swap(_M_ptr, __other._M_ptr); _M_refcount._M_swap(__other._M_refcount); @@ -1033,14 +1037,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION private: void* - _M_get_deleter(const std::type_info& __ti) const + _M_get_deleter(const std::type_info& __ti) const noexcept { return _M_refcount._M_get_deleter(__ti); } template<typename _Tp1, _Lock_policy _Lp1> friend class __shared_ptr; template<typename _Tp1, _Lock_policy _Lp1> friend class __weak_ptr; template<typename _Del, typename _Tp1, _Lock_policy _Lp1> - friend _Del* get_deleter(const __shared_ptr<_Tp1, _Lp1>&); + friend _Del* get_deleter(const __shared_ptr<_Tp1, _Lp1>&) noexcept; _Tp* _M_ptr; // Contained pointer. __shared_count<_Lp> _M_refcount; // Reference counter. @@ -1151,7 +1155,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct _Sp_less : public binary_function<_Sp, _Sp, bool> { bool - operator()(const _Sp& __lhs, const _Sp& __rhs) const + operator()(const _Sp& __lhs, const _Sp& __rhs) const noexcept { typedef typename _Sp::element_type element_type; return std::less<element_type*>()(__lhs.get(), __rhs.get()); @@ -1166,7 +1170,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // 2.2.3.8 shared_ptr specialized algorithms. template<typename _Tp, _Lock_policy _Lp> inline void - swap(__shared_ptr<_Tp, _Lp>& __a, __shared_ptr<_Tp, _Lp>& __b) + swap(__shared_ptr<_Tp, _Lp>& __a, __shared_ptr<_Tp, _Lp>& __b) noexcept { __a.swap(__b); } // 2.2.3.9 shared_ptr casts @@ -1178,7 +1182,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// static_pointer_cast template<typename _Tp, typename _Tp1, _Lock_policy _Lp> inline __shared_ptr<_Tp, _Lp> - static_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r) + static_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r) noexcept { return __shared_ptr<_Tp, _Lp>(__r, static_cast<_Tp*>(__r.get())); } // The seemingly equivalent code: @@ -1188,7 +1192,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// const_pointer_cast template<typename _Tp, typename _Tp1, _Lock_policy _Lp> inline __shared_ptr<_Tp, _Lp> - const_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r) + const_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r) noexcept { return __shared_ptr<_Tp, _Lp>(__r, const_cast<_Tp*>(__r.get())); } // The seemingly equivalent code: @@ -1198,7 +1202,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// dynamic_pointer_cast template<typename _Tp, typename _Tp1, _Lock_policy _Lp> inline __shared_ptr<_Tp, _Lp> - dynamic_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r) + dynamic_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r) noexcept { if (_Tp* __p = dynamic_cast<_Tp*>(__r.get())) return __shared_ptr<_Tp, _Lp>(__r, __p); @@ -1212,11 +1216,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION public: typedef _Tp element_type; - constexpr __weak_ptr() - : _M_ptr(0), _M_refcount() // never throws + constexpr __weak_ptr() noexcept + : _M_ptr(0), _M_refcount() { } - // Generated copy constructor, assignment, destructor are fine. + __weak_ptr(const __weak_ptr&) noexcept = default; + __weak_ptr& operator=(const __weak_ptr&) noexcept = default; + ~__weak_ptr() = default; // The "obvious" converting constructor implementation: // @@ -1234,19 +1240,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // in multithreaded programs __r._M_ptr may be invalidated at any point. template<typename _Tp1, typename = typename std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type> - __weak_ptr(const __weak_ptr<_Tp1, _Lp>& __r) - : _M_refcount(__r._M_refcount) // never throws + __weak_ptr(const __weak_ptr<_Tp1, _Lp>& __r) noexcept + : _M_refcount(__r._M_refcount) { _M_ptr = __r.lock().get(); } template<typename _Tp1, typename = typename std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type> - __weak_ptr(const __shared_ptr<_Tp1, _Lp>& __r) - : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) // never throws + __weak_ptr(const __shared_ptr<_Tp1, _Lp>& __r) noexcept + : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) { } template<typename _Tp1> __weak_ptr& - operator=(const __weak_ptr<_Tp1, _Lp>& __r) // never throws + operator=(const __weak_ptr<_Tp1, _Lp>& __r) noexcept { _M_ptr = __r.lock().get(); _M_refcount = __r._M_refcount; @@ -1255,7 +1261,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _Tp1> __weak_ptr& - operator=(const __shared_ptr<_Tp1, _Lp>& __r) // never throws + operator=(const __shared_ptr<_Tp1, _Lp>& __r) noexcept { _M_ptr = __r._M_ptr; _M_refcount = __r._M_refcount; @@ -1263,7 +1269,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } __shared_ptr<_Tp, _Lp> - lock() const // never throws + lock() const noexcept { #ifdef __GTHREADS // Optimization: avoid throw overhead. @@ -1291,11 +1297,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } // XXX MT long - use_count() const // never throws + use_count() const noexcept { return _M_refcount._M_get_use_count(); } bool - expired() const // never throws + expired() const noexcept { return _M_refcount._M_get_use_count() == 0; } template<typename _Tp1> @@ -1309,11 +1315,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return _M_refcount._M_less(__rhs._M_refcount); } void - reset() // never throws + reset() noexcept { __weak_ptr().swap(*this); } void - swap(__weak_ptr& __s) // never throws + swap(__weak_ptr& __s) noexcept { std::swap(_M_ptr, __s._M_ptr); _M_refcount._M_swap(__s._M_refcount); @@ -1322,7 +1328,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION private: // Used by __enable_shared_from_this. void - _M_assign(_Tp* __ptr, const __shared_count<_Lp>& __refcount) + _M_assign(_Tp* __ptr, const __shared_count<_Lp>& __refcount) noexcept { _M_ptr = __ptr; _M_refcount = __refcount; @@ -1340,7 +1346,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // 20.8.13.3.7 weak_ptr specialized algorithms. template<typename _Tp, _Lock_policy _Lp> inline void - swap(__weak_ptr<_Tp, _Lp>& __a, __weak_ptr<_Tp, _Lp>& __b) + swap(__weak_ptr<_Tp, _Lp>& __a, __weak_ptr<_Tp, _Lp>& __b) noexcept { __a.swap(__b); } template<typename _Tp, typename _Tp1> @@ -1374,12 +1380,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION class __enable_shared_from_this { protected: - constexpr __enable_shared_from_this() { } + constexpr __enable_shared_from_this() noexcept { } - __enable_shared_from_this(const __enable_shared_from_this&) { } + __enable_shared_from_this(const __enable_shared_from_this&) noexcept { } __enable_shared_from_this& - operator=(const __enable_shared_from_this&) + operator=(const __enable_shared_from_this&) noexcept { return *this; } ~__enable_shared_from_this() { } @@ -1396,14 +1402,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION private: template<typename _Tp1> void - _M_weak_assign(_Tp1* __p, const __shared_count<_Lp>& __n) const + _M_weak_assign(_Tp1* __p, const __shared_count<_Lp>& __n) const noexcept { _M_weak_this._M_assign(__p, __n); } template<typename _Tp1> friend void __enable_shared_from_this_helper(const __shared_count<_Lp>& __pn, const __enable_shared_from_this* __pe, - const _Tp1* __px) + const _Tp1* __px) noexcept { if (__pe != 0) __pe->_M_weak_assign(const_cast<_Tp1*>(__px), __pn); diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc index 36cf7f9..42354d4 100644 --- a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc @@ -32,9 +32,9 @@ void test01() { X* px = 0; std::shared_ptr<X> p1(px); // { dg-error "here" } - // { dg-error "incomplete" "" { target *-*-* } 766 } + // { dg-error "incomplete" "" { target *-*-* } 768 } std::shared_ptr<X> p9(ap()); // { dg-error "here" } - // { dg-error "incomplete" "" { target *-*-* } 858 } + // { dg-error "incomplete" "" { target *-*-* } 862 } } diff --git a/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc b/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc index 5564b26..8316d48 100644 --- a/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc +++ b/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc @@ -45,9 +45,9 @@ main() // { dg-warning "note" "" { target *-*-* } 370 } // { dg-warning "note" "" { target *-*-* } 365 } // { dg-warning "note" "" { target *-*-* } 357 } -// { dg-warning "note" "" { target *-*-* } 1099 } -// { dg-warning "note" "" { target *-*-* } 1094 } -// { dg-warning "note" "" { target *-*-* } 1086 } +// { dg-warning "note" "" { target *-*-* } 1103 } +// { dg-warning "note" "" { target *-*-* } 1098 } +// { dg-warning "note" "" { target *-*-* } 1090 } // { dg-warning "note" "" { target *-*-* } 485 } // { dg-warning "note" "" { target *-*-* } 479 } // { dg-warning "note" "" { target *-*-* } 469 } |