From 8a915ed644b910ae9d7d2aef7ad491791fbd4944 Mon Sep 17 00:00:00 2001 From: Roger Ferrer Ibanez Date: Tue, 1 Nov 2016 15:46:16 +0000 Subject: 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 --- .../basic.string/string.capacity/reserve.pass.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp') diff --git a/libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp index b2c254d1fb2..ad29f9cab5f 100644 --- a/libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp @@ -7,7 +7,6 @@ // //===----------------------------------------------------------------------===// -// XFAIL: libcpp-no-exceptions // // void reserve(size_type res_arg=0); @@ -38,18 +37,27 @@ test(S s, typename S::size_type res_arg) { typename S::size_type old_cap = s.capacity(); S s0 = s; - try + if (res_arg <= s.max_size()) { s.reserve(res_arg); - assert(res_arg <= s.max_size()); assert(s == s0); assert(s.capacity() >= res_arg); assert(s.capacity() >= s.size()); } - catch (std::length_error&) +#ifndef TEST_HAS_NO_EXCEPTIONS + else { - assert(res_arg > s.max_size()); + try + { + s.reserve(res_arg); + assert(false); + } + catch (std::length_error&) + { + assert(res_arg > s.max_size()); + } } +#endif } int main() -- cgit v1.2.3