@@ -2281,14 +2281,17 @@ class ResultOfMatcher {
22812281  class  Impl  : public  MatcherInterface <T> {
22822282    using  ResultType = decltype (CallableTraits<Callable>::template  Invoke<T>(
22832283        std::declval<CallableStorageType>(), std::declval<T>()));
2284+     using  InnerType = std::conditional_t <
2285+         std::is_lvalue_reference<ResultType>::value,
2286+         const  typename  std::remove_reference<ResultType>::type&, ResultType>;
22842287
22852288   public: 
22862289    template  <typename  M>
22872290    Impl (const  std::string& result_description,
22882291         const  CallableStorageType& callable, const  M& matcher)
22892292        : result_description_(result_description),
22902293          callable_ (callable),
2291-           matcher_(MatcherCast<ResultType >(matcher)) {}
2294+           matcher_(MatcherCast<InnerType >(matcher)) {}
22922295
22932296    void  DescribeTo (::std::ostream* os) const  override  {
22942297      if  (result_description_.empty ()) {
@@ -2318,7 +2321,7 @@ class ResultOfMatcher {
23182321      //  takes a non-const reference as argument.
23192322      //  Also, specifying template argument explicitly is needed because T could
23202323      //  be a non-const reference (e.g. Matcher<Uncopyable&>).
2321-       ResultType  result =
2324+       InnerType  result =
23222325          CallableTraits<Callable>::template  Invoke<T>(callable_, obj);
23232326      return  MatchPrintAndExplain (result, matcher_, listener);
23242327    }
@@ -2331,7 +2334,7 @@ class ResultOfMatcher {
23312334    //  use stateful callables with ResultOf(), which doesn't guarantee
23322335    //  how many times the callable will be invoked.
23332336    mutable  CallableStorageType callable_;
2334-     const  Matcher<ResultType > matcher_;
2337+     const  Matcher<InnerType > matcher_;
23352338  };  //  class Impl
23362339
23372340  const  std::string result_description_;
0 commit comments