Skip to content

Commit 60b43ef

Browse files
authored
[libc++] Improve the test coverage for std::vector::emplace (llvm#132440)
This patch refactors the test for std::vector::emplace back to cover new corner cases, and increase coverage for normal cases as well. This is building towards llvm#129328.
1 parent 3ea0754 commit 60b43ef

File tree

3 files changed

+326
-220
lines changed

3 files changed

+326
-220
lines changed

libcxx/test/std/containers/sequences/vector/vector.modifiers/common.h

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,35 @@ struct Throws {
3838
};
3939

4040
bool Throws::sThrows = false;
41-
#endif
41+
42+
struct ThrowingMoveOnly {
43+
TEST_CONSTEXPR ThrowingMoveOnly() : value(0), do_throw(false) {}
44+
TEST_CONSTEXPR explicit ThrowingMoveOnly(int v) : value(v), do_throw(false) {}
45+
TEST_CONSTEXPR explicit ThrowingMoveOnly(int v, bool throw_) : value(v), do_throw(throw_) {}
46+
47+
ThrowingMoveOnly(const ThrowingMoveOnly& rhs) = delete;
48+
ThrowingMoveOnly& operator=(const ThrowingMoveOnly&) = delete;
49+
50+
TEST_CONSTEXPR_CXX14 ThrowingMoveOnly(ThrowingMoveOnly&& rhs) : value(rhs.value), do_throw(rhs.do_throw) {
51+
if (do_throw)
52+
throw 1;
53+
}
54+
TEST_CONSTEXPR_CXX14 ThrowingMoveOnly& operator=(ThrowingMoveOnly&& rhs) {
55+
value = rhs.value;
56+
do_throw = rhs.do_throw;
57+
if (do_throw)
58+
throw 1;
59+
return *this;
60+
}
61+
62+
TEST_CONSTEXPR_CXX14 friend bool operator==(ThrowingMoveOnly const& lhs, ThrowingMoveOnly const& rhs) {
63+
return lhs.value == rhs.value;
64+
}
65+
66+
int value;
67+
bool do_throw;
68+
};
69+
#endif // TEST_HAS_NO_EXCEPTIONS
4270

4371
struct Tracker {
4472
int copy_assignments = 0;

0 commit comments

Comments
 (0)