[libcxx] r285697 - Protect exceptional paths under libcpp-no-exceptions

Roger Ferrer Ibanez via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 1 08:46:16 PDT 2016


Author: rogfer01
Date: Tue Nov  1 10:46:16 2016
New Revision: 285697

URL: http://llvm.org/viewvc/llvm-project?rev=285697&view=rev
Log:
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


Modified:
    libcxx/trunk/test/std/strings/basic.string/string.access/at.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.capacity/reserve.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.cons/substr.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/T_size_size.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_T_size_size.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_string_size_size.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer_size.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp

Modified: libcxx/trunk/test/std/strings/basic.string/string.access/at.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.access/at.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.access/at.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.access/at.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // const_reference at(size_type pos) const;
@@ -19,21 +18,41 @@
 
 #include "min_allocator.h"
 
+#include "test_macros.h"
+
 template <class S>
 void
 test(S s, typename S::size_type pos)
 {
-    try
+    const S& cs = s;
+    if (pos < s.size())
     {
-        const S& cs = s;
         assert(s.at(pos) == s[pos]);
         assert(cs.at(pos) == cs[pos]);
-        assert(pos < cs.size());
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos >= s.size());
+        try
+        {
+            s.at(pos);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos >= s.size());
+        }
+        try
+        {
+            cs.at(pos);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos >= s.size());
+        }
     }
+#endif
 }
 
 int main()

Modified: libcxx/trunk/test/std/strings/basic.string/string.capacity/reserve.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.capacity/reserve.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.capacity/reserve.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.capacity/reserve.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // 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()

Modified: libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // void resize(size_type n);
@@ -23,17 +22,26 @@ template <class S>
 void
 test(S s, typename S::size_type n, S expected)
 {
-    try
+    if (n <= s.max_size())
     {
         s.resize(n);
         LIBCPP_ASSERT(s.__invariants());
-        assert(n <= s.max_size());
         assert(s == expected);
     }
-    catch (std::length_error&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(n > s.max_size());
+        try
+        {
+            s.resize(n);
+            assert(false);
+        }
+        catch (std::length_error&)
+        {
+            assert(n > s.max_size());
+        }
     }
+#endif
 }
 
 int main()

Modified: libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // void resize(size_type n, charT c);
@@ -23,17 +22,26 @@ template <class S>
 void
 test(S s, typename S::size_type n, typename S::value_type c, S expected)
 {
-    try
+    if (n <= s.max_size())
     {
         s.resize(n, c);
         LIBCPP_ASSERT(s.__invariants());
-        assert(n <= s.max_size());
         assert(s == expected);
     }
-    catch (std::length_error&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(n > s.max_size());
+        try
+        {
+            s.resize(n, c);
+            assert(false);
+        }
+        catch (std::length_error&)
+        {
+            assert(n > s.max_size());
+        }
     }
+#endif
 }
 
 int main()

Modified: libcxx/trunk/test/std/strings/basic.string/string.cons/substr.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/substr.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/substr.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/substr.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // basic_string(const basic_string<charT,traits,Allocator>& str,
@@ -35,21 +34,31 @@ test(S str, unsigned pos)
 {
     typedef typename S::traits_type T;
     typedef typename S::allocator_type A;
-    try
+
+    if (pos <= str.size())
     {
         S s2(str, pos);
         LIBCPP_ASSERT(s2.__invariants());
-        assert(pos <= str.size());
         unsigned rlen = str.size() - pos;
         assert(s2.size() == rlen);
         assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
         assert(s2.get_allocator() == A());
         assert(s2.capacity() >= s2.size());
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos > str.size());
+        try
+        {
+            S s2(str, pos);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos > str.size());
+        }
     }
+#endif
 }
 
 template <class S>
@@ -58,21 +67,30 @@ test(S str, unsigned pos, unsigned n)
 {
     typedef typename S::traits_type T;
     typedef typename S::allocator_type A;
-    try
+    if (pos <= str.size())
     {
         S s2(str, pos, n);
         LIBCPP_ASSERT(s2.__invariants());
-        assert(pos <= str.size());
         unsigned rlen = std::min<unsigned>(str.size() - pos, n);
         assert(s2.size() == rlen);
         assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
         assert(s2.get_allocator() == A());
         assert(s2.capacity() >= s2.size());
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos > str.size());
+        try
+        {
+            S s2(str, pos, n);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos > str.size());
+        }
     }
+#endif
 }
 
 template <class S>
@@ -81,24 +99,35 @@ test(S str, unsigned pos, unsigned n, co
 {
     typedef typename S::traits_type T;
     typedef typename S::allocator_type A;
-    try
+
+    if (pos <= str.size())
     {
         S s2(str, pos, n, a);
         LIBCPP_ASSERT(s2.__invariants());
-        assert(pos <= str.size());
         unsigned rlen = std::min<unsigned>(str.size() - pos, n);
         assert(s2.size() == rlen);
         assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
         assert(s2.get_allocator() == a);
         assert(s2.capacity() >= s2.size());
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos > str.size());
+        try
+        {
+            S s2(str, pos, n, a);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos > str.size());
+        }
     }
+#endif
 }
 
 #if TEST_STD_VER >= 11
+#ifndef TEST_HAS_NO_EXCEPTIONS
 void test2583()
 {   // LWG #2583
     typedef std::basic_string<char, std::char_traits<char>, test_allocator<char> > StringA;
@@ -111,6 +140,7 @@ void test2583()
     assert(false);
 }
 #endif
+#endif
 
 int main()
 {
@@ -192,6 +222,8 @@ int main()
     test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 100, A());
     }
 
+#ifndef TEST_HAS_NO_EXCEPTIONS
     test2583();
 #endif
+#endif
 }

Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/T_size_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/T_size_size.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/T_size_size.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/T_size_size.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // template <class T>
@@ -25,34 +24,52 @@ template <class S, class SV>
 void
 test(S s, SV sv, typename S::size_type pos, typename S::size_type n, S expected)
 {
-    try
+    if (pos <= sv.size())
     {
         s.append(sv, pos, n);
         LIBCPP_ASSERT(s.__invariants());
-        assert(pos <= sv.size());
         assert(s == expected);
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos > sv.size());
+        try
+        {
+            s.append(sv, pos, n);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos > sv.size());
+        }
     }
+#endif
 }
 
 template <class S, class SV>
 void
 test_npos(S s, SV sv, typename S::size_type pos, S expected)
 {
-    try
+    if (pos <= sv.size())
     {
         s.append(sv, pos);
         LIBCPP_ASSERT(s.__invariants());
-        assert(pos <= sv.size());
         assert(s == expected);
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos > sv.size());
+        try
+        {
+            s.append(sv, pos);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos > sv.size());
+        }
     }
+#endif
 }
 
 int main()

Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // basic_string<charT,traits,Allocator>&
@@ -25,34 +24,52 @@ template <class S>
 void
 test(S s, S str, typename S::size_type pos, typename S::size_type n, S expected)
 {
-    try
+    if (pos <= str.size())
     {
         s.append(str, pos, n);
         LIBCPP_ASSERT(s.__invariants());
-        assert(pos <= str.size());
         assert(s == expected);
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos > str.size());
+        try
+        {
+            s.append(str, pos, n);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos > str.size());
+        }
     }
+#endif
 }
 
 template <class S>
 void
 test_npos(S s, S str, typename S::size_type pos, S expected)
 {
-    try
+    if (pos <= str.size())
     {
         s.append(str, pos);
         LIBCPP_ASSERT(s.__invariants());
-        assert(pos <= str.size());
         assert(s == expected);
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos > str.size());
+        try
+        {
+            s.append(str, pos);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos > str.size());
+        }
     }
+#endif
 }
 
 int main()

Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // template <class T>
@@ -24,34 +23,52 @@ template <class S, class SV>
 void
 test(S s, SV sv, typename S::size_type pos, typename S::size_type n, S expected)
 {
-    try
+    if (pos <= sv.size())
     {
         s.assign(sv, pos, n);
         LIBCPP_ASSERT(s.__invariants());
-        assert(pos <= sv.size());
         assert(s == expected);
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos > sv.size());
+        try
+        {
+            s.assign(sv, pos, n);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos > sv.size());
+        }
     }
+#endif
 }
 
 template <class S, class SV>
 void
 test_npos(S s, SV sv, typename S::size_type pos, S expected)
 {
-    try
+    if (pos <= sv.size())
     {
         s.assign(sv, pos);
         LIBCPP_ASSERT(s.__invariants());
-        assert(pos <= sv.size());
         assert(s == expected);
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos > sv.size());
+        try
+        {
+            s.assign(sv, pos);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos > sv.size());
+        }
     }
+#endif
 }
 
 int main()

Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // basic_string<charT,traits,Allocator>&
@@ -25,34 +24,52 @@ template <class S>
 void
 test(S s, S str, typename S::size_type pos, typename S::size_type n, S expected)
 {
-    try
+    if (pos <= str.size())
     {
         s.assign(str, pos, n);
         LIBCPP_ASSERT(s.__invariants());
-        assert(pos <= str.size());
         assert(s == expected);
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos > str.size());
+        try
+        {
+            s.assign(str, pos, n);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos > str.size());
+        }
     }
+#endif
 }
 
 template <class S>
 void
 test_npos(S s, S str, typename S::size_type pos, S expected)
 {
-    try
+    if (pos <= str.size())
     {
         s.assign(str, pos);
         LIBCPP_ASSERT(s.__invariants());
-        assert(pos <= str.size());
         assert(s == expected);
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos > str.size());
+        try
+        {
+            s.assign(str, pos);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos > str.size());
+        }
     }
+#endif
 }
 
 int main()

Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // size_type copy(charT* s, size_type n, size_type pos = 0) const;
@@ -25,20 +24,29 @@ void
 test(S str, typename S::value_type* s, typename S::size_type n,
      typename S::size_type pos)
 {
-    try
+    const S& cs = str;
+    if (pos <= cs.size())
     {
-        const S& cs = str;
         typename S::size_type r = cs.copy(s, n, pos);
-        assert(pos <= cs.size());
         typename S::size_type rlen = std::min(n, cs.size() - pos);
         assert(r == rlen);
         for (r = 0; r < rlen; ++r)
             assert(S::traits_type::eq(cs[pos+r], s[r]));
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos > str.size());
+        try
+        {
+            typename S::size_type r = cs.copy(s, n, pos);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos > str.size());
+        }
     }
+#endif
 }
 
 int main()

Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp Tue Nov  1 10:46:16 2016
@@ -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>

Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_T_size_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_T_size_size.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_T_size_size.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_T_size_size.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // template <class T>
@@ -28,20 +27,29 @@ test(S s, typename S::size_type pos1, SV
      typename S::size_type n, S expected)
 {
     static_assert((!std::is_same<S, SV>::value), "");
-    typename S::size_type old_size = s.size();
+    const typename S::size_type old_size = s.size();
     S s0 = s;
-    try
+    if (pos1 <= old_size && pos2 <= sv.size())
     {
         s.insert(pos1, sv, pos2, n);
         LIBCPP_ASSERT(s.__invariants());
-        assert(pos1 <= old_size && pos2 <= sv.size());
         assert(s == expected);
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos1 > old_size || pos2 > sv.size());
-        assert(s == s0);
+        try
+        {
+            s.insert(pos1, sv, pos2, n);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos1 > old_size || pos2 > sv.size());
+            assert(s == s0);
+        }
     }
+#endif
 }
 
 template <class S, class SV>
@@ -49,20 +57,29 @@ void
 test_npos(S s, typename S::size_type pos1, SV sv, typename S::size_type pos2, S expected)
 {
     static_assert((!std::is_same<S, SV>::value), "");
-    typename S::size_type old_size = s.size();
+    const typename S::size_type old_size = s.size();
     S s0 = s;
-    try
+    if (pos1 <= old_size && pos2 <= sv.size())
     {
         s.insert(pos1, sv, pos2);
         LIBCPP_ASSERT(s.__invariants());
-        assert(pos1 <= old_size && pos2 <= sv.size());
         assert(s == expected);
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos1 > old_size || pos2 > sv.size());
-        assert(s == s0);
+        try
+        {
+            s.insert(pos1, sv, pos2);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos1 > old_size || pos2 > sv.size());
+            assert(s == s0);
+        }
     }
+#endif
 }
 
 

Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // basic_string<charT,traits,Allocator>&
@@ -24,20 +23,29 @@ template <class S>
 void
 test(S s, typename S::size_type pos, const typename S::value_type* str, 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.insert(pos, str);
         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.insert(pos, str);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos > old_size);
+            assert(s == s0);
+        }
     }
+#endif
 }
 
 int main()

Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // basic_string<charT,traits,Allocator>&
@@ -25,20 +24,29 @@ void
 test(S s, typename S::size_type pos, const typename S::value_type* str,
      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.insert(pos, str, 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.insert(pos, str, n);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos > old_size);
+            assert(s == s0);
+        }
     }
+#endif
 }
 
 int main()

Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // basic_string<charT,traits,Allocator>&
@@ -25,20 +24,29 @@ void
 test(S s, typename S::size_type pos, typename S::size_type n,
      typename S::value_type str, 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.insert(pos, n, str);
         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.insert(pos, n, str);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos > old_size);
+            assert(s == s0);
+        }
     }
+#endif
 }
 
 int main()

Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // basic_string<charT,traits,Allocator>&
@@ -24,20 +23,29 @@ template <class S>
 void
 test(S s, typename S::size_type pos, S str, 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.insert(pos, str);
         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.insert(pos, str);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos > old_size);
+            assert(s == s0);
+        }
     }
+#endif
 }
 
 int main()

Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_string_size_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_string_size_size.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_string_size_size.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_string_size_size.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // basic_string<charT,traits,Allocator>&
@@ -27,40 +26,58 @@ void
 test(S s, typename S::size_type pos1, S str, typename S::size_type pos2,
      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 (pos1 <= old_size && pos2 <= str.size())
     {
         s.insert(pos1, str, pos2, n);
         LIBCPP_ASSERT(s.__invariants());
-        assert(pos1 <= old_size && pos2 <= str.size());
         assert(s == expected);
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos1 > old_size || pos2 > str.size());
-        assert(s == s0);
+        try
+        {
+            s.insert(pos1, str, pos2, n);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos1 > old_size || pos2 > str.size());
+            assert(s == s0);
+        }
     }
+#endif
 }
 
 template <class S>
 void
 test_npos(S s, typename S::size_type pos1, S str, typename S::size_type pos2, S expected)
 {
-    typename S::size_type old_size = s.size();
+    const typename S::size_type old_size = s.size();
     S s0 = s;
-    try
+    if (pos1 <= old_size && pos2 <= str.size())
     {
         s.insert(pos1, str, pos2);
         LIBCPP_ASSERT(s.__invariants());
-        assert(pos1 <= old_size && pos2 <= str.size());
         assert(s == expected);
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos1 > old_size || pos2 > str.size());
-        assert(s == s0);
+        try
+        {
+            s.insert(pos1, str, pos2);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos1 > old_size || pos2 > str.size());
+            assert(s == s0);
+        }
     }
+#endif
 }
 
 

Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // template <class T>
@@ -31,23 +30,32 @@ test(S s, typename S::size_type pos1, ty
      S expected)
 {
     static_assert((!std::is_same<S, SV>::value), "");
-    typename S::size_type old_size = s.size();
+    const typename S::size_type old_size = s.size();
     S s0 = s;
-    try
+    if (pos1 <= old_size && pos2 <= sv.size())
     {
         s.replace(pos1, n1, sv, pos2, n2);
         LIBCPP_ASSERT(s.__invariants());
-        assert(pos1 <= old_size && pos2 <= sv.size());
         assert(s == expected);
         typename S::size_type xlen = std::min(n1, old_size - pos1);
         typename S::size_type rlen = std::min(n2, sv.size() - pos2);
         assert(s.size() == old_size - xlen + rlen);
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos1 > old_size || pos2 > sv.size());
-        assert(s == s0);
+        try
+        {
+            s.replace(pos1, n1, sv, pos2, n2);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos1 > old_size || pos2 > sv.size());
+            assert(s == s0);
+        }
     }
+#endif
 }
 
 template <class S, class SV>
@@ -57,23 +65,32 @@ test_npos(S s, typename S::size_type pos
           S expected)
 {
     static_assert((!std::is_same<S, SV>::value), "");
-    typename S::size_type old_size = s.size();
+    const typename S::size_type old_size = s.size();
     S s0 = s;
-    try
+    if (pos1 <= old_size && pos2 <= sv.size())
     {
         s.replace(pos1, n1, sv, pos2);
         LIBCPP_ASSERT(s.__invariants());
-        assert(pos1 <= old_size && pos2 <= sv.size());
         assert(s == expected);
         typename S::size_type xlen = std::min(n1, old_size - pos1);
         typename S::size_type rlen = std::min(S::npos, sv.size() - pos2);
         assert(s.size() == old_size - xlen + rlen);
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos1 > old_size || pos2 > sv.size());
-        assert(s == s0);
+        try
+        {
+            s.replace(pos1, n1, sv, pos2);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos1 > old_size || pos2 > sv.size());
+            assert(s == s0);
+        }
     }
+#endif
 }
 
 

Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // basic_string<charT,traits,Allocator>&
@@ -26,23 +25,32 @@ void
 test(S s, typename S::size_type pos, typename S::size_type n1,
      const typename S::value_type* str, 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.replace(pos, n1, str);
         LIBCPP_ASSERT(s.__invariants());
-        assert(pos <= old_size);
         assert(s == expected);
         typename S::size_type xlen = std::min(n1, old_size - pos);
         typename S::size_type rlen = S::traits_type::length(str);
         assert(s.size() == old_size - xlen + rlen);
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos > old_size);
-        assert(s == s0);
+        try
+        {
+            s.replace(pos, n1, str);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos > old_size);
+            assert(s == s0);
+        }
     }
+#endif
 }
 
 template <class S>

Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // basic_string<charT,traits,Allocator>&
@@ -27,23 +26,32 @@ test(S s, typename S::size_type pos, typ
      const typename S::value_type* str, typename S::size_type n2,
      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.replace(pos, n1, str, n2);
         LIBCPP_ASSERT(s.__invariants());
-        assert(pos <= old_size);
         assert(s == expected);
         typename S::size_type xlen = std::min(n1, old_size - pos);
         typename S::size_type rlen = n2;
         assert(s.size() == old_size - xlen + rlen);
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos > old_size);
-        assert(s == s0);
+        try
+        {
+            s.replace(pos, n1, str, n2);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos > old_size);
+            assert(s == s0);
+        }
     }
+#endif
 }
 
 template <class S>

Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // basic_string<charT,traits,Allocator>&
@@ -27,23 +26,32 @@ test(S s, typename S::size_type pos, typ
      typename S::size_type n2, typename S::value_type c,
      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.replace(pos, n1, n2, c);
         LIBCPP_ASSERT(s.__invariants());
-        assert(pos <= old_size);
         assert(s == expected);
         typename S::size_type xlen = std::min(n1, old_size - pos);
         typename S::size_type rlen = n2;
         assert(s.size() == old_size - xlen + rlen);
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos > old_size);
-        assert(s == s0);
+        try
+        {
+            s.replace(pos, n1, n2, c);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos > old_size);
+            assert(s == s0);
+        }
     }
+#endif
 }
 
 template <class S>

Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // basic_string<charT,traits,Allocator>&
@@ -25,23 +24,32 @@ template <class S>
 void
 test(S s, typename S::size_type pos1, typename S::size_type n1, S str, S expected)
 {
-    typename S::size_type old_size = s.size();
+    const typename S::size_type old_size = s.size();
     S s0 = s;
-    try
+    if (pos1 <= old_size)
     {
         s.replace(pos1, n1, str);
         LIBCPP_ASSERT(s.__invariants());
-        assert(pos1 <= old_size);
         assert(s == expected);
         typename S::size_type xlen = std::min(n1, old_size - pos1);
         typename S::size_type rlen = str.size();
         assert(s.size() == old_size - xlen + rlen);
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos1 > old_size);
-        assert(s == s0);
+        try
+        {
+            s.replace(pos1, n1, str);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos1 > old_size);
+            assert(s == s0);
+        }
     }
+#endif
 }
 
 template <class S>

Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // basic_string<charT,traits,Allocator>&
@@ -29,23 +28,32 @@ test(S s, typename S::size_type pos1, ty
      S str, typename S::size_type pos2, typename S::size_type n2,
      S expected)
 {
-    typename S::size_type old_size = s.size();
+    const typename S::size_type old_size = s.size();
     S s0 = s;
-    try
+    if (pos1 <= old_size && pos2 <= str.size())
     {
         s.replace(pos1, n1, str, pos2, n2);
         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(n2, str.size() - pos2);
         assert(s.size() == old_size - xlen + rlen);
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos1 > old_size || pos2 > str.size());
-        assert(s == s0);
+        try
+        {
+            s.replace(pos1, n1, str, pos2, n2);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos1 > old_size || pos2 > str.size());
+            assert(s == s0);
+        }
     }
+#endif
 }
 
 template <class S>
@@ -54,23 +62,32 @@ test_npos(S s, typename S::size_type pos
      S str, typename S::size_type pos2,
      S expected)
 {
-    typename S::size_type old_size = s.size();
+    const typename S::size_type old_size = s.size();
     S s0 = s;
-    try
+    if (pos1 <= old_size && pos2 <= str.size())
     {
         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&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos1 > old_size || pos2 > str.size());
-        assert(s == s0);
+        try
+        {
+            s.replace(pos1, n1, str, pos2);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos1 > old_size || pos2 > str.size());
+            assert(s == s0);
+        }
     }
+#endif
 }
 
 

Modified: libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp Tue Nov  1 10:46:16 2016
@@ -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 p
      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_t
           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>

Modified: libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // int compare(size_type pos, size_type n1, const charT *s) const;
@@ -18,6 +17,8 @@
 
 #include "min_allocator.h"
 
+#include "test_macros.h"
+
 int sign(int x)
 {
     if (x == 0)
@@ -32,15 +33,22 @@ void
 test(const S& s, typename S::size_type pos1, typename S::size_type n1,
      const typename S::value_type* str, int x)
 {
-    try
-    {
+    if (pos1 <= s.size())
         assert(sign(s.compare(pos1, n1, str)) == sign(x));
-        assert(pos1 <= s.size());
-    }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos1 > s.size());
+        try
+        {
+            s.compare(pos1, n1, str);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos1 > s.size());
+        }
     }
+#endif
 }
 
 template <class S>

Modified: libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer_size.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer_size.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_pointer_size.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // int compare(size_type pos, size_type n1, const charT *s, size_type n2) const;
@@ -18,6 +17,8 @@
 
 #include "min_allocator.h"
 
+#include "test_macros.h"
+
 int sign(int x)
 {
     if (x == 0)
@@ -32,15 +33,22 @@ void
 test(const S& s, typename S::size_type pos, typename S::size_type n1,
      const typename S::value_type* str, typename S::size_type n2, int x)
 {
-    try
-    {
+    if (pos <= s.size())
         assert(sign(s.compare(pos, n1, str, n2)) == sign(x));
-        assert(pos <= s.size());
-    }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos > s.size());
+        try
+        {
+            s.compare(pos, n1, str, n2);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos > s.size());
+        }
     }
+#endif
 }
 
 template <class S>

Modified: libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // int compare(size_type pos1, size_type n1, const basic_string& str) const;
@@ -18,6 +17,8 @@
 
 #include "min_allocator.h"
 
+#include "test_macros.h"
+
 int sign(int x)
 {
     if (x == 0)
@@ -32,15 +33,22 @@ void
 test(const S& s, typename S::size_type pos1, typename S::size_type n1,
      const S& str, int x)
 {
-    try
-    {
+    if (pos1 <= s.size())
         assert(sign(s.compare(pos1, n1, str)) == sign(x));
-        assert(pos1 <= s.size());
-    }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos1 > s.size());
+        try
+        {
+            s.compare(pos1, n1, str);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos1 > s.size());
+        }
     }
+#endif
 }
 
 template <class S>

Modified: libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp?rev=285697&r1=285696&r2=285697&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp Tue Nov  1 10:46:16 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // int compare(size_type pos1, size_type n1, const basic_string& str,
@@ -20,6 +19,8 @@
 
 #include "min_allocator.h"
 
+#include "test_macros.h"
+
 int sign(int x)
 {
     if (x == 0)
@@ -34,16 +35,22 @@ void
 test(const S& s,   typename S::size_type pos1, typename S::size_type n1,
      const S& str, typename S::size_type pos2, typename S::size_type n2, int x)
 {
-    try
-    {
+    if (pos1 <= s.size() && pos2 <= str.size())
         assert(sign(s.compare(pos1, n1, str, pos2, n2)) == sign(x));
-        assert(pos1 <= s.size());
-        assert(pos2 <= str.size());
-    }
-    catch (const std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos1 > s.size() || pos2 > str.size());
+        try
+        {
+            s.compare(pos1, n1, str, pos2, n2);
+            assert(false);
+        }
+        catch (const std::out_of_range&)
+        {
+            assert(pos1 > s.size() || pos2 > str.size());
+        }
     }
+#endif
 }
 
 template <class S>
@@ -51,16 +58,22 @@ void
 test_npos(const S& s,   typename S::size_type pos1, typename S::size_type n1,
           const S& str, typename S::size_type pos2, int x)
 {
-    try
-    {
+    if (pos1 <= s.size() && pos2 <= str.size())
         assert(sign(s.compare(pos1, n1, str, pos2)) == sign(x));
-        assert(pos1 <= s.size());
-        assert(pos2 <= str.size());
-    }
-    catch (const std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos1 > s.size() || pos2 > str.size());
+        try
+        {
+            s.compare(pos1, n1, str, pos2);
+            assert(false);
+        }
+        catch (const std::out_of_range&)
+        {
+            assert(pos1 > s.size() || pos2 > str.size());
+        }
     }
+#endif
 }
 
 template <class S>




More information about the cfe-commits mailing list