[libcxx] Throw correct exception from std::vector::reserve
authorMikhail Maltsev <mikhail.maltsev@arm.com>
Thu, 21 Oct 2021 09:40:05 +0000 (10:40 +0100)
committerMikhail Maltsev <mikhail.maltsev@arm.com>
Thu, 21 Oct 2021 09:40:48 +0000 (10:40 +0100)
commit05a2d1766864f60210d8f337a7ea709fa0707b53
treeddaae8c2e671f0463177f631d67d44758a8a83be
parent49be23a1eb5743fa92a8367b6081674a8a392da3
[libcxx] Throw correct exception from std::vector::reserve

According to the standard [vector.capacity]/5, std::vector<T>::reserve
shall throw an exception of type std::length_error when the requested
capacity exceeds max_size().

This behavior is not implemented correctly: the function 'reserve'
simply propagates the exception from allocator<T>::allocate. Before
D110846 that exception used to be of type std::length_error (which is
correct for vector<T>::reserve, but incorrect for
allocator<T>::allocate).

This patch fixes the issue and adds regression tests.

Reviewed By: Quuxplusone, ldionne, #libc

Differential Revision: https://reviews.llvm.org/D112068
libcxx/include/vector
libcxx/test/std/containers/sequences/vector.bool/reserve.pass.cpp
libcxx/test/std/containers/sequences/vector/vector.capacity/reserve.pass.cpp