diff options
author | Abseil Team <absl-team@google.com> | 2025-01-16 20:50:32 (GMT) |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2025-01-16 20:51:11 (GMT) |
commit | 2b6b042a77446ff322cd7522ca068d9f2a21c1d1 (patch) | |
tree | 810f729aa3154e3eca6b9c6b04bf54cf010fe1b6 | |
parent | e4ece4881d1fefc1e67d21c7493835815cd13085 (diff) | |
download | googletest-2b6b042a77446ff322cd7522ca068d9f2a21c1d1.zip googletest-2b6b042a77446ff322cd7522ca068d9f2a21c1d1.tar.gz googletest-2b6b042a77446ff322cd7522ca068d9f2a21c1d1.tar.bz2 |
Cast mutable lvalue references to const from testing::ResultOf
PiperOrigin-RevId: 716343482
Change-Id: I125bc4725886958d026c88f3902a8289e476598b
-rw-r--r-- | googlemock/include/gmock/gmock-matchers.h | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 18cbe16..e979544 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -2281,6 +2281,9 @@ class ResultOfMatcher { class Impl : public MatcherInterface<T> { using ResultType = decltype(CallableTraits<Callable>::template Invoke<T>( std::declval<CallableStorageType>(), std::declval<T>())); + using InnerType = std::conditional_t< + std::is_lvalue_reference<ResultType>::value, + const typename std::remove_reference<ResultType>::type&, ResultType>; public: template <typename M> @@ -2288,7 +2291,7 @@ class ResultOfMatcher { const CallableStorageType& callable, const M& matcher) : result_description_(result_description), callable_(callable), - matcher_(MatcherCast<ResultType>(matcher)) {} + matcher_(MatcherCast<InnerType>(matcher)) {} void DescribeTo(::std::ostream* os) const override { if (result_description_.empty()) { @@ -2318,7 +2321,7 @@ class ResultOfMatcher { // takes a non-const reference as argument. // Also, specifying template argument explicitly is needed because T could // be a non-const reference (e.g. Matcher<Uncopyable&>). - ResultType result = + InnerType result = CallableTraits<Callable>::template Invoke<T>(callable_, obj); return MatchPrintAndExplain(result, matcher_, listener); } @@ -2331,7 +2334,7 @@ class ResultOfMatcher { // use stateful callables with ResultOf(), which doesn't guarantee // how many times the callable will be invoked. mutable CallableStorageType callable_; - const Matcher<ResultType> matcher_; + const Matcher<InnerType> matcher_; }; // class Impl const std::string result_description_; |