From 909b1ccfcacc9d6f920aa79e3f643c1a4e806eb2 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 25 Feb 2020 10:52:53 -0500 Subject: Googletest export Relax the implementation of MatcherCast to allow conversion of `Matcher` to `Matcher`. They have the same match signature. PiperOrigin-RevId: 297115843 --- googlemock/include/gmock/gmock-matchers.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'googlemock/include/gmock') diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 4b6ac563..fe88a7c7 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -424,7 +424,14 @@ class MatcherCastImpl > { !std::is_base_of::value, "Can't implicitly convert from to "); - return source_matcher_.MatchAndExplain(static_cast(x), listener); + // Do the cast to `U` explicitly if necessary. + // Otherwise, let implicit conversions do the trick. + using CastType = + typename std::conditional::value, + T&, U>::type; + + return source_matcher_.MatchAndExplain(static_cast(x), + listener); } void DescribeTo(::std::ostream* os) const override { @@ -524,8 +531,8 @@ inline Matcher SafeMatcherCast(const M& polymorphic_matcher_or_value) { template inline Matcher SafeMatcherCast(const Matcher& matcher) { // Enforce that T can be implicitly converted to U. - GTEST_COMPILE_ASSERT_((std::is_convertible::value), - "T must be implicitly convertible to U"); + static_assert(std::is_convertible::value, + "T must be implicitly convertible to U"); // Enforce that we are not converting a non-reference type T to a reference // type U. GTEST_COMPILE_ASSERT_( -- cgit v1.2.3