From b7dd66519f4af354b1938860a4073669b6cd91ab Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Sun, 16 Dec 2018 05:14:13 -0500 Subject: Googletest export Remove GTEST_REFERENCE_TO_CONST_ usage from GMock. In C++11, it's redundant. PiperOrigin-RevId: 225719210 --- googlemock/include/gmock/gmock-matchers.h | 45 ++++++++++++------------------- googletest/include/gtest/gtest-matchers.h | 29 ++++++++------------ 2 files changed, 28 insertions(+), 46 deletions(-) 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::type matcher = std::get(matchers); typedef typename std::tuple_element::type Value; - GTEST_REFERENCE_TO_CONST_(Value) value = std::get(values); + const Value& value = std::get(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(). template -class AnyMatcherImpl : public MatcherInterface { +class AnyMatcherImpl : public MatcherInterface { 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 { // will prevent different instantiations of NotMatcher from sharing // the same NotMatcherImpl class. template -class NotMatcherImpl : public MatcherInterface { +class NotMatcherImpl : public MatcherInterface { public: explicit NotMatcherImpl(const Matcher& 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 class. template -class AllOfMatcherImpl - : public MatcherInterface { +class AllOfMatcherImpl : public MatcherInterface { public: explicit AllOfMatcherImpl(std::vector > 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; // that will prevent different instantiations of AnyOfMatcher from // sharing the same EitherOfMatcherImpl class. template -class AnyOfMatcherImpl - : public MatcherInterface { +class AnyOfMatcherImpl : public MatcherInterface { public: explicit AnyOfMatcherImpl(std::vector > 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 operator Matcher() const { - return Matcher( - new Impl(matcher_)); + return Matcher(new Impl(matcher_)); } private: @@ -1775,11 +1772,7 @@ class FieldMatcher { template 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& matcher) : property_(property), @@ -3776,8 +3769,7 @@ Property(PropertyType (Class::*property)() const, return MakePolymorphicMatcher( internal::PropertyMatcher( - property, - MatcherCast(matcher))); + property, MatcherCast(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( - property_name, property, - MatcherCast(matcher))); + property_name, property, MatcherCast(matcher))); } #if GTEST_LANG_CXX11 @@ -3808,9 +3799,8 @@ Property(PropertyType (Class::*property)() const &, const PropertyMatcher& matcher) { return MakePolymorphicMatcher( internal::PropertyMatcher( - property, - MatcherCast(matcher))); + PropertyType (Class::*)() const&>( + property, MatcherCast(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( - property_name, property, - MatcherCast(matcher))); + PropertyType (Class::*)() const&>( + property_name, property, MatcherCast(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* impl) - : impl_(impl) {} + explicit MatcherBase(const MatcherInterface* impl) : impl_(impl) {} template explicit MatcherBase( const MatcherInterface* impl, typename internal::EnableIf< - !internal::IsSame::value>::type* = - nullptr) + !internal::IsSame::value>::type* = nullptr) : impl_(new internal::MatcherInterfaceAdapter(impl)) {} virtual ~MatcherBase() {} private: - std::shared_ptr> impl_; + std::shared_ptr> impl_; }; } // namespace internal @@ -326,15 +321,13 @@ class Matcher : public internal::MatcherBase { explicit Matcher() {} // NOLINT // Constructs a matcher from its implementation. - explicit Matcher(const MatcherInterface* impl) + explicit Matcher(const MatcherInterface* impl) : internal::MatcherBase(impl) {} template - explicit Matcher( - const MatcherInterface* impl, - typename internal::EnableIf< - !internal::IsSame::value>::type* = - nullptr) + explicit Matcher(const MatcherInterface* impl, + typename internal::EnableIf< + !internal::IsSame::value>::type* = nullptr) : internal::MatcherBase(impl) {} // Implicit constructor here allows people to write @@ -535,7 +528,7 @@ class PolymorphicMatcher { template operator Matcher() const { - return Matcher(new MonomorphicImpl(impl_)); + return Matcher(new MonomorphicImpl(impl_)); } private: -- cgit v1.2.1