[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
Tue Sep 8 02:05:09 PDT 2026


================
@@ -87,55 +95,62 @@ int main(int, char**) {
                           throwing_iterator<bool, std::forward_iterator_tag>(2),
                           alloc);
     (void)vec;
+    assert(false);
   } catch (int) {
   }
   check_new_delete_called();
 
   try { // Throw in vector(InputIterator, InputIterator, const allocator_type&) from allocator
     bool a[] = {true, false};
-    throwing_allocator<bool> alloc(/*throw_on_ctor = */ false, /*throw_on_copy = */ true);
+    throwing_allocator<bool> alloc((throwing_on_allocation_tag()));
     AllocVec vec(cpp17_input_iterator<bool*>(a), cpp17_input_iterator<bool*>(a + 2), alloc);
     (void)vec;
+    assert(false);
   } catch (int) {
   }
   check_new_delete_called();
 
   try { // Throw in vector(InputIterator, InputIterator, const allocator_type&) from allocator
     bool a[] = {true, false};
-    throwing_allocator<bool> alloc(/*throw_on_ctor = */ false, /*throw_on_copy = */ true);
+    throwing_allocator<bool> alloc((throwing_on_allocation_tag()));
     AllocVec vec(forward_iterator<bool*>(a), forward_iterator<bool*>(a + 2), alloc);
     (void)vec;
+    assert(false);
   } catch (int) {
   }
   check_new_delete_called();
 
 #if TEST_STD_VER >= 11
   try { // Throw in vector(const vector&, const allocator_type&) from allocator
-    throwing_allocator<bool> alloc(/*throw_on_ctor = */ false, /*throw_on_copy = */ false);
+    throwing_allocator<bool> alloc((permitting_allocation_tag()));
----------------
frederick-vs-ja wrote:

`permitting_allocation_tag` is necessary for allocator-extended constructors corresponding to copy and move constructors. The seemingly redundant enclosing `()` are due to most vexing parse and lack of list-initialization in C++03.

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


More information about the libcxx-commits mailing list