diff --git a/libcxx/include/__string b/libcxx/include/__string --- a/libcxx/include/__string +++ b/libcxx/include/__string @@ -940,7 +940,7 @@ template inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY __str_find(const _CharT *__p, _SizeT __sz, - _CharT __c, _SizeT __pos) _NOEXCEPT + _CharT __c, _SizeT __pos) { if (__pos >= __sz) return __npos; @@ -992,7 +992,7 @@ template inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY __str_find(const _CharT *__p, _SizeT __sz, - const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT + const _CharT* __s, _SizeT __pos, _SizeT __n) { if (__pos > __sz) return __npos; diff --git a/libcxx/include/string b/libcxx/include/string --- a/libcxx/include/string +++ b/libcxx/include/string @@ -1271,7 +1271,7 @@ allocator_type get_allocator() const _NOEXCEPT {return __alloc();} _LIBCPP_INLINE_VISIBILITY - size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; + size_type find(const basic_string& __str, size_type __pos = 0) const; // _NOEXCEPT template _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS @@ -1281,10 +1281,10 @@ size_type > find(const _Tp& __t, size_type __pos = 0) const; - size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; + size_type find(const value_type* __s, size_type __pos, size_type __n) const; _LIBCPP_INLINE_VISIBILITY - size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT; - size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT; + size_type find(const value_type* __s, size_type __pos = 0) const; + size_type find(value_type __c, size_type __pos = 0) const; // _NOEXCEPT _LIBCPP_INLINE_VISIBILITY size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; @@ -3500,7 +3500,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, size_type __pos, - size_type __n) const _NOEXCEPT + size_type __n) const { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr"); return __str_find @@ -3511,7 +3511,7 @@ inline typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str, - size_type __pos) const _NOEXCEPT + size_type __pos) const // _NOEXCEPT { return __str_find (data(), size(), __str.data(), __pos, __str.size()); @@ -3536,7 +3536,7 @@ inline typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, - size_type __pos) const _NOEXCEPT + size_type __pos) const { _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr"); return __str_find @@ -3546,7 +3546,7 @@ template typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find(value_type __c, - size_type __pos) const _NOEXCEPT + size_type __pos) const // _NOEXCEPT { return __str_find (data(), size(), __c, __pos); diff --git a/libcxx/test/std/strings/basic.string/string.ops/string_find/char_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.ops/string_find/char_size.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.ops/string_find/char_size.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.ops/string_find/char_size.pass.cpp @@ -35,6 +35,27 @@ assert(0 <= x && x + 1 <= s.size()); } +#ifndef _LIBCPP_NO_EXCEPTIONS +template +struct ThrowingTrait : std::char_traits +{ + static const T* + find(const T*, std::size_t, const T&) { + throw 0; + } +}; + +template +void +test_trait_find_throws(const T *s) { + std::basic_string, std::allocator > str = s; + try { + str.find('x'); + assert(false); + } catch (int) { /* Do nothing... */ } +} +#endif // _LIBCPP_NO_EXCEPTIONS + int main(int, char**) { { @@ -96,5 +117,9 @@ } #endif +#ifndef _LIBCPP_NO_EXCEPTIONS + test_trait_find_throws("xyz"); +#endif // _LIBCPP_NO_EXCEPTIONS + return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.ops/string_find/pointer_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.ops/string_find/pointer_size.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.ops/string_find/pointer_size.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.ops/string_find/pointer_size.pass.cpp @@ -41,6 +41,27 @@ } } +#ifndef _LIBCPP_NO_EXCEPTIONS +template +struct ThrowingTrait : std::char_traits +{ + static const T* + find(const T*, std::size_t, const T&) { + throw 0; + } +}; + +template +void +test_trait_find_throws(const T *s) { + std::basic_string, std::allocator > str = s; + try { + str.find(s); + assert(false); + } catch (int) { /* Do nothing... */ } +} +#endif // _LIBCPP_NO_EXCEPTIONS + template void test0() { @@ -162,5 +183,9 @@ } #endif +#ifndef _LIBCPP_NO_EXCEPTIONS + test_trait_find_throws("xyz"); +#endif // _LIBCPP_NO_EXCEPTIONS + return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.ops/string_find/pointer_size_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.ops/string_find/pointer_size_size.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.ops/string_find/pointer_size_size.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.ops/string_find/pointer_size_size.pass.cpp @@ -26,6 +26,27 @@ assert(pos <= x && x + n <= s.size()); } +#ifndef _LIBCPP_NO_EXCEPTIONS +template +struct ThrowingTrait : std::char_traits +{ + static const T* + find(const T*, std::size_t, const T&) { + throw 0; + } +}; + +template +void +test_trait_find_throws(const T *s) { + std::basic_string, std::allocator > str = s; + try { + str.find(s, 0, 2); + assert(false); + } catch (int) { /* Do nothing... */ } +} +#endif // _LIBCPP_NO_EXCEPTIONS + template void test0() { @@ -385,5 +406,9 @@ } #endif +#ifndef _LIBCPP_NO_EXCEPTIONS + test_trait_find_throws("xyz"); +#endif // _LIBCPP_NO_EXCEPTIONS + return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.ops/string_find/string_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.ops/string_find/string_size.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.ops/string_find/string_size.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.ops/string_find/string_size.pass.cpp @@ -34,6 +34,28 @@ assert(0 <= x && x + str.size() <= s.size()); } +#ifndef _LIBCPP_NO_EXCEPTIONS +template +struct ThrowingTrait : std::char_traits +{ + static const T* + find(const T*, std::size_t, const T&) { + throw 0; + } +}; + +template +void +test_trait_find_throws(const T *s) { + std::basic_string, std::allocator > str = s; + std::basic_string, std::allocator > search_val = "xyz"; + try { + str.find(search_val); + assert(false); + } catch (int) { /* Do nothing... */ } +} +#endif // _LIBCPP_NO_EXCEPTIONS + template void test0() { @@ -162,5 +184,9 @@ } #endif +#ifndef _LIBCPP_NO_EXCEPTIONS + test_trait_find_throws("xyz"); +#endif // _LIBCPP_NO_EXCEPTIONS + return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.ops/string_find/string_view_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.ops/string_find/string_view_size.pass.cpp --- a/libcxx/test/std/strings/basic.string/string.ops/string_find/string_view_size.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.ops/string_find/string_view_size.pass.cpp @@ -34,6 +34,28 @@ assert(0 <= x && x + sv.size() <= s.size()); } +#ifndef _LIBCPP_NO_EXCEPTIONS +template +struct ThrowingTrait : std::char_traits +{ + static const T* + find(const T*, std::size_t, const T&) { + throw 0; + } +}; + +template +void +test_trait_find_throws(const T *s) { + std::basic_string, std::allocator > str = s; + std::basic_string_view > view = s; + try { + str.find(view); + assert(false); + } catch (int) { /* Do nothing... */ } +} +#endif // _LIBCPP_NO_EXCEPTIONS + template void test0() { @@ -157,5 +179,9 @@ } #endif +#ifndef _LIBCPP_NO_EXCEPTIONS + test_trait_find_throws("xyz"); +#endif // _LIBCPP_NO_EXCEPTIONS + return 0; }