mclow.lists added a comment.
We've been using a different pattern for this kind of tests (as we support more
and more noexcept cases). Something like this (for the second change):
template <class S>
void
test(const S& s, typename S::size_type pos, typename
S::size_type n)
{
if (pos <= s.size())
{
S str = s.substr(pos, n);
LIBCPP_ASSERT(str.__invariants());
assert(pos <= s.size());
typename S::size_type rlen = std::min(n,
s.size() - pos);
assert(str.size() == rlen);
assert(S::traits_type::compare(s.data()+pos,
str.data(), rlen) == 0);
}
#ifndef TEST_HAS_NO_EXCEPTIONS
else
{
try
{
S str = s.substr(pos, n);
assert(false);
}
catch (std::out_of_range&)
{
assert(pos > s.size());
}
}
#endif
}
I think that's much easier to read (and avoids duplication of the tests).
https://reviews.llvm.org/D26612
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits