From 0a9af7b4ef1b8aa85cc8820acf54d41d1569fc10 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Tue, 14 Jun 2022 14:37:25 +0100 Subject: 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. --- libstdc++-v3/testsuite/20_util/allocator/105975.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 libstdc++-v3/testsuite/20_util/allocator/105975.cc (limited to 'libstdc++-v3/testsuite') 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 + +consteval bool test_pr105957() +{ + std::allocator 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 } -- cgit v1.2.3