https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112314
Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Ever confirmed|0 |1 Last reconfirmed| |2023-10-31 Severity|normal |enhancement --- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> --- For the first problem: --- a/libstdc++-v3/include/std/string_view +++ b/libstdc++-v3/include/std/string_view @@ -301,7 +301,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION 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 For the second one, I did start work on a patch that attempts to verify that the provided length is not more than __builtin_object_size. I can't remember why I stopped working on that. There's no way to make that check 100% reliable, because __builtin_object_size depends on optimizations and whether the compiler can see enough data.