From a9653c401e799933be77ee9dfa4aa0c378031b1d Mon Sep 17 00:00:00 2001 From: Scott Graham Date: Wed, 2 May 2018 11:14:39 -0700 Subject: [PATCH] Fix gmock not building when -fno-rtti Fixes issue #1554. This is internal cl/195020996. --- googlemock/include/gmock/gmock-matchers.h | 8 ++++---- googlemock/test/gmock-matchers_test.cc | 6 ++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index e0a78646..c94f5826 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -2371,6 +2371,7 @@ class PointeeMatcher { GTEST_DISALLOW_ASSIGN_(PointeeMatcher); }; +#if GTEST_HAS_RTTI // Implements the WhenDynamicCastTo(m) matcher that matches a pointer or // reference that matches inner_matcher when dynamic_cast is applied. // The result of dynamic_cast is forwarded to the inner matcher. @@ -2397,11 +2398,7 @@ class WhenDynamicCastToMatcherBase { const Matcher matcher_; static std::string GetToName() { -#if GTEST_HAS_RTTI return GetTypeName(); -#else // GTEST_HAS_RTTI - return "the target type"; -#endif // GTEST_HAS_RTTI } private: @@ -2447,6 +2444,7 @@ class WhenDynamicCastToMatcher : public WhenDynamicCastToMatcherBase { return MatchPrintAndExplain(*to, this->matcher_, listener); } }; +#endif // GTEST_HAS_RTTI // Implements the Field() matcher for matching a field (i.e. member // variable) of an object. @@ -4441,6 +4439,7 @@ inline internal::PointeeMatcher Pointee( return internal::PointeeMatcher(inner_matcher); } +#if GTEST_HAS_RTTI // Creates a matcher that matches a pointer or reference that matches // inner_matcher when dynamic_cast is applied. // The result of dynamic_cast is forwarded to the inner matcher. @@ -4453,6 +4452,7 @@ WhenDynamicCastTo(const Matcher& inner_matcher) { return MakePolymorphicMatcher( internal::WhenDynamicCastToMatcher(inner_matcher)); } +#endif // GTEST_HAS_RTTI // Creates a matcher that matches an object whose given field matches // 'matcher'. For example, diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index b4224651..87b2ad5c 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -3704,6 +3704,7 @@ MATCHER_P(FieldIIs, inner_matcher, "") { return ExplainMatchResult(inner_matcher, arg.i, result_listener); } +#if GTEST_HAS_RTTI TEST(WhenDynamicCastToTest, SameType) { Derived derived; derived.i = 4; @@ -3761,12 +3762,8 @@ TEST(WhenDynamicCastToTest, AmbiguousCast) { TEST(WhenDynamicCastToTest, Describe) { Matcher matcher = WhenDynamicCastTo(Pointee(_)); -#if GTEST_HAS_RTTI const std::string prefix = "when dynamic_cast to " + internal::GetTypeName() + ", "; -#else // GTEST_HAS_RTTI - const std::string prefix = "when dynamic_cast, "; -#endif // GTEST_HAS_RTTI EXPECT_EQ(prefix + "points to a value that is anything", Describe(matcher)); EXPECT_EQ(prefix + "does not point to a value that is anything", DescribeNegation(matcher)); @@ -3799,6 +3796,7 @@ TEST(WhenDynamicCastToTest, BadReference) { Base& as_base_ref = derived; EXPECT_THAT(as_base_ref, Not(WhenDynamicCastTo(_))); } +#endif // GTEST_HAS_RTTI // Minimal const-propagating pointer. template