[libcxx] r319736 - Land D28253 which fixes PR28929 (which we mistakenly marked as fixed before)

Marshall Clow via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 4 20:09:50 PST 2017


Author: marshall
Date: Mon Dec  4 20:09:49 2017
New Revision: 319736

URL: http://llvm.org/viewvc/llvm-project?rev=319736&view=rev
Log:
Land D28253 which fixes PR28929 (which we mistakenly marked as fixed before)

Added:
    libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.private.fail.cpp
    libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.fail.cpp
Modified:
    libcxx/trunk/include/memory

Modified: libcxx/trunk/include/memory
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/memory?rev=319736&r1=319735&r2=319736&view=diff
==============================================================================
--- libcxx/trunk/include/memory (original)
+++ libcxx/trunk/include/memory Mon Dec  4 20:09:49 2017
@@ -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
 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
 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;

Added: libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.private.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.private.fail.cpp?rev=319736&view=auto
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.private.fail.cpp (added)
+++ libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.private.fail.cpp Mon Dec  4 20:09:49 2017
@@ -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>();
+}

Added: libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.fail.cpp?rev=319736&view=auto
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.fail.cpp (added)
+++ libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.fail.cpp Mon Dec  4 20:09:49 2017
@@ -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 at memory:* {{static_assert failed{{.*}} "Can't construct object in make_shared"}}
+}




More information about the cfe-commits mailing list