From e0c80b0a6e5162578399e0539bd7de171e9843e4 Mon Sep 17 00:00:00 2001 From: Krystian Kuzniarek Date: Fri, 22 Nov 2019 14:54:41 +0100 Subject: consistency fix for SafeMatcherCastImpl member functions --- googlemock/include/gmock/gmock-matchers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'googlemock/include/gmock/gmock-matchers.h') diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index b8ec24dd..1078b8d2 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -258,7 +258,7 @@ class SafeMatcherCastImpl { // monomorphic matchers are handled by the next one. template static inline Matcher Cast(const M& polymorphic_matcher_or_value) { - return internal::MatcherCastImpl::Cast(polymorphic_matcher_or_value); + return MatcherCast(polymorphic_matcher_or_value); } // This overload handles monomorphic matchers. -- cgit v1.2.3 From bbbc5d8a4b90b3c372c7cf0ec93c20b6f5cffd23 Mon Sep 17 00:00:00 2001 From: Krystian Kuzniarek Date: Fri, 22 Nov 2019 15:19:25 +0100 Subject: remove Nokia's Symbian compiler workaround: SafeMatcherCastImpl --- googlemock/include/gmock/gmock-matchers.h | 85 +++++++++++++------------------ 1 file changed, 36 insertions(+), 49 deletions(-) (limited to 'googlemock/include/gmock/gmock-matchers.h') diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 1078b8d2..71f1542b 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -247,56 +247,43 @@ inline Matcher MatcherCast(const M& matcher) { return internal::MatcherCastImpl::Cast(matcher); } -// Implements SafeMatcherCast(). -// -// FIXME: The intermediate SafeMatcherCastImpl class was introduced as a -// workaround for a compiler bug, and can now be removed. -template -class SafeMatcherCastImpl { - public: - // This overload handles polymorphic matchers and values only since - // monomorphic matchers are handled by the next one. - template - static inline Matcher Cast(const M& polymorphic_matcher_or_value) { - return MatcherCast(polymorphic_matcher_or_value); - } - - // This overload handles monomorphic matchers. - // - // In general, if type T can be implicitly converted to type U, we can - // safely convert a Matcher to a Matcher (i.e. Matcher is - // contravariant): just keep a copy of the original Matcher, convert the - // argument from type T to U, and then pass it to the underlying Matcher. - // The only exception is when U is a reference and T is not, as the - // underlying Matcher may be interested in the argument's address, which - // is not preserved in the conversion from T to U. - template - static inline Matcher Cast(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"); - // Enforce that we are not converting a non-reference type T to a reference - // type U. - GTEST_COMPILE_ASSERT_( - std::is_reference::value || !std::is_reference::value, - cannot_convert_non_reference_arg_to_reference); - // In case both T and U are arithmetic types, enforce that the - // conversion is not lossy. - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(T) RawT; - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(U) RawU; - const bool kTIsOther = GMOCK_KIND_OF_(RawT) == internal::kOther; - const bool kUIsOther = GMOCK_KIND_OF_(RawU) == internal::kOther; - GTEST_COMPILE_ASSERT_( - kTIsOther || kUIsOther || - (internal::LosslessArithmeticConvertible::value), - conversion_of_arithmetic_types_must_be_lossless); - return MatcherCast(matcher); - } -}; - +// This overload handles polymorphic matchers and values only since +// monomorphic matchers are handled by the next one. template -inline Matcher SafeMatcherCast(const M& polymorphic_matcher) { - return SafeMatcherCastImpl::Cast(polymorphic_matcher); +inline Matcher SafeMatcherCast(const M& polymorphic_matcher_or_value) { + return MatcherCast(polymorphic_matcher_or_value); +} + +// This overload handles monomorphic matchers. +// +// In general, if type T can be implicitly converted to type U, we can +// safely convert a Matcher to a Matcher (i.e. Matcher is +// contravariant): just keep a copy of the original Matcher, convert the +// argument from type T to U, and then pass it to the underlying Matcher. +// The only exception is when U is a reference and T is not, as the +// underlying Matcher may be interested in the argument's address, which +// is not preserved in the conversion from T to U. +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"); + // Enforce that we are not converting a non-reference type T to a reference + // type U. + GTEST_COMPILE_ASSERT_( + std::is_reference::value || !std::is_reference::value, + cannot_convert_non_reference_arg_to_reference); + // In case both T and U are arithmetic types, enforce that the + // conversion is not lossy. + typedef GTEST_REMOVE_REFERENCE_AND_CONST_(T) RawT; + typedef GTEST_REMOVE_REFERENCE_AND_CONST_(U) RawU; + constexpr bool kTIsOther = GMOCK_KIND_OF_(RawT) == internal::kOther; + constexpr bool kUIsOther = GMOCK_KIND_OF_(RawU) == internal::kOther; + GTEST_COMPILE_ASSERT_( + kTIsOther || kUIsOther || + (internal::LosslessArithmeticConvertible::value), + conversion_of_arithmetic_types_must_be_lossless); + return MatcherCast(matcher); } // A() returns a matcher that matches any value of type T. -- cgit v1.2.3