From c618dd98d0eaf13ddf5dea933928a74555b70f27 Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Thu, 12 Oct 2023 16:24:06 +0200 Subject: [PATCH] fix: explicitly copy-convert to std::string in StartsWith/EndsWith matchers Instead of relying on automatic conversions, which won't happen if they're explicit! --- googlemock/include/gmock/gmock-matchers.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 0f677137..8052c74a 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -1048,7 +1048,7 @@ class StartsWithMatcher { template bool MatchAndExplain(const MatcheeStringType& s, MatchResultListener* /* listener */) const { - const StringType& s2(s); + const StringType s2(s); return s2.length() >= prefix_.length() && s2.substr(0, prefix_.length()) == prefix_; } @@ -1102,7 +1102,7 @@ class EndsWithMatcher { template bool MatchAndExplain(const MatcheeStringType& s, MatchResultListener* /* listener */) const { - const StringType& s2(s); + const StringType s2(s); return s2.length() >= suffix_.length() && s2.substr(s2.length() - suffix_.length()) == suffix_; }