summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2017-12-05 04:09:49 +0000
committerMarshall Clow <mclow.lists@gmail.com>2017-12-05 04:09:49 +0000
commitdf68ebc39b3d83f310b90e70e241b1b9aaf0ea49 (patch)
treeab6af6201a50f375400dbd92f8c0f73d9f9b08b4
parentf7d0fecf346bb09a13674a78b6f333912ae67501 (diff)
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
-rw-r--r--include/memory10
-rw-r--r--test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.private.fail.cpp29
-rw-r--r--test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.fail.cpp29
3 files changed, 68 insertions, 0 deletions
diff --git a/include/memory b/include/memory
index 5c109df1c..753101123 100644
--- a/include/memory
+++ b/include/memory
@@ -4265,6 +4265,7 @@ template<class ..._Args>
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<class _Alloc, class ..._Args>
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<class _Tp>
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<class _A0>
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<class _A0, class _A1>
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<class _A0, class _A1, class _A2>
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<class _Alloc>
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<class _Alloc, class _A0>
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<class _Alloc, class _A0, class _A1>
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<class _Alloc, class _A0, class _A1, class _A2>
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.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// shared_ptr
+
+// template<class T, class... Args> shared_ptr<T> make_shared(Args&&... args);
+
+#include <memory>
+#include <cassert>
+
+#include "test_macros.h"
+
+struct S {
+private:
+ S () {}; // ctor is private
+};
+
+int main()
+{
+ std::shared_ptr<S> p = std::make_shared<S>();
+}
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.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// shared_ptr
+
+// template<class T, class... Args> shared_ptr<T> make_shared(Args&&... args);
+
+#include <memory>
+#include <cassert>
+
+#include "test_macros.h"
+
+struct S {
+protected:
+ S () {}; // ctor is protected
+};
+
+int main()
+{
+ std::shared_ptr<S> p = std::make_shared<S>(); // expected-error-re@memory:* {{static_assert failed{{.*}} "Can't construct object in make_shared"}}
+}