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

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jul 29 04:50:53 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;
   }
----------------
philnik777 wrote:

I'm not a huge fan of these overloads. Can we use tag types instead? AFAICT you'd only need a `nothrow` for default construction and a `throw_on_alloc` version.

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

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


More information about the libcxx-commits mailing list