[PATCH] D26136: Protect exceptional path under libcpp-no-exceptions
Marshall Clow via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 31 18:14:44 PDT 2016
mclow.lists added a comment.
This all looks ok to me - all mechanical changes.
I wonder if there's a better way to refactor these - there's all that duplicated code.
Does this look any better to you?
Replace:
try
{
s.replace(pos1, n1, str, pos2);
LIBCPP_ASSERT(s.__invariants());
assert(pos1 <= old_size && pos2 <= str.size());
assert(s == expected);
typename S::size_type xlen = std::min(n1, old_size - pos1);
typename S::size_type rlen = std::min(S::npos, str.size() - pos2);
assert(s.size() == old_size - xlen + rlen);
}
catch (std::out_of_range&)
{
assert(pos1 > old_size || pos2 > str.size());
assert(s == s0);
}
with:
if(pos1 <= old_size && pos2 <= str.size())
{
s.replace(pos1, n1, str, pos2);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
typename S::size_type xlen = std::min(n1, old_size - pos1);
typename S::size_type rlen = std::min(S::npos, str.size() - pos2);
assert(s.size() == old_size - xlen + rlen);
}
#ifndef TEST_HAS_NO_EXCEPTIONS
else
{
try { s.replace(pos1, n1, str, pos2); }
catch (std::out_of_range&)
{
assert(pos1 > old_size || pos2 > str.size());
assert(s == s0);
}
}
#endif
================
Comment at: test/std/strings/basic.string/string.access/at.pass.cpp:42
+ if (pos < cs.size())
+ {
+ assert(s.at(pos) == s[pos]);
----------------
I think you should just test `s.size()` here, not both `s` and `cs`. (the original code got it wrong, too)
The assert at L45 can be removed.
https://reviews.llvm.org/D26136
More information about the cfe-commits
mailing list