Skip to content

Commit edd1544

Browse files
committed
[libc++] Improve the test coverage for std::vector::emplace
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 in preparation for reworking the implementation of emplace.
1 parent 9c6abf0 commit edd1544

File tree

3 files changed

+335
-219
lines changed

3 files changed

+335
-219
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 ThrowingMove {
43+
TEST_CONSTEXPR ThrowingMove() : value(0), do_throw(false) {}
44+
TEST_CONSTEXPR explicit ThrowingMove(int v) : value(v), do_throw(false) {}
45+
TEST_CONSTEXPR explicit ThrowingMove(int v, bool do_throw) : value(v), do_throw(do_throw) {}
46+
47+
ThrowingMove(const ThrowingMove& rhs) = default;
48+
ThrowingMove& operator=(const ThrowingMove&) = default;
49+
50+
TEST_CONSTEXPR_CXX14 ThrowingMove(ThrowingMove&& rhs) : value(rhs.value), do_throw(rhs.do_throw) {
51+
if (do_throw)
52+
throw 1;
53+
}
54+
TEST_CONSTEXPR_CXX14 ThrowingMove& operator=(ThrowingMove&& 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==(ThrowingMove const& lhs, ThrowingMove 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)