libstdc++: Make allocators throw bad_array_new_length on overflow [LWG 3190]
authorJonathan Wakely <jwakely@redhat.com>
Mon, 5 Oct 2020 14:16:58 +0000 (15:16 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 5 Oct 2020 14:18:56 +0000 (15:18 +0100)
commitf92a504fdd943527687faf9557e0b39ff7fe6125
tree007b6dfe3b0578c5f19eff0875b9725996def695
parent717e402dbf55e7da83d4fc87641ab9e60d4846cb
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/config/abi/pre/gnu.ver
libstdc++-v3/include/bits/functexcept.h
libstdc++-v3/include/ext/malloc_allocator.h
libstdc++-v3/include/ext/new_allocator.h
libstdc++-v3/include/std/memory_resource
libstdc++-v3/src/c++11/functexcept.cc
libstdc++-v3/testsuite/20_util/allocator/lwg3190.cc [new file with mode: 0644]