Merge pull request #2597 from kuzkry:remove-workaround_Nokia-Sybian-SafeMatcherCastImpl

PiperOrigin-RevId: 282581402
This commit is contained in:
Gennadiy Rozental 2019-11-26 15:47:21 -05:00
commit db13ff1f0b

View File

@ -247,18 +247,11 @@ inline Matcher<T> MatcherCast(const M& matcher) {
return internal::MatcherCastImpl<T, M>::Cast(matcher); return internal::MatcherCastImpl<T, M>::Cast(matcher);
} }
// Implements SafeMatcherCast().
//
// FIXME: The intermediate SafeMatcherCastImpl class was introduced as a
// workaround for a compiler bug, and can now be removed.
template <typename T>
class SafeMatcherCastImpl {
public:
// This overload handles polymorphic matchers and values only since // This overload handles polymorphic matchers and values only since
// monomorphic matchers are handled by the next one. // monomorphic matchers are handled by the next one.
template <typename M> template <typename T, typename M>
static inline Matcher<T> Cast(const M& polymorphic_matcher_or_value) { inline Matcher<T> SafeMatcherCast(const M& polymorphic_matcher_or_value) {
return internal::MatcherCastImpl<T, M>::Cast(polymorphic_matcher_or_value); return MatcherCast<T>(polymorphic_matcher_or_value);
} }
// This overload handles monomorphic matchers. // This overload handles monomorphic matchers.
@ -270,8 +263,8 @@ class SafeMatcherCastImpl {
// The only exception is when U is a reference and T is not, as the // The only exception is when U is a reference and T is not, as the
// underlying Matcher<U> may be interested in the argument's address, which // underlying Matcher<U> may be interested in the argument's address, which
// is not preserved in the conversion from T to U. // is not preserved in the conversion from T to U.
template <typename U> template <typename T, typename U>
static inline Matcher<T> Cast(const Matcher<U>& matcher) { inline Matcher<T> SafeMatcherCast(const Matcher<U>& matcher) {
// Enforce that T can be implicitly converted to U. // Enforce that T can be implicitly converted to U.
GTEST_COMPILE_ASSERT_((std::is_convertible<T, U>::value), GTEST_COMPILE_ASSERT_((std::is_convertible<T, U>::value),
"T must be implicitly convertible to U"); "T must be implicitly convertible to U");
@ -284,20 +277,14 @@ class SafeMatcherCastImpl {
// conversion is not lossy. // conversion is not lossy.
typedef GTEST_REMOVE_REFERENCE_AND_CONST_(T) RawT; typedef GTEST_REMOVE_REFERENCE_AND_CONST_(T) RawT;
typedef GTEST_REMOVE_REFERENCE_AND_CONST_(U) RawU; typedef GTEST_REMOVE_REFERENCE_AND_CONST_(U) RawU;
const bool kTIsOther = GMOCK_KIND_OF_(RawT) == internal::kOther; constexpr bool kTIsOther = GMOCK_KIND_OF_(RawT) == internal::kOther;
const bool kUIsOther = GMOCK_KIND_OF_(RawU) == internal::kOther; constexpr bool kUIsOther = GMOCK_KIND_OF_(RawU) == internal::kOther;
GTEST_COMPILE_ASSERT_( GTEST_COMPILE_ASSERT_(
kTIsOther || kUIsOther || kTIsOther || kUIsOther ||
(internal::LosslessArithmeticConvertible<RawT, RawU>::value), (internal::LosslessArithmeticConvertible<RawT, RawU>::value),
conversion_of_arithmetic_types_must_be_lossless); conversion_of_arithmetic_types_must_be_lossless);
return MatcherCast<T>(matcher); return MatcherCast<T>(matcher);
} }
};
template <typename T, typename M>
inline Matcher<T> SafeMatcherCast(const M& polymorphic_matcher) {
return SafeMatcherCastImpl<T>::Cast(polymorphic_matcher);
}
// A<T>() returns a matcher that matches any value of type T. // A<T>() returns a matcher that matches any value of type T.
template <typename T> template <typename T>