[libcxx-commits] [libcxx] [libc++][test] Fix `throwing_allocator` and improve related tests (PR #212673)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jul 29 05:31:09 PDT 2026


================
@@ -147,36 +147,46 @@ template <class T>
 struct throwing_allocator {
   using value_type = T;
 
-  bool throw_on_copy_ = false;
+  bool throw_on_allocation_ = false;
+  int payload_              = 0;
 
   explicit throwing_allocator(bool throw_on_ctor = true) {
     if (throw_on_ctor)
       throw 0;
   }
 
-  explicit throwing_allocator(bool throw_on_ctor, bool throw_on_copy) : throw_on_copy_(throw_on_copy) {
+  explicit throwing_allocator(bool throw_on_ctor, bool throw_on_allocation)
+      : throw_on_allocation_(throw_on_allocation) {
     if (throw_on_ctor)
       throw 0;
   }
----------------
frederick-vs-ja wrote:

> Actually, do we ever need `throw_on_allocation == false`? Can we just throw from `allocate` unconditionally instead?

On this, I think we still need verify throwing from `vector(const vector&, const Alloc&)` and `vector(vector&&, const Alloc&)` where the source `vector` is non-empty, so perhaps unconditionally throwing is not feasible.

https://github.com/llvm/llvm-project/pull/212673


More information about the libcxx-commits mailing list