[libc++] [test] Improve test_exceptions() in each string.modifiers test.

When checking the strong exception guarantee, also check that
iterators haven't been invalidated.

Reviewed as part of https://reviews.llvm.org/D98573
This commit is contained in:
Arthur O'Dwyer
2021-04-16 17:31:33 -04:00
parent e87479b00f
commit 036b80fcbb
4 changed files with 46 additions and 16 deletions

View File

@@ -34,14 +34,21 @@ template <class S, class It>
void
test_exceptions(S s, It first, It last)
{
S aCopy = s;
S original = s;
typename S::iterator begin = s.begin();
typename S::iterator end = s.end();
try {
s.assign(first, last);
assert(false);
}
catch (...) {}
} catch (...) {}
// Part of "no effects" is that iterators and pointers
// into the string must not have been invalidated.
LIBCPP_ASSERT(s.__invariants());
assert(s == aCopy);
assert(s == original);
assert(s.begin() == begin);
assert(s.end() == end);
}
#endif