Index: include/memory =================================================================== --- include/memory +++ include/memory @@ -3606,11 +3606,16 @@ class __shared_ptr_pointer : public __shared_weak_count { - __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_; + _Tp __pointee; + _Dp __deleter; + _Alloc __alloc; + public: _LIBCPP_INLINE_VISIBILITY __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a) - : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {} + : __pointee(__p), + __deleter(_VSTD::move(__d)), + __alloc(_VSTD::move(__a)) {} #ifndef _LIBCPP_NO_RTTI virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; @@ -3627,7 +3632,7 @@ const void* __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT { - return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : nullptr; + return __t == typeid(_Dp) ? _VSTD::addressof(__deleter) : nullptr; } #endif // _LIBCPP_NO_RTTI @@ -3636,8 +3641,8 @@ void __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT { - __data_.first().second()(__data_.first().first()); - __data_.first().second().~_Dp(); + __deleter(__pointee); + __deleter.~_Dp(); } template @@ -3648,8 +3653,8 @@ typedef allocator_traits<_Al> _ATraits; typedef pointer_traits _PTraits; - _Al __a(__data_.second()); - __data_.second().~_Alloc(); + _Al __a(__alloc); + __alloc.~_Alloc(); __a.deallocate(_PTraits::pointer_to(*this), 1); } @@ -3657,56 +3662,32 @@ class __shared_ptr_emplace : public __shared_weak_count { - __compressed_pair<_Alloc, _Tp> __data_; -public: -#ifndef _LIBCPP_HAS_NO_VARIADICS + _Tp __pointee; + _Alloc __alloc; + + virtual void __on_zero_shared() _NOEXCEPT; + virtual void __on_zero_shared_weak() _NOEXCEPT; +public: _LIBCPP_INLINE_VISIBILITY __shared_ptr_emplace(_Alloc __a) - : __data_(_VSTD::move(__a)) {} + : __alloc(_VSTD::move(__a)) {} template _LIBCPP_INLINE_VISIBILITY __shared_ptr_emplace(_Alloc __a, _Args&& ...__args) - : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a), - _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {} - -#else // _LIBCPP_HAS_NO_VARIADICS - - _LIBCPP_INLINE_VISIBILITY - __shared_ptr_emplace(_Alloc __a) - : __data_(__a) {} - - template - _LIBCPP_INLINE_VISIBILITY - __shared_ptr_emplace(_Alloc __a, _A0& __a0) - : __data_(__a, _Tp(__a0)) {} - - template - _LIBCPP_INLINE_VISIBILITY - __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1) - : __data_(__a, _Tp(__a0, __a1)) {} - - template - _LIBCPP_INLINE_VISIBILITY - __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2) - : __data_(__a, _Tp(__a0, __a1, __a2)) {} + : __pointee(_Tp(_VSTD::forward<_Args>(__args)...)), + __alloc(_VSTD::move(__a)) {} -#endif // _LIBCPP_HAS_NO_VARIADICS - -private: - virtual void __on_zero_shared() _NOEXCEPT; - virtual void __on_zero_shared_weak() _NOEXCEPT; -public: _LIBCPP_INLINE_VISIBILITY - _Tp* get() _NOEXCEPT {return _VSTD::addressof(__data_.second());} + _Tp* get() _NOEXCEPT {return _VSTD::addressof(__pointee);} }; template void __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT { - __data_.second().~_Tp(); + __pointee.~_Tp(); } template @@ -3716,8 +3697,8 @@ typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al; typedef allocator_traits<_Al> _ATraits; typedef pointer_traits _PTraits; - _Al __a(__data_.first()); - __data_.first().~_Alloc(); + _Al __a(__alloc); + __alloc.~_Alloc(); __a.deallocate(_PTraits::pointer_to(*this), 1); } @@ -3738,18 +3719,18 @@ template class _LIBCPP_TEMPLATE_VIS shared_ptr { -public: - typedef _Tp element_type; - -#if _LIBCPP_STD_VER > 14 - typedef weak_ptr<_Tp> weak_type; -#endif private: - element_type* __ptr_; + _Tp* __ptr_; __shared_weak_count* __cntrl_; struct __nat {int __for_bool_;}; public: +#if _LIBCPP_STD_VER > 14 + typedef weak_ptr<_Tp> weak_type; +#endif + + typedef _Tp element_type; + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY @@ -3793,45 +3774,24 @@ typename enable_if::value, __nat>::type = __nat()); #endif #endif -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - template - shared_ptr(unique_ptr<_Yp, _Dp>&&, - typename enable_if - < - !is_lvalue_reference<_Dp>::value && - !is_array<_Yp>::value && - is_convertible::pointer, element_type*>::value, - __nat - >::type = __nat()); template - shared_ptr(unique_ptr<_Yp, _Dp>&&, - typename enable_if - < - is_lvalue_reference<_Dp>::value && - !is_array<_Yp>::value && - is_convertible::pointer, element_type*>::value, - __nat - >::type = __nat()); -#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES - template - shared_ptr(unique_ptr<_Yp, _Dp>, - typename enable_if - < - !is_lvalue_reference<_Dp>::value && - !is_array<_Yp>::value && - is_convertible::pointer, element_type*>::value, - __nat - >::type = __nat()); + shared_ptr(unique_ptr<_Yp, _Dp>&& __r, + typename enable_if + < + !is_array<_Yp>::value && + is_convertible::pointer, + element_type*>::value, + __nat + >::type = __nat()); template - shared_ptr(unique_ptr<_Yp, _Dp>, - typename enable_if - < - is_lvalue_reference<_Dp>::value && - !is_array<_Yp>::value && - is_convertible::pointer, element_type*>::value, - __nat - >::type = __nat()); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + shared_ptr(unique_ptr<_Yp, _Dp&>&& __r, + typename enable_if + < + !is_array<_Yp>::value && + is_convertible::pointer, + element_type*>::value, + __nat + >::type = __nat()); ~shared_ptr(); @@ -3959,8 +3919,6 @@ : nullptr);} #endif // _LIBCPP_NO_RTTI -#ifndef _LIBCPP_HAS_NO_VARIADICS - template static shared_ptr<_Tp> @@ -3971,37 +3929,6 @@ shared_ptr<_Tp> allocate_shared(const _Alloc& __a, _Args&& ...__args); -#else // _LIBCPP_HAS_NO_VARIADICS - - static shared_ptr<_Tp> make_shared(); - - template - static shared_ptr<_Tp> make_shared(_A0&); - - template - static shared_ptr<_Tp> make_shared(_A0&, _A1&); - - template - static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&); - - template - static shared_ptr<_Tp> - allocate_shared(const _Alloc& __a); - - template - static shared_ptr<_Tp> - allocate_shared(const _Alloc& __a, _A0& __a0); - - template - static shared_ptr<_Tp> - allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1); - - template - static shared_ptr<_Tp> - allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2); - -#endif // _LIBCPP_HAS_NO_VARIADICS - private: template ::value> struct __shared_ptr_default_allocator @@ -4036,6 +3963,52 @@ template friend class _LIBCPP_TEMPLATE_VIS shared_ptr; template friend class _LIBCPP_TEMPLATE_VIS weak_ptr; + + template, + class _Alloc = typename __shared_ptr_default_allocator<_Yp>::type> + static __shared_weak_count* + __allocate_shared(_Yp* __p, _Deleter __d = _Deleter {}, _Alloc __a = _Alloc {}) + { + try { + typedef __shared_ptr_pointer<_Yp*, _Deleter, _Alloc> _CT; + typedef typename __allocator_traits_rebind<_Alloc, _CT>::type _A2; + typedef __allocator_destructor<_A2> _D2; + + _A2 __a2(__a); + unique_ptr<_CT, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); + + ::new(static_cast(_VSTD::addressof(*__hold2.get()))) + _CT(__p, __d, __a); + + return _VSTD::addressof(*__hold2.release()); + } catch (...) { + __d(__p); + throw; + } + } + + template, + class _Alloc = typename __shared_ptr_default_allocator<_Tp>::type> + static __shared_weak_count* + __allocate_shared(nullptr_t __p, _Deleter __d = _Deleter {}, _Alloc __a = _Alloc {}) + { + try { + typedef __shared_ptr_pointer<_Tp*, _Deleter, _Alloc> _CT; + typedef typename __allocator_traits_rebind<_Alloc, _CT>::type _A2; + typedef __allocator_destructor<_A2> _D2; + + _A2 __a2(__a); + unique_ptr<_CT, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); + + ::new(static_cast(_VSTD::addressof(*__hold2.get()))) + _CT(__p, __d, __a); + + return _VSTD::addressof(*__hold2.release()); + } catch (...) { + __d(__p); + throw; + } + } }; @@ -4044,30 +4017,22 @@ _LIBCPP_CONSTEXPR shared_ptr<_Tp>::shared_ptr() _NOEXCEPT : __ptr_(0), - __cntrl_(0) -{ -} + __cntrl_(0) {} template inline _LIBCPP_CONSTEXPR shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT : __ptr_(0), - __cntrl_(0) -{ -} + __cntrl_(0) {} template template shared_ptr<_Tp>::shared_ptr(_Yp* __p, typename enable_if::value, __nat>::type) - : __ptr_(__p) + : __ptr_(__p), + __cntrl_(__allocate_shared(__p)) { - unique_ptr<_Yp> __hold(__p); - typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; - typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, _AllocT > _CntrlBlk; - __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), _AllocT()); - __hold.release(); __enable_weak_this(__p, __p); } @@ -4075,103 +4040,33 @@ template shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, typename enable_if::value, __nat>::type) - : __ptr_(__p) + : __ptr_(__p), + __cntrl_(__allocate_shared(__p, __d)) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; - typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk; - __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); - __enable_weak_this(__p, __p); -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - __d(__p); - throw; - } -#endif // _LIBCPP_NO_EXCEPTIONS + __enable_weak_this(__p, __p); } template template shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d) - : __ptr_(0) -{ -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT; - typedef __shared_ptr_pointer _CntrlBlk; - __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - __d(__p); - throw; - } -#endif // _LIBCPP_NO_EXCEPTIONS -} + : __ptr_(0), + __cntrl_(__allocate_shared(__p, __d)) {} template template shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, typename enable_if::value, __nat>::type) - : __ptr_(__p) + : __ptr_(__p), + __cntrl_(__allocate_shared(__p, __d, __a)) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk; - 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(static_cast(_VSTD::addressof(*__hold2.get()))) - _CntrlBlk(__p, __d, __a); - __cntrl_ = _VSTD::addressof(*__hold2.release()); - __enable_weak_this(__p, __p); -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - __d(__p); - throw; - } -#endif // _LIBCPP_NO_EXCEPTIONS + __enable_weak_this(__p, __p); } template template shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a) - : __ptr_(0) -{ -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - typedef __shared_ptr_pointer _CntrlBlk; - 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(static_cast(_VSTD::addressof(*__hold2.get()))) - _CntrlBlk(__p, __d, __a); - __cntrl_ = _VSTD::addressof(*__hold2.release()); -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - __d(__p); - throw; - } -#endif // _LIBCPP_NO_EXCEPTIONS -} + : __ptr_(0), + __cntrl_(__allocate_shared(__p, __d, __a)) {} template template @@ -4254,16 +4149,12 @@ template template -#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 && !is_array<_Yp>::value && - is_convertible::pointer, element_type*>::value, + is_convertible::pointer, + element_type*>::value, __nat >::type) : __ptr_(__r.get()) @@ -4275,8 +4166,10 @@ #endif { typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; - typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk; - __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT()); + typedef __shared_ptr_pointer<_Yp*, + reference_wrapper::type>, + _AllocT > _CntrlBlk; + __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), _AllocT()); __enable_weak_this(__r.get(), __r.get()); } __r.release(); @@ -4284,16 +4177,12 @@ template template -#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 +shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp&>&& __r, typename enable_if < - is_lvalue_reference<_Dp>::value && !is_array<_Yp>::value && - is_convertible::pointer, element_type*>::value, + is_convertible::pointer, + element_type*>::value, __nat >::type) : __ptr_(__r.get()) @@ -4305,17 +4194,13 @@ #endif { typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; - typedef __shared_ptr_pointer<_Yp*, - reference_wrapper::type>, - _AllocT > _CntrlBlk; - __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), _AllocT()); + typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk; + __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT()); __enable_weak_this(__r.get(), __r.get()); } __r.release(); } -#ifndef _LIBCPP_HAS_NO_VARIADICS - template template shared_ptr<_Tp> @@ -4325,9 +4210,11 @@ typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; typedef allocator<_CntrlBlk> _A2; typedef __allocator_destructor<_A2> _D2; + _A2 __a2; unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...); + shared_ptr<_Tp> __r; __r.__ptr_ = __hold2.get()->get(); __r.__cntrl_ = __hold2.release(); @@ -4340,111 +4227,17 @@ shared_ptr<_Tp> shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args) { - static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared" ); + static_assert(is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared"); + typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; 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(static_cast(_VSTD::addressof(*__hold2.get()))) _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...); - shared_ptr<_Tp> __r; - __r.__ptr_ = __hold2.get()->get(); - __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); - __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); - return __r; -} - -#else // _LIBCPP_HAS_NO_VARIADICS - -template -shared_ptr<_Tp> -shared_ptr<_Tp>::make_shared() -{ - static_assert((is_constructible<_Tp>::value), "Can't construct object in make_shared" ); - typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; - typedef allocator<_CntrlBlk> _Alloc2; - typedef __allocator_destructor<_Alloc2> _D2; - _Alloc2 __alloc2; - unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); - ::new(__hold2.get()) _CntrlBlk(__alloc2); - shared_ptr<_Tp> __r; - __r.__ptr_ = __hold2.get()->get(); - __r.__cntrl_ = __hold2.release(); - __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); - return __r; -} - -template -template -shared_ptr<_Tp> -shared_ptr<_Tp>::make_shared(_A0& __a0) -{ - static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in make_shared" ); - typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; - typedef allocator<_CntrlBlk> _Alloc2; - typedef __allocator_destructor<_Alloc2> _D2; - _Alloc2 __alloc2; - unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); - ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0); - shared_ptr<_Tp> __r; - __r.__ptr_ = __hold2.get()->get(); - __r.__cntrl_ = __hold2.release(); - __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); - return __r; -} - -template -template -shared_ptr<_Tp> -shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1) -{ - static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in make_shared" ); - typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; - typedef allocator<_CntrlBlk> _Alloc2; - typedef __allocator_destructor<_Alloc2> _D2; - _Alloc2 __alloc2; - unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); - ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1); - shared_ptr<_Tp> __r; - __r.__ptr_ = __hold2.get()->get(); - __r.__cntrl_ = __hold2.release(); - __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); - return __r; -} - -template -template -shared_ptr<_Tp> -shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2) -{ - static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in make_shared" ); - typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; - typedef allocator<_CntrlBlk> _Alloc2; - typedef __allocator_destructor<_Alloc2> _D2; - _Alloc2 __alloc2; - unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); - ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2); - shared_ptr<_Tp> __r; - __r.__ptr_ = __hold2.get()->get(); - __r.__cntrl_ = __hold2.release(); - __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); - return __r; -} -template -template -shared_ptr<_Tp> -shared_ptr<_Tp>::allocate_shared(const _Alloc& __a) -{ - static_assert((is_constructible<_Tp>::value), "Can't construct object in allocate_shared" ); - typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; - 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(static_cast(_VSTD::addressof(*__hold2.get()))) - _CntrlBlk(__a); shared_ptr<_Tp> __r; __r.__ptr_ = __hold2.get()->get(); __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); @@ -4452,68 +4245,6 @@ return __r; } -template -template -shared_ptr<_Tp> -shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0) -{ - static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in allocate_shared" ); - typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; - 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(static_cast(_VSTD::addressof(*__hold2.get()))) - _CntrlBlk(__a, __a0); - shared_ptr<_Tp> __r; - __r.__ptr_ = __hold2.get()->get(); - __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); - __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); - return __r; -} - -template -template -shared_ptr<_Tp> -shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1) -{ - static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in allocate_shared" ); - typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; - 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(static_cast(_VSTD::addressof(*__hold2.get()))) - _CntrlBlk(__a, __a0, __a1); - shared_ptr<_Tp> __r; - __r.__ptr_ = __hold2.get()->get(); - __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); - __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); - return __r; -} - -template -template -shared_ptr<_Tp> -shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2) -{ - static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in allocate_shared" ); - typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; - 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(static_cast(_VSTD::addressof(*__hold2.get()))) - _CntrlBlk(__a, __a0, __a1, __a2); - shared_ptr<_Tp> __r; - __r.__ptr_ = __hold2.get()->get(); - __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); - __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); - return __r; -} - -#endif // _LIBCPP_HAS_NO_VARIADICS - template shared_ptr<_Tp>::~shared_ptr() { Index: test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.fail.cpp =================================================================== --- test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.fail.cpp +++ test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.fail.cpp @@ -24,6 +24,7 @@ int main(int, char**) { + // expected-error@memory:* {{field of type 'S' has protected default constructor}} std::shared_ptr p = std::make_shared(); // expected-error-re@memory:* {{static_assert failed{{.*}} "Can't construct object in make_shared"}} return 0;