diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index fa89bd60..be881e14 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -387,7 +387,7 @@ class TuplePrefix { typename std::tuple_element<N - 1, MatcherTuple>::type matcher = std::get<N - 1>(matchers); typedef typename std::tuple_element<N - 1, ValueTuple>::type Value; - GTEST_REFERENCE_TO_CONST_(Value) value = std::get<N - 1>(values); + const Value& value = std::get<N - 1>(values); StringMatchResultListener listener; if (!matcher.MatchAndExplain(value, &listener)) { // FIXME: include in the message the name of the parameter @@ -492,9 +492,9 @@ OutIter TransformTupleValues(Func f, const Tuple& t, OutIter out) { // Implements A<T>(). template <typename T> -class AnyMatcherImpl : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> { +class AnyMatcherImpl : public MatcherInterface<const T&> { public: - bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) /* x */, + bool MatchAndExplain(const T& /* x */, MatchResultListener* /* listener */) const override { return true; } @@ -976,12 +976,12 @@ class Ge2Matcher : public PairMatchBase<Ge2Matcher, AnyGe> { // will prevent different instantiations of NotMatcher from sharing // the same NotMatcherImpl<T> class. template <typename T> -class NotMatcherImpl : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> { +class NotMatcherImpl : public MatcherInterface<const T&> { public: explicit NotMatcherImpl(const Matcher<T>& matcher) : matcher_(matcher) {} - bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x, + bool MatchAndExplain(const T& x, MatchResultListener* listener) const override { return !matcher_.MatchAndExplain(x, listener); } @@ -1025,8 +1025,7 @@ class NotMatcher { // that will prevent different instantiations of BothOfMatcher from // sharing the same BothOfMatcherImpl<T> class. template <typename T> -class AllOfMatcherImpl - : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> { +class AllOfMatcherImpl : public MatcherInterface<const T&> { public: explicit AllOfMatcherImpl(std::vector<Matcher<T> > matchers) : matchers_(std::move(matchers)) {} @@ -1049,7 +1048,7 @@ class AllOfMatcherImpl *os << ")"; } - bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x, + bool MatchAndExplain(const T& x, MatchResultListener* listener) const override { // If either matcher1_ or matcher2_ doesn't match x, we only need // to explain why one of them fails. @@ -1132,8 +1131,7 @@ using AllOfMatcher = VariadicMatcher<AllOfMatcherImpl, Args...>; // that will prevent different instantiations of AnyOfMatcher from // sharing the same EitherOfMatcherImpl<T> class. template <typename T> -class AnyOfMatcherImpl - : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> { +class AnyOfMatcherImpl : public MatcherInterface<const T&> { public: explicit AnyOfMatcherImpl(std::vector<Matcher<T> > matchers) : matchers_(std::move(matchers)) {} @@ -1156,7 +1154,7 @@ class AnyOfMatcherImpl *os << ")"; } - bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x, + bool MatchAndExplain(const T& x, MatchResultListener* listener) const override { std::string no_match_result; @@ -1584,8 +1582,7 @@ class PointeeMatcher { // enough for implementing the DescribeTo() method of Pointee(). template <typename Pointer> operator Matcher<Pointer>() const { - return Matcher<Pointer>( - new Impl<GTEST_REFERENCE_TO_CONST_(Pointer)>(matcher_)); + return Matcher<Pointer>(new Impl<const Pointer&>(matcher_)); } private: @@ -1775,11 +1772,7 @@ class FieldMatcher { template <typename Class, typename PropertyType, typename Property> class PropertyMatcher { public: - // The property may have a reference type, so 'const PropertyType&' - // may cause double references and fail to compile. That's why we - // need GTEST_REFERENCE_TO_CONST, which works regardless of - // PropertyType being a reference or not. - typedef GTEST_REFERENCE_TO_CONST_(PropertyType) RefToConstProperty; + typedef const PropertyType& RefToConstProperty; PropertyMatcher(Property property, const Matcher<RefToConstProperty>& matcher) : property_(property), @@ -3776,8 +3769,7 @@ Property(PropertyType (Class::*property)() const, return MakePolymorphicMatcher( internal::PropertyMatcher<Class, PropertyType, PropertyType (Class::*)() const>( - property, - MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher))); + property, MatcherCast<const PropertyType&>(matcher))); // The call to MatcherCast() is required for supporting inner // matchers of compatible types. For example, it allows // Property(&Foo::bar, m) @@ -3795,8 +3787,7 @@ Property(const std::string& property_name, return MakePolymorphicMatcher( internal::PropertyMatcher<Class, PropertyType, PropertyType (Class::*)() const>( - property_name, property, - MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher))); + property_name, property, MatcherCast<const PropertyType&>(matcher))); } #if GTEST_LANG_CXX11 @@ -3808,9 +3799,8 @@ Property(PropertyType (Class::*property)() const &, const PropertyMatcher& matcher) { return MakePolymorphicMatcher( internal::PropertyMatcher<Class, PropertyType, - PropertyType (Class::*)() const &>( - property, - MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher))); + PropertyType (Class::*)() const&>( + property, MatcherCast<const PropertyType&>(matcher))); } // Three-argument form for reference-qualified member functions. @@ -3822,9 +3812,8 @@ Property(const std::string& property_name, const PropertyMatcher& matcher) { return MakePolymorphicMatcher( internal::PropertyMatcher<Class, PropertyType, - PropertyType (Class::*)() const &>( - property_name, property, - MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher))); + PropertyType (Class::*)() const&>( + property_name, property, MatcherCast<const PropertyType&>(matcher))); } #endif diff --git a/googletest/include/gtest/gtest-matchers.h b/googletest/include/gtest/gtest-matchers.h index 9bcf5ac2..02a9952b 100644 --- a/googletest/include/gtest/gtest-matchers.h +++ b/googletest/include/gtest/gtest-matchers.h @@ -256,13 +256,12 @@ class MatcherBase { public: // Returns true iff the matcher matches x; also explains the match // result to 'listener'. - bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x, - MatchResultListener* listener) const { + bool MatchAndExplain(const T& x, MatchResultListener* listener) const { return impl_->MatchAndExplain(x, listener); } // Returns true iff this matcher matches x. - bool Matches(GTEST_REFERENCE_TO_CONST_(T) x) const { + bool Matches(const T& x) const { DummyMatchResultListener dummy; return MatchAndExplain(x, &dummy); } @@ -276,8 +275,7 @@ class MatcherBase { } // Explains why x matches, or doesn't match, the matcher. - void ExplainMatchResultTo(GTEST_REFERENCE_TO_CONST_(T) x, - ::std::ostream* os) const { + void ExplainMatchResultTo(const T& x, ::std::ostream* os) const { StreamMatchResultListener listener(os); MatchAndExplain(x, &listener); } @@ -293,22 +291,19 @@ class MatcherBase { MatcherBase() {} // Constructs a matcher from its implementation. - explicit MatcherBase( - const MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)>* impl) - : impl_(impl) {} + explicit MatcherBase(const MatcherInterface<const T&>* impl) : impl_(impl) {} template <typename U> explicit MatcherBase( const MatcherInterface<U>* impl, typename internal::EnableIf< - !internal::IsSame<U, GTEST_REFERENCE_TO_CONST_(U)>::value>::type* = - nullptr) + !internal::IsSame<U, const U&>::value>::type* = nullptr) : impl_(new internal::MatcherInterfaceAdapter<U>(impl)) {} virtual ~MatcherBase() {} private: - std::shared_ptr<const MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)>> impl_; + std::shared_ptr<const MatcherInterface<const T&>> impl_; }; } // namespace internal @@ -326,15 +321,13 @@ class Matcher : public internal::MatcherBase<T> { explicit Matcher() {} // NOLINT // Constructs a matcher from its implementation. - explicit Matcher(const MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)>* impl) + explicit Matcher(const MatcherInterface<const T&>* impl) : internal::MatcherBase<T>(impl) {} template <typename U> - explicit Matcher( - const MatcherInterface<U>* impl, - typename internal::EnableIf< - !internal::IsSame<U, GTEST_REFERENCE_TO_CONST_(U)>::value>::type* = - nullptr) + explicit Matcher(const MatcherInterface<U>* impl, + typename internal::EnableIf< + !internal::IsSame<U, const U&>::value>::type* = nullptr) : internal::MatcherBase<T>(impl) {} // Implicit constructor here allows people to write @@ -535,7 +528,7 @@ class PolymorphicMatcher { template <typename T> operator Matcher<T>() const { - return Matcher<T>(new MonomorphicImpl<GTEST_REFERENCE_TO_CONST_(T)>(impl_)); + return Matcher<T>(new MonomorphicImpl<const T&>(impl_)); } private: