[libcxx-commits] [libcxx] [libc++] Improve the test coverage for std::vector::emplace (PR #132440)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Mar 21 22:51:49 PDT 2025
================
@@ -38,7 +38,35 @@ struct Throws {
};
bool Throws::sThrows = false;
-#endif
+
+struct ThrowingMove {
+ TEST_CONSTEXPR ThrowingMove() : value(0), do_throw(false) {}
+ TEST_CONSTEXPR explicit ThrowingMove(int v) : value(v), do_throw(false) {}
+ TEST_CONSTEXPR explicit ThrowingMove(int v, bool do_throw) : value(v), do_throw(do_throw) {}
+
+ ThrowingMove(const ThrowingMove& rhs) = default;
+ ThrowingMove& operator=(const ThrowingMove&) = default;
+
+ TEST_CONSTEXPR_CXX14 ThrowingMove(ThrowingMove&& rhs) : value(rhs.value), do_throw(rhs.do_throw) {
+ if (do_throw)
+ throw 1;
+ }
+ TEST_CONSTEXPR_CXX14 ThrowingMove& operator=(ThrowingMove&& rhs) {
+ value = rhs.value;
+ do_throw = rhs.do_throw;
+ if (do_throw)
+ throw 1;
+ return *this;
+ }
----------------
frederick-vs-ja wrote:
I think we should keep using `TEST_CONSTEXPR_CXX14`. This `operator=` is not always throwing. When it normally returns (i.e. `do_throw` is `false`), the function call is suitable for constant evaluation in C++14.
https://github.com/llvm/llvm-project/pull/132440
More information about the libcxx-commits
mailing list