Make string_view work with -fno-exceptions and get tests passing.
llvm-svn: 271237
diff --git a/libcxx/test/std/experimental/string.view/string.view.access/at.pass.cpp b/libcxx/test/std/experimental/string.view/string.view.access/at.pass.cpp
index 46804d4..af35f54 100644
--- a/libcxx/test/std/experimental/string.view/string.view.access/at.pass.cpp
+++ b/libcxx/test/std/experimental/string.view/string.view.access/at.pass.cpp
@@ -10,7 +10,7 @@
// NOTE: Older versions of clang have a bug where they fail to evalute
// string_view::at as a constant expression.
// XFAIL: clang-3.4, clang-3.3
-// XFAIL: libcpp-no-exceptions
+
// <string_view>
@@ -20,6 +20,8 @@
#include <stdexcept>
#include <cassert>
+#include "test_macros.h"
+
template <typename CharT>
void test ( const CharT *s, size_t len ) {
std::experimental::basic_string_view<CharT> sv ( s, len );
@@ -27,11 +29,13 @@
for ( size_t i = 0; i < len; ++i ) {
assert ( sv.at(i) == s[i] );
assert ( &sv.at(i) == s + i );
- }
+ }
+#ifndef TEST_HAS_NO_EXCEPTIONS
try { sv.at(len); } catch ( const std::out_of_range & ) { return ; }
assert ( false );
- }
+#endif
+}
int main () {
test ( "ABCDE", 5 );
@@ -40,7 +44,7 @@
test ( L"ABCDE", 5 );
test ( L"a", 1 );
-#if __cplusplus >= 201103L
+#if TEST_STD_VER >= 11
test ( u"ABCDE", 5 );
test ( u"a", 1 );
@@ -48,7 +52,7 @@
test ( U"a", 1 );
#endif
-#if __cplusplus >= 201103L
+#if TEST_STD_VER >= 11
{
constexpr std::experimental::basic_string_view<char> sv ( "ABC", 2 );
static_assert ( sv.length() == 2, "" );
diff --git a/libcxx/test/std/experimental/string.view/string.view.comparison/opeq.string_view.string.pass.cpp b/libcxx/test/std/experimental/string.view/string.view.comparison/opeq.string_view.string.pass.cpp
index c2227cf..1fd72d7 100644
--- a/libcxx/test/std/experimental/string.view/string.view.comparison/opeq.string_view.string.pass.cpp
+++ b/libcxx/test/std/experimental/string.view/string.view.comparison/opeq.string_view.string.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// UNSUPPORTED: c++98, c++03, c++11
// <string>
// template<class charT, class traits, class Allocator>
diff --git a/libcxx/test/std/experimental/string.view/string.view.ops/compare.pointer_size.pass.cpp b/libcxx/test/std/experimental/string.view/string.view.ops/compare.pointer_size.pass.cpp
index 7ccbd52..3b6a8a6 100644
--- a/libcxx/test/std/experimental/string.view/string.view.ops/compare.pointer_size.pass.cpp
+++ b/libcxx/test/std/experimental/string.view/string.view.ops/compare.pointer_size.pass.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: libcpp-no-exceptions
// <string_view>
// constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
@@ -15,6 +14,7 @@
#include <experimental/string_view>
#include <cassert>
+#include "test_macros.h"
#include "constexpr_char_traits.hpp"
int sign ( int x ) { return x > 0 ? 1 : ( x < 0 ? -1 : 0 ); }
@@ -22,11 +22,19 @@
template<typename CharT>
void test1 ( std::experimental::basic_string_view<CharT> sv1,
size_t pos1, size_t n1, const CharT *s, int expected ) {
- try {
+ if (pos1 > sv1.size()) {
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ try {
+ sv1.compare(pos1, n1, s);
+ assert(false);
+ } catch (const std::out_of_range&) {
+ } catch (...) {
+ assert(false);
+ }
+#endif
+ } else {
assert(sign(sv1.compare(pos1, n1, s)) == sign(expected));
- assert(pos1 <= sv1.size());
}
- catch (const std::out_of_range&) { assert(pos1 > sv1.size()); }
}
template<typename CharT>
@@ -391,7 +399,7 @@
test(L"abcdefghijklmnopqrst", 0, -1, L"abcdefghijklmnopqrst", 0);
}
-#if __cplusplus >= 201103L
+#if TEST_STD_VER >= 11
{
test(U"", 0, 0, U"", 0);
test(U"", 0, 0, U"abcde", -5);
@@ -431,7 +439,7 @@
}
#endif
-#if _LIBCPP_STD_VER > 11
+#if TEST_STD_VER > 11
{
typedef std::experimental::basic_string_view<char, constexpr_char_traits<char>> SV;
constexpr SV sv1;
diff --git a/libcxx/test/std/experimental/string.view/string.view.ops/compare.size_size_sv.pass.cpp b/libcxx/test/std/experimental/string.view/string.view.ops/compare.size_size_sv.pass.cpp
index 244de9e..d756d15 100644
--- a/libcxx/test/std/experimental/string.view/string.view.ops/compare.size_size_sv.pass.cpp
+++ b/libcxx/test/std/experimental/string.view/string.view.ops/compare.size_size_sv.pass.cpp
@@ -7,8 +7,6 @@
//
//===----------------------------------------------------------------------===//
-
-// XFAIL: libcpp-no-exceptions
// <string_view>
// constexpr int compare(size_type pos1, size_type n1, basic_string_view str) const;
@@ -16,6 +14,7 @@
#include <experimental/string_view>
#include <cassert>
+#include "test_macros.h"
#include "constexpr_char_traits.hpp"
int sign ( int x ) { return x > 0 ? 1 : ( x < 0 ? -1 : 0 ); }
@@ -24,19 +23,25 @@
void test1 ( std::experimental::basic_string_view<CharT> sv1, size_t pos1, size_t n1,
std::experimental::basic_string_view<CharT> sv2, int expected ) {
- try
- {
+ if (pos1 > sv1.size()) {
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ try {
+ sv1.compare(pos1, n1, sv2);
+ assert(false);
+ } catch (const std::out_of_range&) {
+ } catch (...) {
+ assert(false);
+ }
+#endif
+ } else {
assert ( sign( sv1.compare(pos1, n1, sv2)) == sign(expected));
- assert(pos1 <= sv1.size());
}
- catch (const std::out_of_range&) { assert(pos1 > sv1.size()); }
}
template<typename CharT>
void test ( const CharT *s1, size_t pos1, size_t n1, const CharT *s2, int expected ) {
typedef std::experimental::basic_string_view<CharT> string_view_t;
-
string_view_t sv1 ( s1 );
string_view_t sv2 ( s2 );
test1(sv1, pos1, n1, sv2, expected);
@@ -370,7 +375,7 @@
test(L"ABCde", 2, 4, L"abcde", -1);
}
-#if __cplusplus >= 201103L
+#if TEST_STD_VER >= 11
{
test(u"abcde", 5, 1, u"", 0);
test(u"abcde", 2, 4, u"", 3);
@@ -386,7 +391,7 @@
}
#endif
-#if _LIBCPP_STD_VER > 11
+#if TEST_STD_VER > 11
{
typedef std::experimental::basic_string_view<char, constexpr_char_traits<char>> SV;
constexpr SV sv1 { "abcde", 5 };
diff --git a/libcxx/test/std/experimental/string.view/string.view.ops/compare.size_size_sv_pointer_size.pass.cpp b/libcxx/test/std/experimental/string.view/string.view.ops/compare.size_size_sv_pointer_size.pass.cpp
index 1c3bc08..2930d53 100644
--- a/libcxx/test/std/experimental/string.view/string.view.ops/compare.size_size_sv_pointer_size.pass.cpp
+++ b/libcxx/test/std/experimental/string.view/string.view.ops/compare.size_size_sv_pointer_size.pass.cpp
@@ -7,8 +7,6 @@
//
//===----------------------------------------------------------------------===//
-
-// XFAIL: libcpp-no-exceptions
// <string_view>
// constexpr int compare(size_type pos1, size_type n1,
@@ -17,6 +15,7 @@
#include <experimental/string_view>
#include <cassert>
+#include "test_macros.h"
#include "constexpr_char_traits.hpp"
int sign ( int x ) { return x > 0 ? 1 : ( x < 0 ? -1 : 0 ); }
@@ -25,13 +24,21 @@
void test1 ( std::experimental::basic_string_view<CharT> sv1, size_t pos1, size_t n1,
const CharT *s2, size_t n2,
int expected ) {
-
- try
- {
- assert ( sign( sv1.compare(pos1, n1, s2, n2)) == sign(expected));
- assert(pos1 <= sv1.size());
+ if (pos1 > sv1.size()) {
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ try {
+ sv1.compare(pos1, n1, s2, n2);
+ assert(false);
+ } catch (const std::out_of_range&) {
+ return;
+ } catch (...) {
+ assert(false);
+ }
+#endif
+ } else {
+ assert(sign(sv1.compare(pos1, n1, s2, n2)) == sign(expected));
}
- catch (const std::out_of_range&) { assert(pos1 > sv1.size()); }
+
}
@@ -40,7 +47,6 @@
const CharT *s2, size_t n2,
int expected ) {
typedef std::experimental::basic_string_view<CharT> string_view_t;
-
string_view_t sv1 ( s1 );
test1 (sv1, pos1, n1, s2, n2, expected);
}
@@ -1319,7 +1325,7 @@
test(L"abcdefghijklmnopqrst", 10, 0, L"abcdefghij", 10, -10);
}
-#if __cplusplus >= 201103L
+#if TEST_STD_VER >= 11
{
test(U"", 0, 0, U"abcde", 0, 0);
test(U"", 0, 0, U"abcde", 1, -1);
@@ -1337,7 +1343,7 @@
}
#endif
-#if _LIBCPP_STD_VER > 11
+#if TEST_STD_VER > 11
{
typedef std::experimental::basic_string_view<char, constexpr_char_traits<char>> SV;
constexpr SV sv1;
diff --git a/libcxx/test/std/experimental/string.view/string.view.ops/compare.size_size_sv_size_size.pass.cpp b/libcxx/test/std/experimental/string.view/string.view.ops/compare.size_size_sv_size_size.pass.cpp
index c7a6f1e..2b55bdf 100644
--- a/libcxx/test/std/experimental/string.view/string.view.ops/compare.size_size_sv_size_size.pass.cpp
+++ b/libcxx/test/std/experimental/string.view/string.view.ops/compare.size_size_sv_size_size.pass.cpp
@@ -7,8 +7,6 @@
//
//===----------------------------------------------------------------------===//
-
-// XFAIL: libcpp-no-exceptions
// <string_view>
// constexpr int compare(size_type pos1, size_type n1, basic_string_view str,
@@ -17,6 +15,7 @@
#include <experimental/string_view>
#include <cassert>
+#include "test_macros.h"
#include "constexpr_char_traits.hpp"
int sign ( int x ) { return x > 0 ? 1 : ( x < 0 ? -1 : 0 ); }
@@ -26,13 +25,19 @@
std::experimental::basic_string_view<CharT> sv2, size_t pos2, size_t n2,
int expected ) {
- try
- {
- assert ( sign( sv1.compare(pos1, n1, sv2, pos2, n2)) == sign(expected));
- assert(pos1 <= sv1.size());
- assert(pos2 <= sv2.size());
+ if (pos1 > sv1.size() || pos2 > sv2.size()) {
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ try {
+ sv1.compare(pos1, n1, sv2, pos2, n2);
+ assert(false);
+ } catch (const std::out_of_range&) {
+ } catch (...) {
+ assert(false);
+ }
+#endif
+ } else {
+ assert (sign( sv1.compare(pos1, n1, sv2, pos2, n2)) == sign(expected));
}
- catch (const std::out_of_range&) { assert(pos1 > sv1.size() || pos2 > sv2.size()); }
}
@@ -5816,7 +5821,7 @@
test(L"ABCde", 2, 4, L"abcde", 2, 4, -1);
}
-#if __cplusplus >= 201103L
+#if TEST_STD_VER >= 11
{
test(u"abcde", 5, 1, u"", 0, 0, 0);
test(u"abcde", 2, 4, u"", 0, 0, 3);
@@ -5832,7 +5837,7 @@
}
#endif
-#if _LIBCPP_STD_VER > 11
+#if TEST_STD_VER > 11
{
typedef std::experimental::basic_string_view<char, constexpr_char_traits<char>> SV;
constexpr SV sv1 { "abcde", 5 };
diff --git a/libcxx/test/std/experimental/string.view/string.view.ops/copy.pass.cpp b/libcxx/test/std/experimental/string.view/string.view.ops/copy.pass.cpp
index 0e4eb9e..7bdb7c4 100644
--- a/libcxx/test/std/experimental/string.view/string.view.ops/copy.pass.cpp
+++ b/libcxx/test/std/experimental/string.view/string.view.ops/copy.pass.cpp
@@ -7,8 +7,6 @@
//
//===----------------------------------------------------------------------===//
-
-// XFAIL: libcpp-no-exceptions
// <string_view>
// size_type copy(charT* s, size_type n, size_type pos = 0) const;
@@ -23,21 +21,31 @@
#include <experimental/string_view>
#include <cassert>
+#include "test_macros.h"
+
template<typename CharT>
void test1 ( std::experimental::basic_string_view<CharT> sv, size_t n, size_t pos ) {
const size_t rlen = std::min ( n, sv.size() - pos );
CharT *dest1 = new CharT [rlen + 1]; dest1[rlen] = 0;
CharT *dest2 = new CharT [rlen + 1]; dest2[rlen] = 0;
-
- try {
+
+ if (pos > sv.size()) {
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ try {
+ sv.copy(dest1, n, pos);
+ assert(false);
+ } catch (const std::out_of_range&) {
+ } catch (...) {
+ assert(false);
+ }
+#endif
+ } else {
sv.copy(dest1, n, pos);
std::copy_n(sv.begin() + pos, rlen, dest2);
-
for ( size_t i = 0; i <= rlen; ++i )
assert ( dest1[i] == dest2[i] );
- }
- catch ( const std::out_of_range & ) { assert ( pos > sv.size()); }
+ }
delete [] dest1;
delete [] dest2;
}
@@ -79,7 +87,7 @@
test ( L"a" );
test ( L"" );
-#if __cplusplus >= 201103L
+#if TEST_STD_VER >= 11
test ( u"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
test ( u"ABCDE" );
test ( u"a" );
diff --git a/libcxx/test/std/experimental/string.view/string.view.ops/substr.pass.cpp b/libcxx/test/std/experimental/string.view/string.view.ops/substr.pass.cpp
index c80e90a..862a61d 100644
--- a/libcxx/test/std/experimental/string.view/string.view.ops/substr.pass.cpp
+++ b/libcxx/test/std/experimental/string.view/string.view.ops/substr.pass.cpp
@@ -7,8 +7,6 @@
//
//===----------------------------------------------------------------------===//
-
-// XFAIL: libcpp-no-exceptions
// <string_view>
// constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
@@ -20,16 +18,28 @@
#include <experimental/string_view>
#include <cassert>
+#include "test_macros.h"
+
template<typename CharT>
void test1 ( std::experimental::basic_string_view<CharT> sv, size_t n, size_t pos ) {
- try {
+ if (pos > sv.size()) {
+#ifndef TEST_HAS_NO_EXCEPTIONS
+ try {
+ std::experimental::basic_string_view<CharT> sv1 = sv.substr(pos, n);
+ assert(false);
+ } catch (const std::out_of_range&) {
+ return;
+ } catch (...) {
+ assert(false);
+ }
+#endif
+ } else {
std::experimental::basic_string_view<CharT> sv1 = sv.substr(pos, n);
const size_t rlen = std::min ( n, sv.size() - pos );
assert ( sv1.size() == rlen );
for ( size_t i = 0; i <= rlen; ++i )
assert ( sv[pos+i] == sv1[i] );
- }
- catch ( const std::out_of_range & ) { assert ( pos > sv.size()); }
+ }
}
@@ -68,7 +78,7 @@
test ( L"a" );
test ( L"" );
-#if __cplusplus >= 201103L
+#if TEST_STD_VER >= 11
test ( u"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
test ( u"ABCDE" );
test ( u"a" );
@@ -80,7 +90,7 @@
test ( U"" );
#endif
-#if _LIBCPP_STD_VER > 11
+#if TEST_STD_VER > 11
{
constexpr std::experimental::string_view sv1 { "ABCDE", 5 };