From ac24edd6e06114818b1a29c99bb81153514f7fb2 Mon Sep 17 00:00:00 2001 From: Hosein Ghahremanzadeh Date: Thu, 12 Sep 2019 10:36:44 -0400 Subject: Googletest export Merge 4c9ef099b29d2c840c04643cd9662fd7be712f7b into 565f1b848215b77c3732bca345fe76a0431d8b34 Closes #2403 COPYBARA_INTEGRATE_REVIEW=https://github.com/google/googletest/pull/2403 from IYP-Programer-Yeah:remove-compile-assert-type-equal 4c9ef099b29d2c840c04643cd9662fd7be712f7b PiperOrigin-RevId: 268681883 --- googlemock/include/gmock/gmock-actions.h | 4 +- googlemock/test/gmock-internal-utils_test.cc | 101 +++++++++++---------- googletest/include/gtest/internal/gtest-internal.h | 9 -- googletest/test/gtest_unittest.cc | 14 +-- 4 files changed, 59 insertions(+), 69 deletions(-) diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index 9605c43..9842f32 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -619,7 +619,7 @@ class ReturnVoidAction { // Allows Return() to be used in any void-returning function. template static void Perform(const ArgumentTuple&) { - CompileAssertTypesEqual(); + static_assert(std::is_void::value, "Result should be void."); } }; @@ -842,7 +842,7 @@ class IgnoreResultAction { typedef typename internal::Function::Result Result; // Asserts at compile time that F returns void. - CompileAssertTypesEqual(); + static_assert(std::is_void::value, "Result type should be void."); return Action(new Impl(action_)); } diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc index 7df4078..d000e69 100644 --- a/googlemock/test/gmock-internal-utils_test.cc +++ b/googlemock/test/gmock-internal-utils_test.cc @@ -125,15 +125,17 @@ TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameIsMixture) { } TEST(PointeeOfTest, WorksForSmartPointers) { - CompileAssertTypesEqual >::type>(); - CompileAssertTypesEqual >::type>(); + EXPECT_TRUE( + (std::is_same>::type>::value)); + EXPECT_TRUE( + (std::is_same>::type>::value)); } TEST(PointeeOfTest, WorksForRawPointers) { - CompileAssertTypesEqual::type>(); - CompileAssertTypesEqual::type>(); - CompileAssertTypesEqual::type>(); + EXPECT_TRUE((std::is_same::type>::value)); + EXPECT_TRUE((std::is_same::type>::value)); + EXPECT_TRUE((std::is_void::type>::value)); } TEST(GetRawPointerTest, WorksForSmartPointers) { @@ -664,63 +666,66 @@ TEST(StlContainerViewTest, WorksForDynamicNativeArray) { TEST(FunctionTest, Nullary) { typedef Function F; // NOLINT EXPECT_EQ(0u, F::ArgumentCount); - CompileAssertTypesEqual(); - CompileAssertTypesEqual, F::ArgumentTuple>(); - CompileAssertTypesEqual, F::ArgumentMatcherTuple>(); - CompileAssertTypesEqual(); - CompileAssertTypesEqual(); + EXPECT_TRUE((std::is_same::value)); + EXPECT_TRUE((std::is_same, F::ArgumentTuple>::value)); + EXPECT_TRUE((std::is_same, F::ArgumentMatcherTuple>::value)); + EXPECT_TRUE((std::is_same::value)); + EXPECT_TRUE((std::is_same::value)); } TEST(FunctionTest, Unary) { typedef Function F; // NOLINT EXPECT_EQ(1u, F::ArgumentCount); - CompileAssertTypesEqual(); - CompileAssertTypesEqual::type>(); - CompileAssertTypesEqual, F::ArgumentTuple>(); - CompileAssertTypesEqual >, - F::ArgumentMatcherTuple>(); - CompileAssertTypesEqual(); // NOLINT - CompileAssertTypesEqual(); + EXPECT_TRUE((std::is_same::value)); + EXPECT_TRUE((std::is_same::type>::value)); + EXPECT_TRUE((std::is_same, F::ArgumentTuple>::value)); + EXPECT_TRUE(( + std::is_same>, F::ArgumentMatcherTuple>::value)); + EXPECT_TRUE((std::is_same::value)); // NOLINT + EXPECT_TRUE((std::is_same::value)); } TEST(FunctionTest, Binary) { typedef Function F; // NOLINT EXPECT_EQ(2u, F::ArgumentCount); - CompileAssertTypesEqual(); - CompileAssertTypesEqual::type>(); - CompileAssertTypesEqual::type>(); // NOLINT - CompileAssertTypesEqual, // NOLINT - F::ArgumentTuple>(); - CompileAssertTypesEqual< - std::tuple, Matcher >, // NOLINT - F::ArgumentMatcherTuple>(); - CompileAssertTypesEqual(); // NOLINT - CompileAssertTypesEqual(); + EXPECT_TRUE((std::is_same::value)); + EXPECT_TRUE((std::is_same::type>::value)); + EXPECT_TRUE((std::is_same::type>::value)); // NOLINT + EXPECT_TRUE((std::is_same, // NOLINT + F::ArgumentTuple>::value)); + EXPECT_TRUE( + (std::is_same, Matcher>, // NOLINT + F::ArgumentMatcherTuple>::value)); + EXPECT_TRUE((std::is_same::value)); + EXPECT_TRUE((std::is_same::value)); } TEST(FunctionTest, LongArgumentList) { typedef Function F; // NOLINT EXPECT_EQ(5u, F::ArgumentCount); - CompileAssertTypesEqual(); - CompileAssertTypesEqual::type>(); - CompileAssertTypesEqual::type>(); - CompileAssertTypesEqual::type>(); - CompileAssertTypesEqual::type>(); - CompileAssertTypesEqual::type>(); // NOLINT - CompileAssertTypesEqual< - std::tuple, // NOLINT - F::ArgumentTuple>(); - CompileAssertTypesEqual< - std::tuple, Matcher, Matcher, Matcher, - Matcher >, // NOLINT - F::ArgumentMatcherTuple>(); - CompileAssertTypesEqual(); - CompileAssertTypesEqual< - IgnoredValue(bool, int, char*, int&, const long&), // NOLINT - F::MakeResultIgnoredValue>(); + EXPECT_TRUE((std::is_same::value)); + EXPECT_TRUE((std::is_same::type>::value)); + EXPECT_TRUE((std::is_same::type>::value)); + EXPECT_TRUE((std::is_same::type>::value)); + EXPECT_TRUE((std::is_same::type>::value)); + EXPECT_TRUE((std::is_same::type>::value)); // NOLINT + EXPECT_TRUE( + (std::is_same, // NOLINT + F::ArgumentTuple>::value)); + EXPECT_TRUE( + (std::is_same< + std::tuple, Matcher, Matcher, Matcher, + Matcher>, // NOLINT + F::ArgumentMatcherTuple>::value)); + EXPECT_TRUE( + (std::is_same::value)); + EXPECT_TRUE(( + std::is_same::value)); } } // namespace diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index 3a98ce4..62af669 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -847,15 +847,6 @@ class GTEST_API_ Random { GTEST_DISALLOW_COPY_AND_ASSIGN_(Random); }; -// Defining a variable of type CompileAssertTypesEqual will cause a -// compiler error if T1 and T2 are different types. -template -struct CompileAssertTypesEqual; - -template -struct CompileAssertTypesEqual { -}; - // Turns const U&, U&, const U, and U all into U. #define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \ typename std::remove_const::type>::type diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 12c5a87..2c0552d 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -233,7 +233,6 @@ using testing::internal::AppendUserMessage; using testing::internal::ArrayAwareFind; using testing::internal::ArrayEq; using testing::internal::CodePointToUtf8; -using testing::internal::CompileAssertTypesEqual; using testing::internal::CopyArray; using testing::internal::CountIf; using testing::internal::EqFailure; @@ -7102,18 +7101,12 @@ TEST(IsAProtocolMessageTest, ValueIsFalseWhenTypeIsNotAProtocolMessage) { EXPECT_FALSE(IsAProtocolMessage::value); } -// Tests that CompileAssertTypesEqual compiles when the type arguments are -// equal. -TEST(CompileAssertTypesEqual, CompilesWhenTypesAreEqual) { - CompileAssertTypesEqual(); - CompileAssertTypesEqual(); -} - // Tests GTEST_REMOVE_REFERENCE_AND_CONST_. template void TestGTestRemoveReferenceAndConst() { - CompileAssertTypesEqual(); + static_assert(std::is_same::value, + "GTEST_REMOVE_REFERENCE_AND_CONST_ failed."); } TEST(RemoveReferenceToConstTest, Works) { @@ -7128,7 +7121,8 @@ TEST(RemoveReferenceToConstTest, Works) { template void TestGTestReferenceToConst() { - CompileAssertTypesEqual(); + static_assert(std::is_same::value, + "GTEST_REFERENCE_TO_CONST_ failed."); } TEST(GTestReferenceToConstTest, Works) { -- cgit v0.12