diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 18cbe160..e979544c 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 { using ResultType = decltype(CallableTraits::template Invoke( std::declval(), std::declval())); + using InnerType = std::conditional_t< + std::is_lvalue_reference::value, + const typename std::remove_reference::type&, ResultType>; public: template @@ -2288,7 +2291,7 @@ class ResultOfMatcher { const CallableStorageType& callable, const M& matcher) : result_description_(result_description), callable_(callable), - matcher_(MatcherCast(matcher)) {} + matcher_(MatcherCast(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). - ResultType result = + InnerType result = CallableTraits::template Invoke(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 matcher_; + const Matcher matcher_; }; // class Impl const std::string result_description_;