summaryrefslogtreecommitdiff
path: root/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp
diff options
context:
space:
mode:
authorRoger Ferrer Ibanez <roger.ferreribanez@arm.com>2016-11-01 15:46:16 +0000
committerRoger Ferrer Ibanez <roger.ferreribanez@arm.com>2016-11-01 15:46:16 +0000
commitc09116009cebdebbe60b713a918069fcda4d9886 (patch)
treef45680935d1750cd21a3ec4e6a64e0ef60cc57c8 /test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp
parent88837404569b90c0e871550086169612545f253a (diff)
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 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@285697 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp')
-rw-r--r--test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp43
1 files changed, 28 insertions, 15 deletions
diff --git a/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp b/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp
index 2cdc348b6..bc2bf656d 100644
--- a/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp
+++ b/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// template <typename T>
@@ -22,6 +21,8 @@
#include "min_allocator.h"
+#include "test_macros.h"
+
int sign(int x)
{
if (x == 0)
@@ -37,16 +38,22 @@ test(const S& s, typename S::size_type pos1, typename S::size_type n1,
SV sv, typename S::size_type pos2, typename S::size_type n2, int x)
{
static_assert((!std::is_same<S, SV>::value), "");
- try
- {
+ if (pos1 <= s.size() && pos2 <= sv.size())
assert(sign(s.compare(pos1, n1, sv, pos2, n2)) == sign(x));
- assert(pos1 <= s.size());
- assert(pos2 <= sv.size());
- }
- catch (const std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ else
{
- assert(pos1 > s.size() || pos2 > sv.size());
+ try
+ {
+ s.compare(pos1, n1, sv, pos2, n2);
+ assert(false);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(pos1 > s.size() || pos2 > sv.size());
+ }
}
+#endif
}
template <class S, class SV>
@@ -55,16 +62,22 @@ test_npos(const S& s, typename S::size_type pos1, typename S::size_type n1,
SV sv, typename S::size_type pos2, int x)
{
static_assert((!std::is_same<S, SV>::value), "");
- try
- {
+ if (pos1 <= s.size() && pos2 <= sv.size())
assert(sign(s.compare(pos1, n1, sv, pos2)) == sign(x));
- assert(pos1 <= s.size());
- assert(pos2 <= sv.size());
- }
- catch (const std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ else
{
- assert(pos1 > s.size() || pos2 > sv.size());
+ try
+ {
+ s.compare(pos1, n1, sv, pos2);
+ assert(false);
+ }
+ catch (const std::out_of_range&)
+ {
+ assert(pos1 > s.size() || pos2 > sv.size());
+ }
}
+#endif
}
template <class S, class SV>