From df68ebc39b3d83f310b90e70e241b1b9aaf0ea49 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Tue, 5 Dec 2017 04:09:49 +0000 Subject: Land D28253 which fixes PR28929 (which we mistakenly marked as fixed before) git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@319736 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/memory | 10 ++++++++ .../make_shared.private.fail.cpp | 29 ++++++++++++++++++++++ .../make_shared.protected.fail.cpp | 29 ++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.private.fail.cpp create mode 100644 test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.fail.cpp diff --git a/include/memory b/include/memory index 5c109df1c..753101123 100644 --- a/include/memory +++ b/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/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.private.fail.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.private.fail.cpp new file mode 100644 index 000000000..7f304054b --- /dev/null +++ b/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/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.fail.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.fail.cpp new file mode 100644 index 000000000..0eeeed4e8 --- /dev/null +++ b/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"}} +} -- cgit v1.2.3