_GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
_If_sv<_Tp, int>
compare(size_type __pos, size_type __n, const _Tp& __svt) const
- noexcept(is_same<_Tp, __sv_type>::value)
{
__sv_type __sv = __svt;
return __sv_type(*this).substr(__pos, __n).compare(__sv);
_If_sv<_Tp, int>
compare(size_type __pos1, size_type __n1, const _Tp& __svt,
size_type __pos2, size_type __n2 = npos) const
- noexcept(is_same<_Tp, __sv_type>::value)
{
__sv_type __sv = __svt;
return __sv_type(*this)
template<typename _Tp>
_If_sv<_Tp, int>
compare(size_type __pos, size_type __n, const _Tp& __svt) const
- noexcept(is_same<_Tp, __sv_type>::value)
{
__sv_type __sv = __svt;
return __sv_type(*this).substr(__pos, __n).compare(__sv);
_If_sv<_Tp, int>
compare(size_type __pos1, size_type __n1, const _Tp& __svt,
size_type __pos2, size_type __n2 = npos) const
- noexcept(is_same<_Tp, __sv_type>::value)
{
__sv_type __sv = __svt;
return __sv_type(*this)
--- /dev/null
+// { dg-do run { target c++17 } }
+
+// Bug 123991 - std::string::compare crashes instead of throwing
+
+#include <string>
+#include <string_view>
+#include <stdexcept>
+#include <testsuite_hooks.h>
+
+void
+test_compare_3arg()
+{
+ std::string_view sv;
+ std::string s;
+ static_assert( ! noexcept(s.compare(0, 0, sv)) );
+#ifdef __cpp_exceptions
+ try
+ {
+ (void) s.compare(1, 0, sv);
+ VERIFY(false);
+ }
+ catch (const std::out_of_range&)
+ { }
+#endif
+}
+
+void
+test_compare_5arg()
+{
+ std::string_view sv;
+ std::string s;
+ static_assert( ! noexcept(s.compare(0, 0, sv, 0, 0)) );
+#ifdef __cpp_exceptions
+ try
+ {
+ (void) s.compare(1, 0, sv, 0, 0);
+ VERIFY(false);
+ }
+ catch (const std::out_of_range&)
+ { }
+
+ try
+ {
+ (void) s.compare(0, 0, sv, 1, 0);
+ VERIFY(false);
+ }
+ catch (const std::out_of_range&)
+ { }
+#endif
+}
+
+int main()
+{
+ test_compare_3arg();
+ test_compare_5arg();
+}
--- /dev/null
+// { dg-do run { target c++17 } }
+
+// Bug 123991 - std::string::compare crashes instead of throwing
+
+#include <string>
+#include <string_view>
+#include <stdexcept>
+#include <testsuite_hooks.h>
+
+void
+test_compare_3arg()
+{
+ std::wstring_view sv;
+ std::wstring s;
+ static_assert( ! noexcept(s.compare(0, 0, sv)) );
+#ifdef __cpp_exceptions
+ try
+ {
+ (void) s.compare(1, 0, sv);
+ VERIFY(false);
+ }
+ catch (const std::out_of_range&)
+ { }
+#endif
+}
+
+void
+test_compare_5arg()
+{
+ std::wstring_view sv;
+ std::wstring s;
+ static_assert( ! noexcept(s.compare(0, 0, sv, 0, 0)) );
+#ifdef __cpp_exceptions
+ try
+ {
+ (void) s.compare(1, 0, sv, 0, 0);
+ VERIFY(false);
+ }
+ catch (const std::out_of_range&)
+ { }
+
+ try
+ {
+ (void) s.compare(0, 0, sv, 1, 0);
+ VERIFY(false);
+ }
+ catch (const std::out_of_range&)
+ { }
+#endif
+}
+
+int main()
+{
+ test_compare_3arg();
+ test_compare_5arg();
+}