Skip to content

Commit 40c4768

Browse files
committed
[libcxx] Remove shared_ptr::make_shared
Summary: This patch removes `shared_ptr::make_shared` as it is not part of the standard. This patch also adds __create_with_cntrl_block, which is a help function that can be used in std::allocate_shared and std::make_shared. This is the third patch (out of 4) from D66178. Reviewers: EricWF, mclow.lists, ldionne Subscribers: christof, dexonsmith, libcxx-commits Tags: #libc Differential Revision: https://reviews.llvm.org/D68805 llvm-svn: 375504
1 parent 3ef017d commit 40c4768

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

libcxx/include/memory

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3871,10 +3871,16 @@ public:
38713871
: nullptr);}
38723872
#endif // _LIBCPP_NO_RTTI
38733873

3874-
template<class ..._Args>
3875-
static
3876-
shared_ptr<_Tp>
3877-
make_shared(_Args&& ...__args);
3874+
template<class _Yp, class _CntrlBlk>
3875+
static shared_ptr<_Tp>
3876+
__create_with_control_block(_Yp* __p, _CntrlBlk* __cntrl)
3877+
{
3878+
shared_ptr<_Tp> __r;
3879+
__r.__ptr_ = __p;
3880+
__r.__cntrl_ = __cntrl;
3881+
__r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
3882+
return __r;
3883+
}
38783884

38793885
template<class _Alloc, class ..._Args>
38803886
static
@@ -4193,25 +4199,6 @@ shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
41934199
__r.release();
41944200
}
41954201

4196-
template<class _Tp>
4197-
template<class ..._Args>
4198-
shared_ptr<_Tp>
4199-
shared_ptr<_Tp>::make_shared(_Args&& ...__args)
4200-
{
4201-
static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared" );
4202-
typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4203-
typedef allocator<_CntrlBlk> _A2;
4204-
typedef __allocator_destructor<_A2> _D2;
4205-
_A2 __a2;
4206-
unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4207-
::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
4208-
shared_ptr<_Tp> __r;
4209-
__r.__ptr_ = __hold2.get()->get();
4210-
__r.__cntrl_ = __hold2.release();
4211-
__r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4212-
return __r;
4213-
}
4214-
42154202
template<class _Tp>
42164203
template<class _Alloc, class ..._Args>
42174204
shared_ptr<_Tp>
@@ -4422,7 +4409,17 @@ typename enable_if
44224409
>::type
44234410
make_shared(_Args&& ...__args)
44244411
{
4425-
return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
4412+
static_assert(is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared");
4413+
typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4414+
typedef allocator<_CntrlBlk> _A2;
4415+
typedef __allocator_destructor<_A2> _D2;
4416+
4417+
_A2 __a2;
4418+
unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4419+
::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
4420+
4421+
_Tp *__ptr = __hold2.get()->get();
4422+
return shared_ptr<_Tp>::__create_with_control_block(__ptr, __hold2.release());
44264423
}
44274424

44284425
template<class _Tp, class _Alloc, class ..._Args>

0 commit comments

Comments
 (0)