Protect exceptional paths under libcpp-no-exceptions

These tests are of the form

try {
   action-that-may-throw
   assert(!exceptional-condition)
   assert(some-other-facts)
 } catch (relevant-exception) {
   assert(exceptional-condition)
 }

Under libcpp-no-exceptions there is still value in verifying
some-other-facts while avoiding the exceptional case. So for these tests
just conditionally check some-other-facts if exceptional-condition is
false. When exception are supported make sure that a true
exceptional-condition throws an exception

Differential Revision: https://reviews.llvm.org/D26136

llvm-svn: 285697
This commit is contained in:
Roger Ferrer Ibanez
2016-11-01 15:46:16 +00:00
parent 6dd8fab443
commit 8a915ed644
28 changed files with 598 additions and 248 deletions

View File

@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
// XFAIL: libcpp-no-exceptions
// <string>
// basic_string<charT,traits,Allocator>&
@@ -24,40 +23,58 @@ template <class S>
void
test(S s, typename S::size_type pos, typename S::size_type n, S expected)
{
typename S::size_type old_size = s.size();
const typename S::size_type old_size = s.size();
S s0 = s;
try
if (pos <= old_size)
{
s.erase(pos, n);
LIBCPP_ASSERT(s.__invariants());
assert(pos <= old_size);
assert(s == expected);
}
catch (std::out_of_range&)
#ifndef TEST_HAS_NO_EXCEPTIONS
else
{
assert(pos > old_size);
assert(s == s0);
try
{
s.erase(pos, n);
assert(false);
}
catch (std::out_of_range&)
{
assert(pos > old_size);
assert(s == s0);
}
}
#endif
}
template <class S>
void
test(S s, typename S::size_type pos, S expected)
{
typename S::size_type old_size = s.size();
const typename S::size_type old_size = s.size();
S s0 = s;
try
if (pos <= old_size)
{
s.erase(pos);
LIBCPP_ASSERT(s.__invariants());
assert(pos <= old_size);
assert(s == expected);
}
catch (std::out_of_range&)
#ifndef TEST_HAS_NO_EXCEPTIONS
else
{
assert(pos > old_size);
assert(s == s0);
try
{
s.erase(pos);
assert(false);
}
catch (std::out_of_range&)
{
assert(pos > old_size);
assert(s == s0);
}
}
#endif
}
template <class S>