From 7700912976a5948d31a0e34fe9f8c1059afabcac Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Tue, 5 Dec 2017 04:09:49 +0000 Subject: [PATCH] Land D28253 which fixes PR28929 (which we mistakenly marked as fixed before) llvm-svn: 319736 --- libcxx/include/memory | 10 +++++++ .../make_shared.private.fail.cpp | 29 +++++++++++++++++++ .../make_shared.protected.fail.cpp | 29 +++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.private.fail.cpp create mode 100644 libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.fail.cpp diff --git a/libcxx/include/memory b/libcxx/include/memory index 5c109df1cafe..7531011236f0 100644 --- a/libcxx/include/memory +++ b/libcxx/include/memory @@ -4265,6 +4265,7 @@ template shared_ptr<_Tp> shared_ptr<_Tp>::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; @@ -4283,6 +4284,7 @@ template 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" ); typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; typedef __allocator_destructor<_A2> _D2; @@ -4303,6 +4305,7 @@ 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; @@ -4321,6 +4324,7 @@ 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; @@ -4339,6 +4343,7 @@ 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; @@ -4357,6 +4362,7 @@ 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; @@ -4375,6 +4381,7 @@ 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; @@ -4394,6 +4401,7 @@ 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; @@ -4413,6 +4421,7 @@ 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; @@ -4432,6 +4441,7 @@ 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; diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.private.fail.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.private.fail.cpp new file mode 100644 index 000000000000..7f304054bda0 --- /dev/null +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.private.fail.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// shared_ptr + +// template shared_ptr make_shared(Args&&... args); + +#include +#include + +#include "test_macros.h" + +struct S { +private: + S () {}; // ctor is private +}; + +int main() +{ + std::shared_ptr p = std::make_shared(); +} 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.fail.cpp new file mode 100644 index 000000000000..0eeeed4e88c9 --- /dev/null +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.fail.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// shared_ptr + +// template shared_ptr make_shared(Args&&... args); + +#include +#include + +#include "test_macros.h" + +struct S { +protected: + S () {}; // ctor is protected +}; + +int main() +{ + std::shared_ptr p = std::make_shared(); // expected-error-re@memory:* {{static_assert failed{{.*}} "Can't construct object in make_shared"}} +}