https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101361
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> --- This would be better, because it avoids the redundant range checking done when this->compare calls this->substr: { const auto __len = this->size(); const auto __xlen = __x.size(); return __len >= __xlen && traits_type::compare(end() - __xlen, __x.data(), __xlen) == 0; } But there's still a bug if the compiler warns about unreachable code. The npos is passed to substr as __n which does: const size_type __rlen = std::min(__n, _M_len - __pos); So there is no way we ever pass that value to memcmp. From my uninformed point of view this seems like a problem with jump threading vs VRP and changing libstdc++ just sweeps it under the rug.