libstdc++-v3/ChangeLog:
PR libstdc++/112314
* include/std/string_view (string_view::remove_suffix): Add
debug assertion.
* testsuite/21_strings/basic_string_view/modifiers/remove_prefix/debug.cc:
New test.
* testsuite/21_strings/basic_string_view/modifiers/remove_suffix/debug.cc:
New test.
constexpr void
remove_suffix(size_type __n) noexcept
- { this->_M_len -= __n; }
+ {
+ __glibcxx_assert(this->_M_len >= __n);
+ this->_M_len -= __n;
+ }
constexpr void
swap(basic_string_view& __sv) noexcept
--- /dev/null
+// { dg-do compile { target c++17 } }
+
+#include <string_view>
+
+constexpr bool
+check_remove_prefix()
+{
+ std::string_view sv("123");
+ sv.remove_prefix(4);
+ // { dg-error "not a constant expression" "" { target *-*-* } 0 }
+ return true;
+}
+
+constexpr bool test = check_remove_prefix();
--- /dev/null
+// { dg-do compile { target c++17 } }
+
+#include <string_view>
+
+constexpr bool
+check_remove_suffix()
+{
+ std::string_view sv("123");
+ sv.remove_suffix(4);
+ // { dg-error "not a constant expression" "" { target *-*-* } 0 }
+ return true;
+}
+
+constexpr bool test = check_remove_suffix();