[libcxx-commits] [libcxx] [libc++] Improve the test coverage for std::vector::emplace (PR #132440)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Mar 27 09:15:10 PDT 2025


================
@@ -7,150 +7,341 @@
 //===----------------------------------------------------------------------===//
 
 // UNSUPPORTED: c++03 && !stdlib=libc++
+// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-steps): -fconstexpr-steps=9000000
 
 // <vector>
 
 // template <class... Args> iterator emplace(const_iterator pos, Args&&... args);
 
-#include <vector>
 #include <cassert>
+#include <cstddef>
+#include <type_traits>
+#include <utility>
+#include <vector>
 
-#include "test_macros.h"
-#include "test_allocator.h"
-#include "min_allocator.h"
 #include "asan_testing.h"
+#include "common.h"
+#include "min_allocator.h"
+#include "test_allocator.h"
+#include "test_macros.h"
 
-class A {
-  int i_;
-  double d_;
+struct MoveOnly {
+  int value;
 
-  A(const A&);
-  A& operator=(const A&);
+  TEST_CONSTEXPR_CXX14 explicit MoveOnly(int i) : value(i) {}
 
-public:
-  TEST_CONSTEXPR_CXX14 A(int i, double d) : i_(i), d_(d) {}
+  MoveOnly(MoveOnly const&)            = delete;
+  MoveOnly& operator=(MoveOnly const&) = delete;
 
-  TEST_CONSTEXPR_CXX14 A(A&& a) : i_(a.i_), d_(a.d_) {
-    a.i_ = 0;
-    a.d_ = 0;
-  }
+  TEST_CONSTEXPR_CXX14 MoveOnly(MoveOnly&& other) TEST_NOEXCEPT : value(other.value) { other.value = -1; }
 
-  TEST_CONSTEXPR_CXX14 A& operator=(A&& a) {
-    i_   = a.i_;
-    d_   = a.d_;
-    a.i_ = 0;
-    a.d_ = 0;
+  TEST_CONSTEXPR_CXX14 MoveOnly& operator=(MoveOnly&& other) TEST_NOEXCEPT {
+    value       = other.value;
+    other.value = -1;
     return *this;
   }
 
-  TEST_CONSTEXPR_CXX14 int geti() const { return i_; }
-  TEST_CONSTEXPR_CXX14 double getd() const { return d_; }
+  TEST_CONSTEXPR_CXX14 friend bool operator==(MoveOnly const& lhs, MoveOnly const& rhs) {
+    return lhs.value == rhs.value;
+  }
 };
----------------
ldionne wrote:

Great point, thanks!

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


More information about the libcxx-commits mailing list