Googletest export

Remove GTEST_REFERENCE_TO_CONST_ usage from GMock. In C++11, it's redundant.

PiperOrigin-RevId: 225719210
This commit is contained in:
Abseil Team 2018-12-16 05:14:13 -05:00 committed by Mark Barolak
parent 1ec20f87e3
commit b7dd66519f
2 changed files with 28 additions and 46 deletions

View File

@ -387,7 +387,7 @@ class TuplePrefix {
typename std::tuple_element<N - 1, MatcherTuple>::type matcher = typename std::tuple_element<N - 1, MatcherTuple>::type matcher =
std::get<N - 1>(matchers); std::get<N - 1>(matchers);
typedef typename std::tuple_element<N - 1, ValueTuple>::type Value; 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; StringMatchResultListener listener;
if (!matcher.MatchAndExplain(value, &listener)) { if (!matcher.MatchAndExplain(value, &listener)) {
// FIXME: include in the message the name of the parameter // 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>(). // Implements A<T>().
template <typename T> template <typename T>
class AnyMatcherImpl : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> { class AnyMatcherImpl : public MatcherInterface<const T&> {
public: public:
bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) /* x */, bool MatchAndExplain(const T& /* x */,
MatchResultListener* /* listener */) const override { MatchResultListener* /* listener */) const override {
return true; return true;
} }
@ -976,12 +976,12 @@ class Ge2Matcher : public PairMatchBase<Ge2Matcher, AnyGe> {
// will prevent different instantiations of NotMatcher from sharing // will prevent different instantiations of NotMatcher from sharing
// the same NotMatcherImpl<T> class. // the same NotMatcherImpl<T> class.
template <typename T> template <typename T>
class NotMatcherImpl : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> { class NotMatcherImpl : public MatcherInterface<const T&> {
public: public:
explicit NotMatcherImpl(const Matcher<T>& matcher) explicit NotMatcherImpl(const Matcher<T>& matcher)
: matcher_(matcher) {} : matcher_(matcher) {}
bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x, bool MatchAndExplain(const T& x,
MatchResultListener* listener) const override { MatchResultListener* listener) const override {
return !matcher_.MatchAndExplain(x, listener); return !matcher_.MatchAndExplain(x, listener);
} }
@ -1025,8 +1025,7 @@ class NotMatcher {
// that will prevent different instantiations of BothOfMatcher from // that will prevent different instantiations of BothOfMatcher from
// sharing the same BothOfMatcherImpl<T> class. // sharing the same BothOfMatcherImpl<T> class.
template <typename T> template <typename T>
class AllOfMatcherImpl class AllOfMatcherImpl : public MatcherInterface<const T&> {
: public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> {
public: public:
explicit AllOfMatcherImpl(std::vector<Matcher<T> > matchers) explicit AllOfMatcherImpl(std::vector<Matcher<T> > matchers)
: matchers_(std::move(matchers)) {} : matchers_(std::move(matchers)) {}
@ -1049,7 +1048,7 @@ class AllOfMatcherImpl
*os << ")"; *os << ")";
} }
bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x, bool MatchAndExplain(const T& x,
MatchResultListener* listener) const override { MatchResultListener* listener) const override {
// If either matcher1_ or matcher2_ doesn't match x, we only need // If either matcher1_ or matcher2_ doesn't match x, we only need
// to explain why one of them fails. // to explain why one of them fails.
@ -1132,8 +1131,7 @@ using AllOfMatcher = VariadicMatcher<AllOfMatcherImpl, Args...>;
// that will prevent different instantiations of AnyOfMatcher from // that will prevent different instantiations of AnyOfMatcher from
// sharing the same EitherOfMatcherImpl<T> class. // sharing the same EitherOfMatcherImpl<T> class.
template <typename T> template <typename T>
class AnyOfMatcherImpl class AnyOfMatcherImpl : public MatcherInterface<const T&> {
: public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> {
public: public:
explicit AnyOfMatcherImpl(std::vector<Matcher<T> > matchers) explicit AnyOfMatcherImpl(std::vector<Matcher<T> > matchers)
: matchers_(std::move(matchers)) {} : matchers_(std::move(matchers)) {}
@ -1156,7 +1154,7 @@ class AnyOfMatcherImpl
*os << ")"; *os << ")";
} }
bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x, bool MatchAndExplain(const T& x,
MatchResultListener* listener) const override { MatchResultListener* listener) const override {
std::string no_match_result; std::string no_match_result;
@ -1584,8 +1582,7 @@ class PointeeMatcher {
// enough for implementing the DescribeTo() method of Pointee(). // enough for implementing the DescribeTo() method of Pointee().
template <typename Pointer> template <typename Pointer>
operator Matcher<Pointer>() const { operator Matcher<Pointer>() const {
return Matcher<Pointer>( return Matcher<Pointer>(new Impl<const Pointer&>(matcher_));
new Impl<GTEST_REFERENCE_TO_CONST_(Pointer)>(matcher_));
} }
private: private:
@ -1775,11 +1772,7 @@ class FieldMatcher {
template <typename Class, typename PropertyType, typename Property> template <typename Class, typename PropertyType, typename Property>
class PropertyMatcher { class PropertyMatcher {
public: public:
// The property may have a reference type, so 'const PropertyType&' typedef const PropertyType& RefToConstProperty;
// 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;
PropertyMatcher(Property property, const Matcher<RefToConstProperty>& matcher) PropertyMatcher(Property property, const Matcher<RefToConstProperty>& matcher)
: property_(property), : property_(property),
@ -3776,8 +3769,7 @@ Property(PropertyType (Class::*property)() const,
return MakePolymorphicMatcher( return MakePolymorphicMatcher(
internal::PropertyMatcher<Class, PropertyType, internal::PropertyMatcher<Class, PropertyType,
PropertyType (Class::*)() const>( PropertyType (Class::*)() const>(
property, property, MatcherCast<const PropertyType&>(matcher)));
MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher)));
// The call to MatcherCast() is required for supporting inner // The call to MatcherCast() is required for supporting inner
// matchers of compatible types. For example, it allows // matchers of compatible types. For example, it allows
// Property(&Foo::bar, m) // Property(&Foo::bar, m)
@ -3795,8 +3787,7 @@ Property(const std::string& property_name,
return MakePolymorphicMatcher( return MakePolymorphicMatcher(
internal::PropertyMatcher<Class, PropertyType, internal::PropertyMatcher<Class, PropertyType,
PropertyType (Class::*)() const>( PropertyType (Class::*)() const>(
property_name, property, property_name, property, MatcherCast<const PropertyType&>(matcher)));
MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher)));
} }
#if GTEST_LANG_CXX11 #if GTEST_LANG_CXX11
@ -3809,8 +3800,7 @@ Property(PropertyType (Class::*property)() const &,
return MakePolymorphicMatcher( return MakePolymorphicMatcher(
internal::PropertyMatcher<Class, PropertyType, internal::PropertyMatcher<Class, PropertyType,
PropertyType (Class::*)() const&>( PropertyType (Class::*)() const&>(
property, property, MatcherCast<const PropertyType&>(matcher)));
MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher)));
} }
// Three-argument form for reference-qualified member functions. // Three-argument form for reference-qualified member functions.
@ -3823,8 +3813,7 @@ Property(const std::string& property_name,
return MakePolymorphicMatcher( return MakePolymorphicMatcher(
internal::PropertyMatcher<Class, PropertyType, internal::PropertyMatcher<Class, PropertyType,
PropertyType (Class::*)() const&>( PropertyType (Class::*)() const&>(
property_name, property, property_name, property, MatcherCast<const PropertyType&>(matcher)));
MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher)));
} }
#endif #endif

View File

@ -256,13 +256,12 @@ class MatcherBase {
public: public:
// Returns true iff the matcher matches x; also explains the match // Returns true iff the matcher matches x; also explains the match
// result to 'listener'. // result to 'listener'.
bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x, bool MatchAndExplain(const T& x, MatchResultListener* listener) const {
MatchResultListener* listener) const {
return impl_->MatchAndExplain(x, listener); return impl_->MatchAndExplain(x, listener);
} }
// Returns true iff this matcher matches x. // Returns true iff this matcher matches x.
bool Matches(GTEST_REFERENCE_TO_CONST_(T) x) const { bool Matches(const T& x) const {
DummyMatchResultListener dummy; DummyMatchResultListener dummy;
return MatchAndExplain(x, &dummy); return MatchAndExplain(x, &dummy);
} }
@ -276,8 +275,7 @@ class MatcherBase {
} }
// Explains why x matches, or doesn't match, the matcher. // Explains why x matches, or doesn't match, the matcher.
void ExplainMatchResultTo(GTEST_REFERENCE_TO_CONST_(T) x, void ExplainMatchResultTo(const T& x, ::std::ostream* os) const {
::std::ostream* os) const {
StreamMatchResultListener listener(os); StreamMatchResultListener listener(os);
MatchAndExplain(x, &listener); MatchAndExplain(x, &listener);
} }
@ -293,22 +291,19 @@ class MatcherBase {
MatcherBase() {} MatcherBase() {}
// Constructs a matcher from its implementation. // Constructs a matcher from its implementation.
explicit MatcherBase( explicit MatcherBase(const MatcherInterface<const T&>* impl) : impl_(impl) {}
const MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)>* impl)
: impl_(impl) {}
template <typename U> template <typename U>
explicit MatcherBase( explicit MatcherBase(
const MatcherInterface<U>* impl, const MatcherInterface<U>* impl,
typename internal::EnableIf< typename internal::EnableIf<
!internal::IsSame<U, GTEST_REFERENCE_TO_CONST_(U)>::value>::type* = !internal::IsSame<U, const U&>::value>::type* = nullptr)
nullptr)
: impl_(new internal::MatcherInterfaceAdapter<U>(impl)) {} : impl_(new internal::MatcherInterfaceAdapter<U>(impl)) {}
virtual ~MatcherBase() {} virtual ~MatcherBase() {}
private: private:
std::shared_ptr<const MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)>> impl_; std::shared_ptr<const MatcherInterface<const T&>> impl_;
}; };
} // namespace internal } // namespace internal
@ -326,15 +321,13 @@ class Matcher : public internal::MatcherBase<T> {
explicit Matcher() {} // NOLINT explicit Matcher() {} // NOLINT
// Constructs a matcher from its implementation. // 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) {} : internal::MatcherBase<T>(impl) {}
template <typename U> template <typename U>
explicit Matcher( explicit Matcher(const MatcherInterface<U>* impl,
const MatcherInterface<U>* impl,
typename internal::EnableIf< typename internal::EnableIf<
!internal::IsSame<U, GTEST_REFERENCE_TO_CONST_(U)>::value>::type* = !internal::IsSame<U, const U&>::value>::type* = nullptr)
nullptr)
: internal::MatcherBase<T>(impl) {} : internal::MatcherBase<T>(impl) {}
// Implicit constructor here allows people to write // Implicit constructor here allows people to write
@ -535,7 +528,7 @@ class PolymorphicMatcher {
template <typename T> template <typename T>
operator Matcher<T>() const { operator Matcher<T>() const {
return Matcher<T>(new MonomorphicImpl<GTEST_REFERENCE_TO_CONST_(T)>(impl_)); return Matcher<T>(new MonomorphicImpl<const T&>(impl_));
} }
private: private: