[libcxx-commits] [libcxx] [libc++] Improve test coverage for copy/move ctors for vector<bool> (PR #120132)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Mar 19 09:06:15 PDT 2025


================
@@ -9,54 +9,70 @@
 // UNSUPPORTED: c++03
 
 // <vector>
+// vector<bool>
 
 // vector(vector&& c);
 
-#include <vector>
+#include <array>
 #include <cassert>
-#include "test_macros.h"
-#include "test_allocator.h"
+#include <vector>
+
 #include "min_allocator.h"
+#include "test_allocator.h"
+#include "test_macros.h"
+
+template <unsigned N, class A>
+TEST_CONSTEXPR_CXX20 void test(const A& a) {
+  std::vector<bool, A> v(N, false, a);
+  std::vector<bool, A> v0(N, false, a);
+  for (unsigned i = 1; i < N; i += 2) {
+    v[i]  = true;
+    v0[i] = true;
+  }
+  std::vector<bool, A> v2 = std::move(v);
+  assert(v2 == v0);
+  assert(v.empty()); // The moved-from vector is guarantted to be empty after move-construction
----------------
ldionne wrote:

```suggestion
  assert(v.empty()); // The moved-from vector is guaranteed to be empty after move-construction
```

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


More information about the libcxx-commits mailing list