diff options
Diffstat (limited to 'include/memory')
-rw-r--r-- | include/memory | 314 |
1 files changed, 164 insertions, 150 deletions
diff --git a/include/memory b/include/memory index b382f70..662faa0 100644 --- a/include/memory +++ b/include/memory @@ -479,6 +479,8 @@ public: template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept; weak_ptr(weak_ptr const& r) noexcept; template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept; + weak_ptr(weak_ptr&& r) noexcept; // C++14 + template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14 // destructor ~weak_ptr(); @@ -487,6 +489,8 @@ public: weak_ptr& operator=(weak_ptr const& r) noexcept; template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept; template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept; + weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14 + template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14 // modifiers void swap(weak_ptr& r) noexcept; @@ -606,7 +610,7 @@ void* align(size_t alignment, size_t size, void*& ptr, size_t& space); #include <cassert> #endif -#if __has_feature(cxx_atomic) +#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS) # include <atomic> #endif @@ -1446,7 +1450,7 @@ struct _LIBCPP_TYPE_VIS_ONLY allocator_traits template <class _Tp, class... _Args> _LIBCPP_INLINE_VISIBILITY static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args) - {__construct(__has_construct<allocator_type, pointer, _Args...>(), + {__construct(__has_construct<allocator_type, _Tp*, _Args...>(), __a, __p, _VSTD::forward<_Args>(__args)...);} #else // _LIBCPP_HAS_NO_VARIADICS template <class _Tp> @@ -1627,9 +1631,9 @@ public: _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT {return _VSTD::addressof(__x);} _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0) - {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));} + {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));} _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT - {::operator delete((void*)__p);} + {_VSTD::__deallocate((void*)__p);} _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT {return size_type(~0) / sizeof(_Tp);} #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) @@ -1717,9 +1721,9 @@ public: _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT {return _VSTD::addressof(__x);} _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0) - {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));} + {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));} _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT - {::operator delete((void*)__p);} + {_VSTD::__deallocate((void*)__p);} _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT {return size_type(~0) / sizeof(_Tp);} #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) @@ -2001,8 +2005,8 @@ public: tuple<_Args2...> __second_args, __tuple_indices<_I1...>, __tuple_indices<_I2...>) - : __first_(_VSTD::forward<_Args1>(get<_I1>(__first_args))...), - __second_(_VSTD::forward<_Args2>(get<_I2>(__second_args))...) + : __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...), + __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...) {} #endif // _LIBCPP_HAS_NO_VARIADICS @@ -2015,7 +2019,7 @@ public: _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x) _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && - __is_nothrow_swappable<_T1>::value) + __is_nothrow_swappable<_T2>::value) { using _VSTD::swap; swap(__first_, __x.__first_); @@ -2092,8 +2096,8 @@ public: tuple<_Args2...> __second_args, __tuple_indices<_I1...>, __tuple_indices<_I2...>) - : _T1(_VSTD::forward<_Args1>(get<_I1>(__first_args))...), - __second_(_VSTD::forward<_Args2>(get<_I2>(__second_args))...) + : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...), + __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...) {} #endif // _LIBCPP_HAS_NO_VARIADICS @@ -2106,7 +2110,7 @@ public: _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x) _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && - __is_nothrow_swappable<_T1>::value) + __is_nothrow_swappable<_T2>::value) { using _VSTD::swap; swap(__second_, __x.__second_); @@ -2184,8 +2188,8 @@ public: tuple<_Args2...> __second_args, __tuple_indices<_I1...>, __tuple_indices<_I2...>) - : _T2(_VSTD::forward<_Args2>(get<_I2>(__second_args))...), - __first_(_VSTD::forward<_Args1>(get<_I1>(__first_args))...) + : _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...), + __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...) {} @@ -2199,7 +2203,7 @@ public: _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x) _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && - __is_nothrow_swappable<_T1>::value) + __is_nothrow_swappable<_T2>::value) { using _VSTD::swap; swap(__first_, __x.__first_); @@ -2274,8 +2278,8 @@ public: tuple<_Args2...> __second_args, __tuple_indices<_I1...>, __tuple_indices<_I2...>) - : _T1(_VSTD::forward<_Args1>(get<_I1>(__first_args))...), - _T2(_VSTD::forward<_Args2>(get<_I2>(__second_args))...) + : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...), + _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...) {} #endif // _LIBCPP_HAS_NO_VARIADICS @@ -2288,7 +2292,7 @@ public: _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&) _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && - __is_nothrow_swappable<_T1>::value) + __is_nothrow_swappable<_T2>::value) { } }; @@ -2371,7 +2375,7 @@ public: _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x) _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && - __is_nothrow_swappable<_T1>::value) + __is_nothrow_swappable<_T2>::value) {base::swap(__x);} }; @@ -2380,7 +2384,7 @@ inline _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y) _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && - __is_nothrow_swappable<_T1>::value) + __is_nothrow_swappable<_T2>::value) {__x.swap(__y);} // __same_or_less_cv_qualified @@ -2397,13 +2401,14 @@ template <class _Ptr1, class _Ptr2> struct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false> : false_type {}; -template <class _Ptr1, class _Ptr2, bool = is_scalar<_Ptr1>::value && - !is_pointer<_Ptr1>::value> +template <class _Ptr1, class _Ptr2, bool = is_pointer<_Ptr1>::value || + is_same<_Ptr1, _Ptr2>::value || + __has_element_type<_Ptr1>::value> struct __same_or_less_cv_qualified : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {}; template <class _Ptr1, class _Ptr2> -struct __same_or_less_cv_qualified<_Ptr1, _Ptr2, true> +struct __same_or_less_cv_qualified<_Ptr1, _Ptr2, false> : false_type {}; // default_delete @@ -2666,23 +2671,21 @@ public: "unique_ptr constructed with null function pointer deleter"); } #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _Pp, - class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type - > - _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p) _NOEXCEPT + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p, + typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) _NOEXCEPT : __ptr_(__p) { static_assert(!is_pointer<deleter_type>::value, "unique_ptr constructed with null function pointer deleter"); } - template <class _Pp, - class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type - > + template <class _Pp> _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional< is_reference<deleter_type>::value, deleter_type, - typename add_lvalue_reference<const deleter_type>::type>::type __d) + typename add_lvalue_reference<const deleter_type>::type>::type __d, + typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) _NOEXCEPT : __ptr_(__p, __d) {} @@ -2693,10 +2696,10 @@ public: _NOEXCEPT : __ptr_(pointer(), __d) {} - template <class _Pp, - class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type - > - _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename remove_reference<deleter_type>::type&& __d) + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, + typename remove_reference<deleter_type>::type&& __d, + typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) _NOEXCEPT : __ptr_(__p, _VSTD::move(__d)) { @@ -2811,10 +2814,10 @@ public: } #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _Pp, - class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type - > - _LIBCPP_INLINE_VISIBILITY void reset(_Pp __p) _NOEXCEPT + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, void>::type + reset(_Pp __p) _NOEXCEPT { pointer __tmp = __ptr_.first(); __ptr_.first() = __p; @@ -3657,7 +3660,7 @@ template <class _Tp, class _Dp, class _Alloc> const void* __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT { - return __t == typeid(_Dp) ? &__data_.first().second() : 0; + return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : 0; } #endif // _LIBCPP_NO_RTTI @@ -3674,9 +3677,13 @@ template <class _Tp, class _Dp, class _Alloc> void __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT { - typename _Alloc::template rebind<__shared_ptr_pointer>::other __a(__data_.second()); + typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _A; + typedef allocator_traits<_A> _ATraits; + typedef pointer_traits<typename _ATraits::pointer> _PTraits; + + _A __a(__data_.second()); __data_.second().~_Alloc(); - __a.deallocate(this, 1); + __a.deallocate(_PTraits::pointer_to(*this), 1); } template <class _Tp, class _Alloc> @@ -3739,9 +3746,12 @@ template <class _Tp, class _Alloc> void __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT { - typename _Alloc::template rebind<__shared_ptr_emplace>::other __a(__data_.first()); + typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _A; + typedef allocator_traits<_A> _ATraits; + typedef pointer_traits<typename _ATraits::pointer> _PTraits; + _A __a(__data_.first()); __data_.first().~_Alloc(); - __a.deallocate(this, 1); + __a.deallocate(_PTraits::pointer_to(*this), 1); } template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this; @@ -3759,27 +3769,15 @@ private: public: _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT; _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT; - template<class _Yp, - class = typename enable_if - < - is_convertible<_Yp*, element_type*>::value - >::type - > - explicit shared_ptr(_Yp* __p); - template<class _Yp, class _Dp, - class = typename enable_if - < - is_convertible<_Yp*, element_type*>::value - >::type - > - shared_ptr(_Yp* __p, _Dp __d); - template<class _Yp, class _Dp, class _Alloc, - class = typename enable_if - < - is_convertible<_Yp*, element_type*>::value - >::type - > - shared_ptr(_Yp* __p, _Dp __d, _Alloc __a); + template<class _Yp> + explicit shared_ptr(_Yp* __p, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); + template<class _Yp, class _Dp> + shared_ptr(_Yp* __p, _Dp __d, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); + template<class _Yp, class _Dp, class _Alloc> + shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d); template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a); template<class _Yp> shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT; @@ -3797,59 +3795,52 @@ public: template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r, typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat()); #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - template<class _Yp, - class = typename enable_if - < - is_convertible<_Yp*, element_type*>::value - >::type - > - shared_ptr(auto_ptr<_Yp>&& __r); + template<class _Yp> + shared_ptr(auto_ptr<_Yp>&& __r, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); #else - template<class _Yp, - class = typename enable_if - < - is_convertible<_Yp*, element_type*>::value - >::type - > - shared_ptr(auto_ptr<_Yp> __r); + template<class _Yp> + shared_ptr(auto_ptr<_Yp> __r, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); #endif #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _Yp, class _Dp, - class = typename enable_if - < - !is_array<_Yp>::value && - is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value - >::type - > - shared_ptr(unique_ptr<_Yp, _Dp>&&, - typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat()); - template <class _Yp, class _Dp, - class = typename enable_if - < - !is_array<_Yp>::value && - is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value - >::type - > - shared_ptr(unique_ptr<_Yp, _Dp>&&, - typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat()); + template <class _Yp, class _Dp> + shared_ptr(unique_ptr<_Yp, _Dp>&&, + typename enable_if + < + !is_lvalue_reference<_Dp>::value && + !is_array<_Yp>::value && + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, + __nat + >::type = __nat()); + template <class _Yp, class _Dp> + shared_ptr(unique_ptr<_Yp, _Dp>&&, + typename enable_if + < + is_lvalue_reference<_Dp>::value && + !is_array<_Yp>::value && + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, + __nat + >::type = __nat()); #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _Yp, class _Dp, - class = typename enable_if - < - !is_array<_Yp>::value && - is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value - >::type - > shared_ptr(unique_ptr<_Yp, _Dp>, - typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat()); - template <class _Yp, class _Dp, - class = typename enable_if - < - !is_array<_Yp>::value && - is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value - >::type - > - shared_ptr(unique_ptr<_Yp, _Dp>, - typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat()); + template <class _Yp, class _Dp> + shared_ptr(unique_ptr<_Yp, _Dp>, + typename enable_if + < + !is_lvalue_reference<_Dp>::value && + !is_array<_Yp>::value && + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, + __nat + >::type = __nat()); + template <class _Yp, class _Dp> + shared_ptr(unique_ptr<_Yp, _Dp>, + typename enable_if + < + is_lvalue_reference<_Dp>::value && + !is_array<_Yp>::value && + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, + __nat + >::type = __nat()); #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES ~shared_ptr(); @@ -4039,8 +4030,9 @@ shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT } template<class _Tp> -template<class _Yp, class> -shared_ptr<_Tp>::shared_ptr(_Yp* __p) +template<class _Yp> +shared_ptr<_Tp>::shared_ptr(_Yp* __p, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) : __ptr_(__p) { unique_ptr<_Yp> __hold(__p); @@ -4051,8 +4043,9 @@ shared_ptr<_Tp>::shared_ptr(_Yp* __p) } template<class _Tp> -template<class _Yp, class _Dp, class> -shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d) +template<class _Yp, class _Dp> +shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) : __ptr_(__p) { #ifndef _LIBCPP_NO_EXCEPTIONS @@ -4094,8 +4087,9 @@ shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d) } template<class _Tp> -template<class _Yp, class _Dp, class _Alloc, class> -shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a) +template<class _Yp, class _Dp, class _Alloc> +shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) : __ptr_(__p) { #ifndef _LIBCPP_NO_EXCEPTIONS @@ -4103,12 +4097,13 @@ shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a) { #endif // _LIBCPP_NO_EXCEPTIONS typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk; - typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2; + typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; typedef __allocator_destructor<_A2> _D2; _A2 __a2(__a); unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); - ::new(__hold2.get()) _CntrlBlk(__p, __d, __a); - __cntrl_ = __hold2.release(); + ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) + _CntrlBlk(__p, __d, __a); + __cntrl_ = _VSTD::addressof(*__hold2.release()); __enable_weak_this(__p); #ifndef _LIBCPP_NO_EXCEPTIONS } @@ -4130,12 +4125,13 @@ shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a) { #endif // _LIBCPP_NO_EXCEPTIONS typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk; - typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2; + typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; typedef __allocator_destructor<_A2> _D2; _A2 __a2(__a); unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); - ::new(__hold2.get()) _CntrlBlk(__p, __d, __a); - __cntrl_ = __hold2.release(); + ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) + _CntrlBlk(__p, __d, __a); + __cntrl_ = _VSTD::addressof(*__hold2.release()); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) @@ -4208,12 +4204,13 @@ shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r, #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES template<class _Tp> -template<class _Yp, class> +template<class _Yp> #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES -shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r) +shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r, #else -shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r) +shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r, #endif + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) : __ptr_(__r.get()) { typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk; @@ -4223,13 +4220,19 @@ shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r) } template<class _Tp> -template <class _Yp, class _Dp, class> +template <class _Yp, class _Dp> #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, #else shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, #endif - typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type) + typename enable_if + < + !is_lvalue_reference<_Dp>::value && + !is_array<_Yp>::value && + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, + __nat + >::type) : __ptr_(__r.get()) { typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk; @@ -4239,13 +4242,19 @@ shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, } template<class _Tp> -template <class _Yp, class _Dp, class> +template <class _Yp, class _Dp> #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, #else shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, #endif - typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type) + typename enable_if + < + is_lvalue_reference<_Dp>::value && + !is_array<_Yp>::value && + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, + __nat + >::type) : __ptr_(__r.get()) { typedef __shared_ptr_pointer<_Yp*, @@ -4282,14 +4291,15 @@ shared_ptr<_Tp> shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args) { typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; - typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2; + typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; typedef __allocator_destructor<_A2> _D2; _A2 __a2(__a); unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); - ::new(__hold2.get()) _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...); + ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) + _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...); shared_ptr<_Tp> __r; __r.__ptr_ = __hold2.get()->get(); - __r.__cntrl_ = __hold2.release(); + __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); __r.__enable_weak_this(__r.__ptr_); return __r; } @@ -4373,14 +4383,15 @@ shared_ptr<_Tp> shared_ptr<_Tp>::allocate_shared(const _Alloc& __a) { typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; - typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2; + typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; typedef __allocator_destructor<_Alloc2> _D2; _Alloc2 __alloc2(__a); unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); - ::new(__hold2.get()) _CntrlBlk(__a); + ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) + _CntrlBlk(__a); shared_ptr<_Tp> __r; __r.__ptr_ = __hold2.get()->get(); - __r.__cntrl_ = __hold2.release(); + __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); __r.__enable_weak_this(__r.__ptr_); return __r; } @@ -4391,14 +4402,15 @@ shared_ptr<_Tp> shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0) { typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; - typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2; + typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; typedef __allocator_destructor<_Alloc2> _D2; _Alloc2 __alloc2(__a); unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); - ::new(__hold2.get()) _CntrlBlk(__a, __a0); + ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) + _CntrlBlk(__a, __a0); shared_ptr<_Tp> __r; __r.__ptr_ = __hold2.get()->get(); - __r.__cntrl_ = __hold2.release(); + __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); __r.__enable_weak_this(__r.__ptr_); return __r; } @@ -4409,14 +4421,15 @@ shared_ptr<_Tp> shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1) { typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; - typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2; + typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; typedef __allocator_destructor<_Alloc2> _D2; _Alloc2 __alloc2(__a); unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); - ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1); + ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) + _CntrlBlk(__a, __a0, __a1); shared_ptr<_Tp> __r; __r.__ptr_ = __hold2.get()->get(); - __r.__cntrl_ = __hold2.release(); + __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); __r.__enable_weak_this(__r.__ptr_); return __r; } @@ -4427,14 +4440,15 @@ shared_ptr<_Tp> shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2) { typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; - typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2; + typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; typedef __allocator_destructor<_Alloc2> _D2; _Alloc2 __alloc2(__a); unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); - ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1, __a2); + ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) + _CntrlBlk(__a, __a0, __a1, __a2); shared_ptr<_Tp> __r; __r.__ptr_ = __hold2.get()->get(); - __r.__cntrl_ = __hold2.release(); + __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); __r.__enable_weak_this(__r.__ptr_); return __r; } @@ -5262,7 +5276,7 @@ inline _LIBCPP_INLINE_VISIBILITY basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p); -#if __has_feature(cxx_atomic) +#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS) class _LIBCPP_TYPE_VIS __sp_mut { @@ -5388,7 +5402,7 @@ atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v return atomic_compare_exchange_weak(__p, __v, __w); } -#endif // __has_feature(cxx_atomic) +#endif // __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS) //enum class struct _LIBCPP_TYPE_VIS pointer_safety |