Protect std::string tests under libcpp-no-exceptions

Skip tests that expect an exception be thrown and/or disable
unreachable catch handlers.

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



git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@288158 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Roger Ferrer Ibanez
2016-11-29 16:40:19 +00:00
parent d6f05863c3
commit 81086f8bfe
2 changed files with 19 additions and 5 deletions

View File

@@ -7,7 +7,6 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// XFAIL: libcpp-no-exceptions
// <string> // <string>
// size_type capacity() const; // size_type capacity() const;
@@ -18,21 +17,27 @@
#include "test_allocator.h" #include "test_allocator.h"
#include "min_allocator.h" #include "min_allocator.h"
#include "test_macros.h"
template <class S> template <class S>
void void
test(S s) test(S s)
{ {
S::allocator_type::throw_after = 0; S::allocator_type::throw_after = 0;
#ifndef TEST_HAS_NO_EXCEPTIONS
try try
#endif
{ {
while (s.size() < s.capacity()) while (s.size() < s.capacity())
s.push_back(typename S::value_type()); s.push_back(typename S::value_type());
assert(s.size() == s.capacity()); assert(s.size() == s.capacity());
} }
#ifndef TEST_HAS_NO_EXCEPTIONS
catch (...) catch (...)
{ {
assert(false); assert(false);
} }
#endif
S::allocator_type::throw_after = INT_MAX; S::allocator_type::throw_after = INT_MAX;
} }

View File

@@ -7,7 +7,6 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// XFAIL: libcpp-no-exceptions
// <string> // <string>
// basic_string substr(size_type pos = 0, size_type n = npos) const; // basic_string substr(size_type pos = 0, size_type n = npos) const;
@@ -24,7 +23,7 @@ template <class S>
void void
test(const S& s, typename S::size_type pos, typename S::size_type n) test(const S& s, typename S::size_type pos, typename S::size_type n)
{ {
try if (pos <= s.size())
{ {
S str = s.substr(pos, n); S str = s.substr(pos, n);
LIBCPP_ASSERT(str.__invariants()); LIBCPP_ASSERT(str.__invariants());
@@ -33,11 +32,21 @@ test(const S& s, typename S::size_type pos, typename S::size_type n)
assert(str.size() == rlen); assert(str.size() == rlen);
assert(S::traits_type::compare(s.data()+pos, str.data(), rlen) == 0); 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&) catch (std::out_of_range&)
{ {
assert(pos > s.size()); assert(pos > s.size());
} }
} }
#endif
}
int main() int main()
{ {