[libcxx] r288158 - Protect std::string tests under libcpp-no-exceptions

Roger Ferrer Ibanez via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 29 08:40:19 PST 2016


Author: rogfer01
Date: Tue Nov 29 10:40:19 2016
New Revision: 288158

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


Modified:
    libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp

Modified: libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp?rev=288158&r1=288157&r2=288158&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp Tue Nov 29 10:40:19 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // size_type capacity() const;
@@ -18,21 +17,27 @@
 #include "test_allocator.h"
 #include "min_allocator.h"
 
+#include "test_macros.h"
+
 template <class S>
 void
 test(S s)
 {
     S::allocator_type::throw_after = 0;
+#ifndef TEST_HAS_NO_EXCEPTIONS
     try
+#endif
     {
         while (s.size() < s.capacity())
             s.push_back(typename S::value_type());
         assert(s.size() == s.capacity());
     }
+#ifndef TEST_HAS_NO_EXCEPTIONS
     catch (...)
     {
         assert(false);
     }
+#endif
     S::allocator_type::throw_after = INT_MAX;
 }
 

Modified: libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp?rev=288158&r1=288157&r2=288158&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp Tue Nov 29 10:40:19 2016
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// XFAIL: libcpp-no-exceptions
 // <string>
 
 // basic_string substr(size_type pos = 0, size_type n = npos) const;
@@ -24,7 +23,7 @@ template <class S>
 void
 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);
         LIBCPP_ASSERT(str.__invariants());
@@ -33,10 +32,20 @@ test(const S& s, typename S::size_type p
         assert(str.size() == rlen);
         assert(S::traits_type::compare(s.data()+pos, str.data(), rlen) == 0);
     }
-    catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+    else
     {
-        assert(pos > s.size());
+        try
+        {
+            S str = s.substr(pos, n);
+            assert(false);
+        }
+        catch (std::out_of_range&)
+        {
+            assert(pos > s.size());
+        }
     }
+#endif
 }
 
 int main()




More information about the cfe-commits mailing list