Blame SOURCES/gcc8-libstdc++-make_shared.patch

47043d
commit 79fa567e234585dc6a71f9bd069101c993513f3e
47043d
Author: Jonathan Wakely <jwakely@redhat.com>
47043d
Date:   Thu Apr 22 15:46:51 2021 +0100
47043d
47043d
    libstdc++: Reject std::make_shared<T[]> [PR 99006]
47043d
    
47043d
    Prior to C++20 it should be ill-formed to use std::make_shared with an
47043d
    array type (and we don't support the C++20 feature to make it valid yet
47043d
    anyway).
47043d
    
47043d
    libstdc++-v3/ChangeLog:
47043d
    
47043d
            PR libstdc++/99006
47043d
            * include/bits/shared_ptr.h (allocate_shared): Assert that _Tp
47043d
            is not an array type.
47043d
            * include/bits/shared_ptr_base.h (__allocate_shared): Likewise.
47043d
            * testsuite/20_util/shared_ptr/creation/99006.cc: New test.
47043d
    
47043d
    (cherry picked from commit 55650236cd97d81f42f9fdb4f6bcb12babafe51f)
47043d
47043d
diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h
47043d
index 281600b2901..4ddc52ae723 100644
47043d
--- a/libstdc++-v3/include/bits/shared_ptr.h
47043d
+++ b/libstdc++-v3/include/bits/shared_ptr.h
47043d
@@ -698,6 +698,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
47043d
     inline shared_ptr<_Tp>
47043d
     allocate_shared(const _Alloc& __a, _Args&&... __args)
47043d
     {
47043d
+      static_assert(!is_array<_Tp>::value, "make_shared<T[]> not supported");
47043d
+
47043d
       return shared_ptr<_Tp>(_Sp_alloc_shared_tag<_Alloc>{__a},
47043d
 			     std::forward<_Args>(__args)...);
47043d
     }
47043d
diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h
47043d
index 0367c2d51a5..8af6e9fb11c 100644
47043d
--- a/libstdc++-v3/include/bits/shared_ptr_base.h
47043d
+++ b/libstdc++-v3/include/bits/shared_ptr_base.h
47043d
@@ -1822,6 +1822,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
47043d
     inline __shared_ptr<_Tp, _Lp>
47043d
     __allocate_shared(const _Alloc& __a, _Args&&... __args)
47043d
     {
47043d
+      static_assert(!is_array<_Tp>::value, "make_shared<T[]> not supported");
47043d
+
47043d
       return __shared_ptr<_Tp, _Lp>(_Sp_alloc_shared_tag<_Alloc>{__a},
47043d
 				    std::forward<_Args>(__args)...);
47043d
     }
47043d
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/creation/99006.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/99006.cc
47043d
new file mode 100644
47043d
index 00000000000..d5f7a5da5e9
47043d
--- /dev/null
47043d
+++ b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/99006.cc
47043d
@@ -0,0 +1,9 @@
47043d
+// FIXME: This should use { target { ! c++20 } }
47043d
+// { dg-do compile }
47043d
+
47043d
+#include <memory>
47043d
+
47043d
+auto p = std::make_shared<int[]>(2); // { dg-error "here" }
47043d
+auto q = std::make_shared<int[2]>(1, 2); // { dg-error "here" }
47043d
+
47043d
+// { dg-prune-output "static assertion failed" }