diff --git a/libcxx/include/memory b/libcxx/include/memory --- a/libcxx/include/memory +++ b/libcxx/include/memory @@ -4036,28 +4036,6 @@ shared_ptr(__p, __d, __a).swap(*this); } -template -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - !is_array<_Tp>::value, - shared_ptr<_Tp> ->::type -make_shared(_Args&& ...__args) -{ - static_assert(is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared"); - 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)...); - - _Tp *__ptr = __hold2->__get_elem(); - return shared_ptr<_Tp>::__create_with_control_block(__ptr, __hold2.release()); -} - template inline _LIBCPP_INLINE_VISIBILITY typename enable_if @@ -4067,7 +4045,8 @@ >::type 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, + "allocate_shared/make_shared: the type is not constructible from the provided arguments"); typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; @@ -4082,6 +4061,13 @@ return shared_ptr<_Tp>::__create_with_control_block(__p, _VSTD::addressof(*__hold2.release())); } +template::value> > +_LIBCPP_HIDE_FROM_ABI +shared_ptr<_Tp> make_shared(_Args&& ...__args) +{ + return _VSTD::allocate_shared<_Tp>(allocator<_Tp>(), _VSTD::forward<_Args>(__args)...); +} + template inline _LIBCPP_INLINE_VISIBILITY bool diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.fail.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.protected.verify.cpp rename from libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.fail.cpp rename to libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.protected.verify.cpp --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.fail.cpp +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.protected.verify.cpp @@ -13,10 +13,10 @@ // shared_ptr -// template shared_ptr make_shared(Args&&... args); +// template +// shared_ptr allocate_shared(const A& a, Args&&... args); #include -#include #include "test_macros.h" @@ -25,10 +25,10 @@ S () {}; // ctor is protected }; -int main(int, char**) -{ - std::shared_ptr p = std::make_shared< - S>(); // expected-error@memory:* {{static_assert failed due to requirement 'is_constructible::value' "Can't construct object in make_shared"}} +int main(int, char**) { + typedef std::allocator A; + A a; + std::shared_ptr p = std::allocate_shared(a); // expected-error@memory:* {{static_assert failed due to requirement 'is_constructible::value}} - return 0; + return 0; } diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.fail.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.verify.cpp rename from libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.fail.cpp rename to libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.verify.cpp --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.fail.cpp +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.verify.cpp @@ -16,7 +16,6 @@ // template shared_ptr make_shared(Args&&... args); #include -#include #include "test_macros.h" @@ -25,10 +24,8 @@ S () {}; // ctor is protected }; -int main(int, char**) -{ - std::shared_ptr p = std::make_shared< - S>(); // expected-error@memory:* {{static_assert failed due to requirement 'is_constructible::value' "Can't construct object in make_shared"}} +int main(int, char**) { + std::shared_ptr p = std::make_shared(); // expected-error@memory:* {{static_assert failed due to requirement 'is_constructible::value}} return 0; }