[libcxx-commits] [PATCH] D110846: [libcxx] Make allocator<T>:allocate throw bad_array_new_length

Mikhail Maltsev via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Sep 30 09:09:42 PDT 2021


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

Currently the member functions std::allocator<T>::allocate,
std::experimental::pmr::polymorphic_allocator::allocate and
std::resource_adaptor<T>::do_allocate throw an exception of type
std::length_error when the requested size exceeds the maximum size.

      

According to the C++ standard ([allocator.members]/4,
[mem.poly.allocator.mem]/1), std::allocator<T>::allocate and
std::pmr::polymorphic_allocator::allocate must throw a
std::bad_array_new_length exception in this case.

      

The patch fixes the issue with std::allocator<T>::allocate and changes
the type the exception thrown by
std::experimental::pmr::resource_adaptor<T>::do_allocate to
std::bad_array_new_length as well for consistency.

      

The patch resolves LWG 3237 and also marks LWG 3038 and LWG 3190 as
fixed (the existing implementation is not affected by these two
defects).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110846

Files:
  libcxx/docs/Status/Cxx20Issues.csv
  libcxx/include/__memory/allocator.h
  libcxx/include/experimental/memory_resource
  libcxx/include/new
  libcxx/src/new.cpp
  libcxx/test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/allocate.pass.cpp
  libcxx/test/std/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.mem/do_allocate_and_deallocate.pass.cpp
  libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110846.376243.patch
Type: text/x-patch
Size: 9119 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210930/180a21a5/attachment-0001.bin>


More information about the libcxx-commits mailing list