[libcxx-commits] [PATCH] D112068: [libcxx] Throw correct exception from std::vector::reserve

Mikhail Maltsev via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 19 05:35:03 PDT 2021


miyuki created this revision.
miyuki added reviewers: Quuxplusone, ldionne.
miyuki requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

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 <https://reviews.llvm.org/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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112068

Files:
  libcxx/include/vector
  libcxx/test/libcxx/containers/sequences/vector.bool/reserve.pass.cpp
  libcxx/test/std/containers/sequences/vector/vector.capacity/reserve.pass.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112068.380661.patch
Type: text/x-patch
Size: 3361 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211019/d9e347f1/attachment.bin>


More information about the libcxx-commits mailing list