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