rogfer01 created this revision.
rogfer01 added reviewers: EricWF, mclow.lists, rmaprath.
rogfer01 added a subscriber: cfe-commits.
This is another followup of https://reviews.llvm.org/D24562
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.
https://reviews.llvm.org/D26136
Files:
test/std/strings/basic.string/string.access/at.pass.cpp
test/std/strings/basic.string/string.capacity/reserve.pass.cpp
test/std/strings/basic.string/string.capacity/resize_size.pass.cpp
test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp
test/std/strings/basic.string/string.cons/substr.pass.cpp
test/std/strings/basic.string/string.modifiers/string_append/T_size_size.pass.cpp
test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp
test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp
test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp
test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp
test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp
test/std/strings/basic.string/string.modifiers/string_insert/size_T_size_size.pass.cpp
test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp
test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp
test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp
test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp
test/std/strings/basic.string/string.modifiers/string_insert/size_string_size_size.pass.cpp
test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp
test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp
test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp
test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp
test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp
test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp
test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp
test/std/strings/basic.string/string.ops/string_compare/size_size_pointer.pass.cpp
test/std/strings/basic.string/string.ops/string_compare/size_size_pointer_size.pass.cpp
test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp
test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp
Index: test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp
+++ test/std/strings/basic.string/string.ops/string_compare/size_size_string_size_size.pass.cpp
@@ -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,6 +35,7 @@
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)
{
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
assert(sign(s.compare(pos1, n1, str, pos2, n2)) == sign(x));
@@ -44,13 +46,18 @@
{
assert(pos1 > s.size() || pos2 > str.size());
}
+#else
+ if (pos1 <= s.size() && pos2 <= str.size())
+ assert(sign(s.compare(pos1, n1, str, pos2, n2)) == sign(x));
+#endif
}
template <class S>
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)
{
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
assert(sign(s.compare(pos1, n1, str, pos2)) == sign(x));
@@ -61,6 +68,10 @@
{
assert(pos1 > s.size() || pos2 > str.size());
}
+#else
+ if (pos1 <= s.size() && pos2 <= str.size())
+ assert(sign(s.compare(pos1, n1, str, pos2)) == sign(x));
+#endif
}
template <class S>
Index: test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp
+++ test/std/strings/basic.string/string.ops/string_compare/size_size_string.pass.cpp
@@ -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,6 +33,7 @@
test(const S& s, typename S::size_type pos1, typename S::size_type n1,
const S& str, int x)
{
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
assert(sign(s.compare(pos1, n1, str)) == sign(x));
@@ -41,6 +43,10 @@
{
assert(pos1 > s.size());
}
+#else
+ if (pos1 <= s.size())
+ assert(sign(s.compare(pos1, n1, str)) == sign(x));
+#endif
}
template <class S>
Index: test/std/strings/basic.string/string.ops/string_compare/size_size_pointer_size.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.ops/string_compare/size_size_pointer_size.pass.cpp
+++ test/std/strings/basic.string/string.ops/string_compare/size_size_pointer_size.pass.cpp
@@ -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,6 +33,7 @@
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)
{
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
assert(sign(s.compare(pos, n1, str, n2)) == sign(x));
@@ -41,6 +43,10 @@
{
assert(pos > s.size());
}
+#else
+ if (pos <= s.size())
+ assert(sign(s.compare(pos, n1, str, n2)) == sign(x));
+#endif
}
template <class S>
Index: test/std/strings/basic.string/string.ops/string_compare/size_size_pointer.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.ops/string_compare/size_size_pointer.pass.cpp
+++ test/std/strings/basic.string/string.ops/string_compare/size_size_pointer.pass.cpp
@@ -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,6 +33,7 @@
test(const S& s, typename S::size_type pos1, typename S::size_type n1,
const typename S::value_type* str, int x)
{
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
assert(sign(s.compare(pos1, n1, str)) == sign(x));
@@ -41,6 +43,10 @@
{
assert(pos1 > s.size());
}
+#else
+ if (pos1 <= s.size())
+ assert(sign(s.compare(pos1, n1, str)) == sign(x));
+#endif
}
template <class S>
Index: test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp
+++ 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,6 +38,7 @@
SV sv, typename S::size_type pos2, typename S::size_type n2, int x)
{
static_assert((!std::is_same<S, SV>::value), "");
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
assert(sign(s.compare(pos1, n1, sv, pos2, n2)) == sign(x));
@@ -47,14 +49,19 @@
{
assert(pos1 > s.size() || pos2 > sv.size());
}
+#else
+ if (pos1 <= s.size() && pos2 <= sv.size())
+ assert(sign(s.compare(pos1, n1, sv, pos2, n2)) == sign(x));
+#endif
}
template <class S, class SV>
void
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), "");
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
assert(sign(s.compare(pos1, n1, sv, pos2)) == sign(x));
@@ -65,6 +72,10 @@
{
assert(pos1 > s.size() || pos2 > sv.size());
}
+#else
+ if (pos1 <= s.size() && pos2 <= sv.size())
+ assert(sign(s.compare(pos1, n1, sv, pos2)) == sign(x));
+#endif
}
template <class S, class SV>
Index: test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp
+++ test/std/strings/basic.string/string.modifiers/string_replace/size_size_string_size_size.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// basic_string<charT,traits,Allocator>&
@@ -31,6 +30,7 @@
{
typename S::size_type old_size = s.size();
S s0 = s;
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.replace(pos1, n1, str, pos2, n2);
@@ -46,6 +46,17 @@
assert(pos1 > old_size || pos2 > str.size());
assert(s == s0);
}
+#else
+ if (pos1 <= old_size && pos2 <= str.size())
+ {
+ s.replace(pos1, n1, str, pos2, n2);
+ LIBCPP_ASSERT(s.__invariants());
+ 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);
+ }
+#endif
}
template <class S>
@@ -56,6 +67,7 @@
{
typename S::size_type old_size = s.size();
S s0 = s;
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.replace(pos1, n1, str, pos2);
@@ -71,6 +83,17 @@
assert(pos1 > old_size || pos2 > str.size());
assert(s == s0);
}
+#else
+ if (pos1 <= old_size && pos2 <= str.size())
+ {
+ s.replace(pos1, n1, str, pos2);
+ LIBCPP_ASSERT(s.__invariants());
+ 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);
+ }
+#endif
}
Index: test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp
+++ test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// basic_string<charT,traits,Allocator>&
@@ -27,6 +26,7 @@
{
typename S::size_type old_size = s.size();
S s0 = s;
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.replace(pos1, n1, str);
@@ -42,6 +42,17 @@
assert(pos1 > old_size);
assert(s == s0);
}
+#else
+ if (pos1 <= old_size)
+ {
+ s.replace(pos1, n1, str);
+ LIBCPP_ASSERT(s.__invariants());
+ 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);
+ }
+#endif
}
template <class S>
Index: test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp
+++ test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// basic_string<charT,traits,Allocator>&
@@ -29,6 +28,7 @@
{
typename S::size_type old_size = s.size();
S s0 = s;
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.replace(pos, n1, n2, c);
@@ -44,6 +44,17 @@
assert(pos > old_size);
assert(s == s0);
}
+#else
+ if (pos <= old_size)
+ {
+ s.replace(pos, n1, n2, c);
+ LIBCPP_ASSERT(s.__invariants());
+ 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);
+ }
+#endif
}
template <class S>
Index: test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp
+++ test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// basic_string<charT,traits,Allocator>&
@@ -29,6 +28,7 @@
{
typename S::size_type old_size = s.size();
S s0 = s;
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.replace(pos, n1, str, n2);
@@ -44,6 +44,17 @@
assert(pos > old_size);
assert(s == s0);
}
+#else
+ if (pos <= old_size)
+ {
+ s.replace(pos, n1, str, n2);
+ LIBCPP_ASSERT(s.__invariants());
+ 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);
+ }
+#endif
}
template <class S>
Index: test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp
+++ test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// basic_string<charT,traits,Allocator>&
@@ -28,6 +27,7 @@
{
typename S::size_type old_size = s.size();
S s0 = s;
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.replace(pos, n1, str);
@@ -43,6 +43,17 @@
assert(pos > old_size);
assert(s == s0);
}
+#else
+ if (pos <= old_size)
+ {
+ s.replace(pos, n1, str);
+ LIBCPP_ASSERT(s.__invariants());
+ 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);
+ }
+#endif
}
template <class S>
Index: test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp
+++ test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// template <class T>
@@ -33,6 +32,7 @@
static_assert((!std::is_same<S, SV>::value), "");
typename S::size_type old_size = s.size();
S s0 = s;
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.replace(pos1, n1, sv, pos2, n2);
@@ -48,6 +48,17 @@
assert(pos1 > old_size || pos2 > sv.size());
assert(s == s0);
}
+#else
+ if (pos1 <= old_size && pos2 <= sv.size())
+ {
+ s.replace(pos1, n1, sv, pos2, n2);
+ LIBCPP_ASSERT(s.__invariants());
+ 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);
+ }
+#endif
}
template <class S, class SV>
@@ -59,6 +70,7 @@
static_assert((!std::is_same<S, SV>::value), "");
typename S::size_type old_size = s.size();
S s0 = s;
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.replace(pos1, n1, sv, pos2);
@@ -74,6 +86,17 @@
assert(pos1 > old_size || pos2 > sv.size());
assert(s == s0);
}
+#else
+ if (pos1 <= old_size && pos2 <= sv.size())
+ {
+ s.replace(pos1, n1, sv, pos2);
+ LIBCPP_ASSERT(s.__invariants());
+ 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);
+ }
+#endif
}
Index: test/std/strings/basic.string/string.modifiers/string_insert/size_string_size_size.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.modifiers/string_insert/size_string_size_size.pass.cpp
+++ test/std/strings/basic.string/string.modifiers/string_insert/size_string_size_size.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// basic_string<charT,traits,Allocator>&
@@ -29,6 +28,7 @@
{
typename S::size_type old_size = s.size();
S s0 = s;
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.insert(pos1, str, pos2, n);
@@ -41,14 +41,23 @@
assert(pos1 > old_size || pos2 > str.size());
assert(s == s0);
}
+#else
+ if (pos1 <= old_size && pos2 <= str.size())
+ {
+ s.insert(pos1, str, pos2, n);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ }
+#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();
S s0 = s;
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.insert(pos1, str, pos2);
@@ -61,6 +70,14 @@
assert(pos1 > old_size || pos2 > str.size());
assert(s == s0);
}
+#else
+ if (pos1 <= old_size && pos2 <= str.size())
+ {
+ s.insert(pos1, str, pos2);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ }
+#endif
}
Index: test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp
+++ test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// basic_string<charT,traits,Allocator>&
@@ -26,6 +25,7 @@
{
typename S::size_type old_size = s.size();
S s0 = s;
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.insert(pos, str);
@@ -38,6 +38,14 @@
assert(pos > old_size);
assert(s == s0);
}
+#else
+ if (pos <= old_size)
+ {
+ s.insert(pos, str);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ }
+#endif
}
int main()
Index: test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp
+++ test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// basic_string<charT,traits,Allocator>&
@@ -27,6 +26,7 @@
{
typename S::size_type old_size = s.size();
S s0 = s;
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.insert(pos, n, str);
@@ -39,6 +39,14 @@
assert(pos > old_size);
assert(s == s0);
}
+#else
+ if (pos <= old_size)
+ {
+ s.insert(pos, n, str);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ }
+#endif
}
int main()
Index: test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp
+++ test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// basic_string<charT,traits,Allocator>&
@@ -27,6 +26,7 @@
{
typename S::size_type old_size = s.size();
S s0 = s;
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.insert(pos, str, n);
@@ -39,6 +39,14 @@
assert(pos > old_size);
assert(s == s0);
}
+#else
+ if (pos <= old_size)
+ {
+ s.insert(pos, str, n);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ }
+#endif
}
int main()
Index: test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp
+++ test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// basic_string<charT,traits,Allocator>&
@@ -26,6 +25,7 @@
{
typename S::size_type old_size = s.size();
S s0 = s;
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.insert(pos, str);
@@ -38,6 +38,14 @@
assert(pos > old_size);
assert(s == s0);
}
+#else
+ if (pos <= old_size)
+ {
+ s.insert(pos, str);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ }
+#endif
}
int main()
Index: test/std/strings/basic.string/string.modifiers/string_insert/size_T_size_size.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.modifiers/string_insert/size_T_size_size.pass.cpp
+++ test/std/strings/basic.string/string.modifiers/string_insert/size_T_size_size.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// template <class T>
@@ -30,6 +29,7 @@
static_assert((!std::is_same<S, SV>::value), "");
typename S::size_type old_size = s.size();
S s0 = s;
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.insert(pos1, sv, pos2, n);
@@ -42,6 +42,14 @@
assert(pos1 > old_size || pos2 > sv.size());
assert(s == s0);
}
+#else
+ if (pos1 <= old_size && pos2 <= sv.size())
+ {
+ s.insert(pos1, sv, pos2, n);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ }
+#endif
}
template <class S, class SV>
@@ -51,6 +59,7 @@
static_assert((!std::is_same<S, SV>::value), "");
typename S::size_type old_size = s.size();
S s0 = s;
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.insert(pos1, sv, pos2);
@@ -63,6 +72,14 @@
assert(pos1 > old_size || pos2 > sv.size());
assert(s == s0);
}
+#else
+ if (pos1 <= old_size && pos2 <= sv.size())
+ {
+ s.insert(pos1, sv, pos2);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ }
+#endif
}
Index: test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp
+++ test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// basic_string<charT,traits,Allocator>&
@@ -26,6 +25,7 @@
{
typename S::size_type old_size = s.size();
S s0 = s;
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.erase(pos, n);
@@ -38,14 +38,23 @@
assert(pos > old_size);
assert(s == s0);
}
+#else
+ if (pos <= old_size)
+ {
+ s.erase(pos, n);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ }
+#endif
}
template <class S>
void
test(S s, typename S::size_type pos, S expected)
{
typename S::size_type old_size = s.size();
S s0 = s;
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.erase(pos);
@@ -58,6 +67,14 @@
assert(pos > old_size);
assert(s == s0);
}
+#else
+ if (pos <= old_size)
+ {
+ s.erase(pos);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ }
+#endif
}
template <class S>
Index: test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp
+++ test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// size_type copy(charT* s, size_type n, size_type pos = 0) const;
@@ -25,6 +24,7 @@
test(S str, typename S::value_type* s, typename S::size_type n,
typename S::size_type pos)
{
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
const S& cs = str;
@@ -39,6 +39,17 @@
{
assert(pos > str.size());
}
+#else
+ const S& cs = str;
+ if (pos <= cs.size())
+ {
+ typename S::size_type r = cs.copy(s, n, pos);
+ 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]));
+ }
+#endif
}
int main()
Index: test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp
+++ test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// basic_string<charT,traits,Allocator>&
@@ -25,6 +24,7 @@
void
test(S s, S str, typename S::size_type pos, typename S::size_type n, S expected)
{
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.assign(str, pos, n);
@@ -36,12 +36,21 @@
{
assert(pos > str.size());
}
+#else
+ if (pos <= str.size())
+ {
+ s.assign(str, pos, n);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ }
+#endif
}
template <class S>
void
test_npos(S s, S str, typename S::size_type pos, S expected)
{
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.assign(str, pos);
@@ -53,6 +62,14 @@
{
assert(pos > str.size());
}
+#else
+ if (pos <= str.size())
+ {
+ s.assign(str, pos);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ }
+#endif
}
int main()
Index: test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp
+++ test/std/strings/basic.string/string.modifiers/string_assign/T_size_size.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// template <class T>
@@ -24,6 +23,7 @@
void
test(S s, SV sv, typename S::size_type pos, typename S::size_type n, S expected)
{
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.assign(sv, pos, n);
@@ -35,12 +35,21 @@
{
assert(pos > sv.size());
}
+#else
+ if (pos <= sv.size())
+ {
+ s.assign(sv, pos, n);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ }
+#endif
}
template <class S, class SV>
void
test_npos(S s, SV sv, typename S::size_type pos, S expected)
{
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.assign(sv, pos);
@@ -52,6 +61,14 @@
{
assert(pos > sv.size());
}
+#else
+ if (pos <= sv.size())
+ {
+ s.assign(sv, pos);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ }
+#endif
}
int main()
Index: test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp
+++ test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// basic_string<charT,traits,Allocator>&
@@ -25,6 +24,7 @@
void
test(S s, S str, typename S::size_type pos, typename S::size_type n, S expected)
{
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.append(str, pos, n);
@@ -36,12 +36,21 @@
{
assert(pos > str.size());
}
+#else
+ if (pos <= str.size())
+ {
+ s.append(str, pos, n);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ }
+#endif
}
template <class S>
void
test_npos(S s, S str, typename S::size_type pos, S expected)
{
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.append(str, pos);
@@ -53,6 +62,14 @@
{
assert(pos > str.size());
}
+#else
+ if (pos <= str.size())
+ {
+ s.append(str, pos);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ }
+#endif
}
int main()
Index: test/std/strings/basic.string/string.modifiers/string_append/T_size_size.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.modifiers/string_append/T_size_size.pass.cpp
+++ test/std/strings/basic.string/string.modifiers/string_append/T_size_size.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// template <class T>
@@ -25,6 +24,7 @@
void
test(S s, SV sv, typename S::size_type pos, typename S::size_type n, S expected)
{
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.append(sv, pos, n);
@@ -36,12 +36,21 @@
{
assert(pos > sv.size());
}
+#else
+ if (pos <= sv.size())
+ {
+ s.append(sv, pos, n);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ }
+#endif
}
template <class S, class SV>
void
test_npos(S s, SV sv, typename S::size_type pos, S expected)
{
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.append(sv, pos);
@@ -53,6 +62,14 @@
{
assert(pos > sv.size());
}
+#else
+ if (pos <= sv.size())
+ {
+ s.append(sv, pos);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ }
+#endif
}
int main()
Index: test/std/strings/basic.string/string.cons/substr.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.cons/substr.pass.cpp
+++ test/std/strings/basic.string/string.cons/substr.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// basic_string(const basic_string<charT,traits,Allocator>& str,
@@ -35,6 +34,7 @@
{
typedef typename S::traits_type T;
typedef typename S::allocator_type A;
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
S s2(str, pos);
@@ -50,14 +50,27 @@
{
assert(pos > str.size());
}
+#else
+ if (pos <= str.size())
+ {
+ S s2(str, pos);
+ LIBCPP_ASSERT(s2.__invariants());
+ 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());
+ }
+#endif
}
template <class S>
void
test(S str, unsigned pos, unsigned n)
{
typedef typename S::traits_type T;
typedef typename S::allocator_type A;
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
S s2(str, pos, n);
@@ -73,14 +86,27 @@
{
assert(pos > str.size());
}
+#else
+ if (pos <= str.size())
+ {
+ S s2(str, pos, n);
+ LIBCPP_ASSERT(s2.__invariants());
+ 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());
+ }
+#endif
}
template <class S>
void
test(S str, unsigned pos, unsigned n, const typename S::allocator_type& a)
{
typedef typename S::traits_type T;
typedef typename S::allocator_type A;
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
S s2(str, pos, n, a);
@@ -96,9 +122,22 @@
{
assert(pos > str.size());
}
+#else
+ if (pos <= str.size())
+ {
+ S s2(str, pos, n, a);
+ LIBCPP_ASSERT(s2.__invariants());
+ 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());
+ }
+#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 +150,7 @@
assert(false);
}
#endif
+#endif
int main()
{
@@ -192,6 +232,8 @@
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 100, A());
}
+#ifndef TEST_HAS_NO_EXCEPTIONS
test2583();
#endif
+#endif
}
Index: test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp
+++ test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// void resize(size_type n, charT c);
@@ -23,6 +22,7 @@
void
test(S s, typename S::size_type n, typename S::value_type c, S expected)
{
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.resize(n, c);
@@ -34,6 +34,14 @@
{
assert(n > s.max_size());
}
+#else
+ if (n <= s.max_size())
+ {
+ s.resize(n, c);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ }
+#endif
}
int main()
Index: test/std/strings/basic.string/string.capacity/resize_size.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.capacity/resize_size.pass.cpp
+++ test/std/strings/basic.string/string.capacity/resize_size.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// void resize(size_type n);
@@ -23,6 +22,7 @@
void
test(S s, typename S::size_type n, S expected)
{
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.resize(n);
@@ -34,6 +34,14 @@
{
assert(n > s.max_size());
}
+#else
+ if (n <= s.max_size())
+ {
+ s.resize(n);
+ LIBCPP_ASSERT(s.__invariants());
+ assert(s == expected);
+ }
+#endif
}
int main()
Index: test/std/strings/basic.string/string.capacity/reserve.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.capacity/reserve.pass.cpp
+++ test/std/strings/basic.string/string.capacity/reserve.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// void reserve(size_type res_arg=0);
@@ -38,6 +37,7 @@
{
typename S::size_type old_cap = s.capacity();
S s0 = s;
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
s.reserve(res_arg);
@@ -50,6 +50,15 @@
{
assert(res_arg > s.max_size());
}
+#else
+ if (res_arg <= s.max_size())
+ {
+ s.reserve(res_arg);
+ assert(s == s0);
+ assert(s.capacity() >= res_arg);
+ assert(s.capacity() >= s.size());
+ }
+#endif
}
int main()
Index: test/std/strings/basic.string/string.access/at.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.access/at.pass.cpp
+++ test/std/strings/basic.string/string.access/at.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string>
// const_reference at(size_type pos) const;
@@ -19,10 +18,13 @@
#include "min_allocator.h"
+#include "test_macros.h"
+
template <class S>
void
test(S s, typename S::size_type pos)
{
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
const S& cs = s;
@@ -34,6 +36,15 @@
{
assert(pos >= s.size());
}
+#else
+ const S& cs = s;
+ if (pos < cs.size())
+ {
+ assert(s.at(pos) == s[pos]);
+ assert(cs.at(pos) == cs[pos]);
+ assert(pos < cs.size());
+ }
+#endif
}
int main()
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits