summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2022-06-14 14:37:25 +0100
committerJonathan Wakely <jwakely@redhat.com>2022-06-14 21:07:47 +0100
commit0a9af7b4ef1b8aa85cc8820acf54d41d1569fc10 (patch)
tree8bf40c0d45908561bf164ca1224fd892a27fd4be /libstdc++-v3/testsuite
parent3e16b4359e86b36676ed01219e6deafa95f3c16b (diff)
libstdc++: Check for size overflow in constexpr allocation [PR105957]
libstdc++-v3/ChangeLog: PR libstdc++/105957 * include/bits/allocator.h (allocator::allocate): Check for overflow in constexpr allocation. * testsuite/20_util/allocator/105975.cc: New test.
Diffstat (limited to 'libstdc++-v3/testsuite')
-rw-r--r--libstdc++-v3/testsuite/20_util/allocator/105975.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/20_util/allocator/105975.cc b/libstdc++-v3/testsuite/20_util/allocator/105975.cc
new file mode 100644
index 00000000000..4342aeade04
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/allocator/105975.cc
@@ -0,0 +1,18 @@
+// { dg-options "-std=gnu++20" }
+// { dg-do compile { target c++20 } }
+
+// PR libstdc++/105957
+
+#include <memory>
+
+consteval bool test_pr105957()
+{
+ std::allocator<long long> a;
+ auto n = std::size_t(-1) / (sizeof(long long) - 1);
+ auto p = a.allocate(n); // { dg-error "constexpr" }
+ a.deallocate(p, n);
+ return true;
+}
+static_assert( test_pr105957() );
+
+// { dg-error "throw_bad_array_new_length" "" { target *-*-* } 0 }