From f31bf1d362afa1eba7efdc5bc0a33b0e814ce43a Mon Sep 17 00:00:00 2001 From: misterg Date: Tue, 8 Jan 2019 11:26:35 -0500 Subject: Googletest export Replace testing::internal::ImplicitlyConvertible with std::is_convertible Fixes #2054 PiperOrigin-RevId: 228334305 --- googlemock/include/gmock/gmock-matchers.h | 8 ++-- googletest/include/gtest/gtest-printers.h | 4 +- googletest/include/gtest/gtest.h | 2 +- googletest/include/gtest/internal/gtest-internal.h | 52 +--------------------- googletest/test/gtest_unittest.cc | 30 ------------- 5 files changed, 9 insertions(+), 87 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index b99fdc3..56804f3 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -128,9 +128,9 @@ class MatcherCastImpl { return CastImpl( polymorphic_matcher_or_value, BooleanConstant< - internal::ImplicitlyConvertible >::value>(), + std::is_convertible >::value>(), BooleanConstant< - internal::ImplicitlyConvertible::value>()); + std::is_convertible::value>()); } private: @@ -268,8 +268,8 @@ class SafeMatcherCastImpl { template static inline Matcher Cast(const Matcher& matcher) { // Enforce that T can be implicitly converted to U. - GTEST_COMPILE_ASSERT_((internal::ImplicitlyConvertible::value), - T_must_be_implicitly_convertible_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_( diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index d6596e4..9048459 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -232,12 +232,12 @@ template ::std::basic_ostream& os, const T& x) { TypeWithoutFormatter::value ? kProtobuf - : internal::ImplicitlyConvertible< + : std::is_convertible< const T&, internal::BiggestInt>::value ? kConvertibleToInteger : #if GTEST_HAS_ABSL - internal::ImplicitlyConvertible< + std::is_convertible< const T&, absl::string_view>::value ? kConvertibleToStringView : diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index a0df29e..3c72575 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -306,7 +306,7 @@ class GTEST_API_ AssertionResult { explicit AssertionResult( const T& success, typename internal::EnableIf< - !internal::ImplicitlyConvertible::value>::type* + !std::is_convertible::value>::type* /*enabler*/ = nullptr) : success_(success) {} diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index 8ef69c4..94773df 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -920,62 +920,14 @@ struct RemoveConst { #define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \ GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T)) -// ImplicitlyConvertible::value is a compile-time bool -// constant that's true iff type From can be implicitly converted to -// type To. -template -class ImplicitlyConvertible { - private: - // We need the following helper functions only for their types. - // They have no implementations. - - // MakeFrom() is an expression whose type is From. We cannot simply - // use From(), as the type From may not have a public default - // constructor. - static typename AddReference::type MakeFrom(); - - // These two functions are overloaded. Given an expression - // Helper(x), the compiler will pick the first version if x can be - // implicitly converted to type To; otherwise it will pick the - // second version. - // - // The first version returns a value of size 1, and the second - // version returns a value of size 2. Therefore, by checking the - // size of Helper(x), which can be done at compile time, we can tell - // which version of Helper() is used, and hence whether x can be - // implicitly converted to type To. - static char Helper(To); - static char (&Helper(...))[2]; // NOLINT - - // We have to put the 'public' section after the 'private' section, - // or MSVC refuses to compile the code. - public: -#if defined(__BORLANDC__) - // C++Builder cannot use member overload resolution during template - // instantiation. The simplest workaround is to use its C++0x type traits - // functions (C++Builder 2009 and above only). - static const bool value = __is_convertible(From, To); -#else - // MSVC warns about implicitly converting from double to int for - // possible loss of data, so we need to temporarily disable the - // warning. - GTEST_DISABLE_MSC_WARNINGS_PUSH_(4244) - static const bool value = - sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1; - GTEST_DISABLE_MSC_WARNINGS_POP_() -#endif // __BORLANDC__ -}; -template -const bool ImplicitlyConvertible::value; - // IsAProtocolMessage::value is a compile-time bool constant that's // true iff T is type ProtocolMessage, proto2::Message, or a subclass // of those. template struct IsAProtocolMessage : public bool_constant< - ImplicitlyConvertible::value || - ImplicitlyConvertible::value> { + std::is_convertible::value || + std::is_convertible::value> { }; // When the compiler sees expression IsContainerTest(0), if C is an diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 147f0f5..3b18af6 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -250,7 +250,6 @@ using testing::internal::GetTestTypeId; using testing::internal::GetTimeInMillis; using testing::internal::GetTypeId; using testing::internal::GetUnitTestImpl; -using testing::internal::ImplicitlyConvertible; using testing::internal::Int32; using testing::internal::Int32FromEnvOrDie; using testing::internal::IsAProtocolMessage; @@ -7240,35 +7239,6 @@ TEST(GTestReferenceToConstTest, Works) { TestGTestReferenceToConst(); } -// Tests that ImplicitlyConvertible::value is a compile-time constant. -TEST(ImplicitlyConvertibleTest, ValueIsCompileTimeConstant) { - GTEST_COMPILE_ASSERT_((ImplicitlyConvertible::value), const_true); - GTEST_COMPILE_ASSERT_((!ImplicitlyConvertible::value), - const_false); -} - -// Tests that ImplicitlyConvertible::value is true when T1 can -// be implicitly converted to T2. -TEST(ImplicitlyConvertibleTest, ValueIsTrueWhenConvertible) { - EXPECT_TRUE((ImplicitlyConvertible::value)); - EXPECT_TRUE((ImplicitlyConvertible::value)); - EXPECT_TRUE((ImplicitlyConvertible::value)); - EXPECT_TRUE((ImplicitlyConvertible::value)); - EXPECT_TRUE((ImplicitlyConvertible::value)); - EXPECT_TRUE((ImplicitlyConvertible::value)); -} - -// Tests that ImplicitlyConvertible::value is false when T1 -// cannot be implicitly converted to T2. -TEST(ImplicitlyConvertibleTest, ValueIsFalseWhenNotConvertible) { - EXPECT_FALSE((ImplicitlyConvertible::value)); - EXPECT_FALSE((ImplicitlyConvertible::value)); - EXPECT_FALSE((ImplicitlyConvertible::value)); - EXPECT_FALSE((ImplicitlyConvertible::value)); -} // Tests IsContainerTest. -- cgit v0.12