diff options
author | Eric Fiselier <eric@efcs.ca> | 2016-05-30 23:53:19 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2016-05-30 23:53:19 +0000 |
commit | af4a5a7f3323c3a6b43653a8475940d10ff7e63f (patch) | |
tree | 15b8cf0c30860a16f6ff2b609cf7968d03617c24 /libcxx/test/std/experimental | |
parent | 8287fd8abde6228ebab32953e85c78e75ce0fd30 (diff) | |
download | bcm5719-llvm-af4a5a7f3323c3a6b43653a8475940d10ff7e63f.tar.gz bcm5719-llvm-af4a5a7f3323c3a6b43653a8475940d10ff7e63f.zip |
Make string_view work with -fno-exceptions and get tests passing.
llvm-svn: 271237
Diffstat (limited to 'libcxx/test/std/experimental')
8 files changed, 102 insertions, 57 deletions
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 46804d4df3a..af35f54e26a 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 @@ void test ( const CharT *s, size_t len ) { 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 @@ int main () { 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 @@ int main () { 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 c2227cfc92b..1fd72d7964b 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 7ccbd528c7f..3b6a8a6943b 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 @@ int sign ( int x ) { return x > 0 ? 1 : ( x < 0 ? -1 : 0 ); } 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 @@ int main() 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 @@ int main() } #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 244de9eb510..d756d15998d 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 @@ template<typename CharT> 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 @@ int main () { 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 @@ int main () { } #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 1c3bc089a65..2930d53cb29 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 @@ template<typename CharT> 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 @@ void test ( const CharT *s1, size_t pos1, size_t n1, 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 @@ int main () { 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 @@ int main () { } #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 c7a6f1e1eb6..2b55bdf18fa 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 @@ void test1 ( std::experimental::basic_string_view<CharT> sv1, size_t pos1, size_ 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 @@ int main () { 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 @@ int main () { } #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 0e4eb9e50bb..7bdb7c40c97 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 @@ int main () { 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 c80e90a0478..862a61d8082 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 @@ int main () { 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 @@ int main () { test ( U"" ); #endif -#if _LIBCPP_STD_VER > 11 +#if TEST_STD_VER > 11 { constexpr std::experimental::string_view sv1 { "ABCDE", 5 }; |