From f92a504fdd943527687faf9557e0b39ff7fe6125 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Mon, 5 Oct 2020 15:16:58 +0100 Subject: libstdc++: Make allocators throw bad_array_new_length on overflow [LWG 3190] std::allocator and std::pmr::polymorphic_allocator should throw std::bad_array_new_length from their allocate member functions if the number of bytes required cannot be represented in std::size_t. libstdc++-v3/ChangeLog: * config/abi/pre/gnu.ver: Add new symbol. * include/bits/functexcept.h (__throw_bad_array_new_length): Declare new function. * include/ext/malloc_allocator.h (malloc_allocator::allocate): Throw bad_array_new_length for impossible sizes (LWG 3190). * include/ext/new_allocator.h (new_allocator::allocate): Likewise. * include/std/memory_resource (polymorphic_allocator::allocate) (polymorphic_allocator::allocate_object): Use new function, __throw_bad_array_new_length. * src/c++11/functexcept.cc (__throw_bad_array_new_length): Define. * testsuite/20_util/allocator/lwg3190.cc: New test. --- libstdc++-v3/src/c++11/functexcept.cc | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libstdc++-v3/src') diff --git a/libstdc++-v3/src/c++11/functexcept.cc b/libstdc++-v3/src/c++11/functexcept.cc index d43167d..b5da174 100644 --- a/libstdc++-v3/src/c++11/functexcept.cc +++ b/libstdc++-v3/src/c++11/functexcept.cc @@ -54,6 +54,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { _GLIBCXX_THROW_OR_ABORT(bad_alloc()); } void + __throw_bad_array_new_length() + { _GLIBCXX_THROW_OR_ABORT(bad_array_new_length()); } + + void __throw_bad_cast() { _GLIBCXX_THROW_OR_ABORT(bad_cast()); } -- cgit v1.1