Skip to content

Commit 71eb8d1

Browse files
committed
Clarify test
1 parent 931a0cb commit 71eb8d1

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,27 @@ struct Throws {
3939

4040
bool Throws::sThrows = false;
4141

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 throw_) : value(v), do_throw(throw_) {}
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_) {}
4646

47-
ThrowingMove(const ThrowingMove& rhs) = default;
48-
ThrowingMove& operator=(const ThrowingMove&) = default;
47+
ThrowingMoveOnly(const ThrowingMoveOnly& rhs) = delete;
48+
ThrowingMoveOnly& operator=(const ThrowingMoveOnly&) = delete;
4949

50-
TEST_CONSTEXPR_CXX14 ThrowingMove(ThrowingMove&& rhs) : value(rhs.value), do_throw(rhs.do_throw) {
50+
TEST_CONSTEXPR_CXX14 ThrowingMoveOnly(ThrowingMoveOnly&& rhs) : value(rhs.value), do_throw(rhs.do_throw) {
5151
if (do_throw)
5252
throw 1;
5353
}
54-
TEST_CONSTEXPR_CXX14 ThrowingMove& operator=(ThrowingMove&& rhs) {
54+
TEST_CONSTEXPR_CXX14 ThrowingMoveOnly& operator=(ThrowingMoveOnly&& rhs) {
5555
value = rhs.value;
5656
do_throw = rhs.do_throw;
5757
if (do_throw)
5858
throw 1;
5959
return *this;
6060
}
6161

62-
TEST_CONSTEXPR_CXX14 friend bool operator==(ThrowingMove const& lhs, ThrowingMove const& rhs) {
62+
TEST_CONSTEXPR_CXX14 friend bool operator==(ThrowingMoveOnly const& lhs, ThrowingMoveOnly const& rhs) {
6363
return lhs.value == rhs.value;
6464
}
6565

libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace.pass.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,13 @@ TEST_CONSTEXPR_CXX20 void test() {
290290
// change in the future.
291291
#if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_EXCEPTIONS)
292292
{
293-
std::vector<ThrowingMove, Allocator<ThrowingMove> > v;
293+
// This ensures that we test what we intend to test: the Standard requires the strong exception safety
294+
// guarantee for types that are nothrow move constructible or copy insertable, but that's not what we're
295+
// trying to test. We're trying to test the stronger libc++ guarantee.
296+
static_assert(!std::is_nothrow_move_constructible<ThrowingMoveOnly>::value, "");
297+
static_assert(!std::is_copy_constructible<ThrowingMoveOnly>::value, "");
298+
299+
std::vector<ThrowingMoveOnly, Allocator<ThrowingMoveOnly> > v;
294300
v.emplace_back(0, /* do throw */ false);
295301
v.emplace_back(1, /* do throw */ false);
296302

@@ -302,9 +308,9 @@ TEST_CONSTEXPR_CXX20 void test() {
302308
v.emplace(v.cend(), 3, /* do throw */ true); // this shouldn't throw since we shouldn't move this element at all
303309

304310
assert(v.size() >= 3);
305-
assert(v[0] == ThrowingMove(0));
306-
assert(v[1] == ThrowingMove(1));
307-
assert(v.back() == ThrowingMove(3));
311+
assert(v[0] == ThrowingMoveOnly(0));
312+
assert(v[1] == ThrowingMoveOnly(1));
313+
assert(v.back() == ThrowingMoveOnly(3));
308314
assert(is_contiguous_container_asan_correct(v));
309315
}
310316
#endif // defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_EXCEPTIONS)

0 commit comments

Comments
 (0)