Index: include/string =================================================================== --- include/string +++ include/string @@ -3795,7 +3795,10 @@ operator==(const _CharT* __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT { - return __rhs.compare(__lhs) == 0; + _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr"); + size_t __lhs_len = _Traits::length(__lhs); + if (__lhs_len != __rhs.size()) return false; + return _Traits::compare(__rhs.data(), __lhs, __lhs_len) == 0; } template @@ -3804,7 +3807,10 @@ operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs, const _CharT* __rhs) _NOEXCEPT { - return __lhs.compare(__rhs) == 0; + _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr"); + size_t __rhs_len = _Traits::length(__rhs); + if (__rhs_len != __lhs.size()) return false; + return _Traits::compare(__lhs.data(), __rhs, __rhs_len) == 0; } // operator!=