[libcxx-commits] [libcxx] [libc++][test] Fix and refactor exception tests for std::vector constructors (PR #117662)

Peng Liu via libcxx-commits libcxx-commits at lists.llvm.org
Thu Nov 28 08:39:27 PST 2024


================
@@ -16,10 +16,41 @@
 
 #include "count_new.h"
 
+struct throwing_t {
+  int* throw_after_n_ = nullptr;
+  throwing_t() { throw 0; }
+
+  throwing_t(int& throw_after_n) : throw_after_n_(&throw_after_n) {
+    if (throw_after_n == 0)
+      throw 0;
+    --throw_after_n;
+  }
+
+  throwing_t(const throwing_t& rhs) : throw_after_n_(rhs.throw_after_n_) {
+    if (throw_after_n_ == nullptr || *throw_after_n_ == 0)
+      throw 1;
+    --*throw_after_n_;
+  }
+
+  throwing_t& operator=(const throwing_t& rhs) {
+    throw_after_n_ = rhs.throw_after_n_;
+    if (throw_after_n_ == nullptr || *throw_after_n_ == 0)
+      throw 1;
+    --*throw_after_n_;
+    return *this;
+  }
+
+  friend bool operator==(const throwing_t& lhs, const throwing_t& rhs) {
+    return lhs.throw_after_n_ == rhs.throw_after_n_;
+  }
+  friend bool operator!=(const throwing_t& lhs, const throwing_t& rhs) {
+    return lhs.throw_after_n_ != rhs.throw_after_n_;
+  }
+};
+
 template <class T>
 struct throwing_allocator {
-  using value_type      = T;
-  using is_always_equal = std::false_type;
----------------
winner245 wrote:

I think this member type is causing confusion, as no tests rely on this member type for comparing the equality between two instances of `throwing_allocator<T>`, as explained [here](https://github.com/llvm/llvm-project/pull/115491#discussion_r1859818964). 

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


More information about the libcxx-commits mailing list