diff --git a/include/gmock/gmock-matchers.h b/include/gmock/gmock-matchers.h index 822337b1..58fe3b63 100644 --- a/include/gmock/gmock-matchers.h +++ b/include/gmock/gmock-matchers.h @@ -1833,7 +1833,7 @@ class MatcherAsPredicate { template class PredicateFormatterFromMatcher { public: - explicit PredicateFormatterFromMatcher(const M& m) : matcher_(m) {} + explicit PredicateFormatterFromMatcher(M m) : matcher_(internal::move(m)) {} // This template () operator allows a PredicateFormatterFromMatcher // object to act as a predicate-formatter suitable for using with @@ -1873,10 +1873,11 @@ class PredicateFormatterFromMatcher { // A helper function for converting a matcher to a predicate-formatter // without the user needing to explicitly write the type. This is // used for implementing ASSERT_THAT() and EXPECT_THAT(). +// Implementation detail: 'matcher' is received by-value to force decaying. template inline PredicateFormatterFromMatcher -MakePredicateFormatterFromMatcher(const M& matcher) { - return PredicateFormatterFromMatcher(matcher); +MakePredicateFormatterFromMatcher(M matcher) { + return PredicateFormatterFromMatcher(internal::move(matcher)); } // Implements the polymorphic floating point equality matcher, which matches diff --git a/test/gmock-matchers_test.cc b/test/gmock-matchers_test.cc index 494c85f4..ceb20022 100644 --- a/test/gmock-matchers_test.cc +++ b/test/gmock-matchers_test.cc @@ -762,6 +762,21 @@ TEST(SafeMatcherCastTest, ValueIsNotCopied) { EXPECT_TRUE(m.Matches(n)); } +TEST(ExpectThat, TakesLiterals) { + EXPECT_THAT(1, 1); + EXPECT_THAT(1.0, 1.0); + EXPECT_THAT(string(), ""); +} + +TEST(ExpectThat, TakesFunctions) { + struct Helper { + static void Func() {} + }; + void (*func)() = Helper::Func; + EXPECT_THAT(func, Helper::Func); + EXPECT_THAT(func, &Helper::Func); +} + // Tests that A() matches any value of type T. TEST(ATest, MatchesAnyValue) { // Tests a matcher for a value type.