[libcxx-commits] [libcxx] [libc++][test] Fix and refactor exception tests for std::vector constructors (PR #117662)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Nov 28 10:11:23 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;
----------------
ldionne wrote:
Ah, thanks a lot for explaining!
https://github.com/llvm/llvm-project/pull/117662
More information about the libcxx-commits
mailing list