Googletest export
Merge 4c9ef099b29d2c840c04643cd9662fd7be712f7b into 565f1b8482
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
			
			
This commit is contained in:
		
				
					committed by
					
						
						Shaindel Schwartz
					
				
			
			
				
	
			
			
			
						parent
						
							274afe50cf
						
					
				
				
					commit
					ac24edd6e0
				
			@@ -619,7 +619,7 @@ class ReturnVoidAction {
 | 
				
			|||||||
  // Allows Return() to be used in any void-returning function.
 | 
					  // Allows Return() to be used in any void-returning function.
 | 
				
			||||||
  template <typename Result, typename ArgumentTuple>
 | 
					  template <typename Result, typename ArgumentTuple>
 | 
				
			||||||
  static void Perform(const ArgumentTuple&) {
 | 
					  static void Perform(const ArgumentTuple&) {
 | 
				
			||||||
    CompileAssertTypesEqual<void, Result>();
 | 
					    static_assert(std::is_void<Result>::value, "Result should be void.");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -842,7 +842,7 @@ class IgnoreResultAction {
 | 
				
			|||||||
    typedef typename internal::Function<F>::Result Result;
 | 
					    typedef typename internal::Function<F>::Result Result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Asserts at compile time that F returns void.
 | 
					    // Asserts at compile time that F returns void.
 | 
				
			||||||
    CompileAssertTypesEqual<void, Result>();
 | 
					    static_assert(std::is_void<Result>::value, "Result type should be void.");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return Action<F>(new Impl<F>(action_));
 | 
					    return Action<F>(new Impl<F>(action_));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -125,15 +125,17 @@ TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameIsMixture) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST(PointeeOfTest, WorksForSmartPointers) {
 | 
					TEST(PointeeOfTest, WorksForSmartPointers) {
 | 
				
			||||||
  CompileAssertTypesEqual<int, PointeeOf<std::unique_ptr<int> >::type>();
 | 
					  EXPECT_TRUE(
 | 
				
			||||||
  CompileAssertTypesEqual<std::string,
 | 
					      (std::is_same<int, PointeeOf<std::unique_ptr<int>>::type>::value));
 | 
				
			||||||
                          PointeeOf<std::shared_ptr<std::string> >::type>();
 | 
					  EXPECT_TRUE(
 | 
				
			||||||
 | 
					      (std::is_same<std::string,
 | 
				
			||||||
 | 
					                    PointeeOf<std::shared_ptr<std::string>>::type>::value));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST(PointeeOfTest, WorksForRawPointers) {
 | 
					TEST(PointeeOfTest, WorksForRawPointers) {
 | 
				
			||||||
  CompileAssertTypesEqual<int, PointeeOf<int*>::type>();
 | 
					  EXPECT_TRUE((std::is_same<int, PointeeOf<int*>::type>::value));
 | 
				
			||||||
  CompileAssertTypesEqual<const char, PointeeOf<const char*>::type>();
 | 
					  EXPECT_TRUE((std::is_same<const char, PointeeOf<const char*>::type>::value));
 | 
				
			||||||
  CompileAssertTypesEqual<void, PointeeOf<void*>::type>();
 | 
					  EXPECT_TRUE((std::is_void<PointeeOf<void*>::type>::value));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST(GetRawPointerTest, WorksForSmartPointers) {
 | 
					TEST(GetRawPointerTest, WorksForSmartPointers) {
 | 
				
			||||||
@@ -664,63 +666,66 @@ TEST(StlContainerViewTest, WorksForDynamicNativeArray) {
 | 
				
			|||||||
TEST(FunctionTest, Nullary) {
 | 
					TEST(FunctionTest, Nullary) {
 | 
				
			||||||
  typedef Function<int()> F;  // NOLINT
 | 
					  typedef Function<int()> F;  // NOLINT
 | 
				
			||||||
  EXPECT_EQ(0u, F::ArgumentCount);
 | 
					  EXPECT_EQ(0u, F::ArgumentCount);
 | 
				
			||||||
  CompileAssertTypesEqual<int, F::Result>();
 | 
					  EXPECT_TRUE((std::is_same<int, F::Result>::value));
 | 
				
			||||||
  CompileAssertTypesEqual<std::tuple<>, F::ArgumentTuple>();
 | 
					  EXPECT_TRUE((std::is_same<std::tuple<>, F::ArgumentTuple>::value));
 | 
				
			||||||
  CompileAssertTypesEqual<std::tuple<>, F::ArgumentMatcherTuple>();
 | 
					  EXPECT_TRUE((std::is_same<std::tuple<>, F::ArgumentMatcherTuple>::value));
 | 
				
			||||||
  CompileAssertTypesEqual<void(), F::MakeResultVoid>();
 | 
					  EXPECT_TRUE((std::is_same<void(), F::MakeResultVoid>::value));
 | 
				
			||||||
  CompileAssertTypesEqual<IgnoredValue(), F::MakeResultIgnoredValue>();
 | 
					  EXPECT_TRUE((std::is_same<IgnoredValue(), F::MakeResultIgnoredValue>::value));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST(FunctionTest, Unary) {
 | 
					TEST(FunctionTest, Unary) {
 | 
				
			||||||
  typedef Function<int(bool)> F;  // NOLINT
 | 
					  typedef Function<int(bool)> F;  // NOLINT
 | 
				
			||||||
  EXPECT_EQ(1u, F::ArgumentCount);
 | 
					  EXPECT_EQ(1u, F::ArgumentCount);
 | 
				
			||||||
  CompileAssertTypesEqual<int, F::Result>();
 | 
					  EXPECT_TRUE((std::is_same<int, F::Result>::value));
 | 
				
			||||||
  CompileAssertTypesEqual<bool, F::Arg<0>::type>();
 | 
					  EXPECT_TRUE((std::is_same<bool, F::Arg<0>::type>::value));
 | 
				
			||||||
  CompileAssertTypesEqual<std::tuple<bool>, F::ArgumentTuple>();
 | 
					  EXPECT_TRUE((std::is_same<std::tuple<bool>, F::ArgumentTuple>::value));
 | 
				
			||||||
  CompileAssertTypesEqual<std::tuple<Matcher<bool> >,
 | 
					  EXPECT_TRUE((
 | 
				
			||||||
                          F::ArgumentMatcherTuple>();
 | 
					      std::is_same<std::tuple<Matcher<bool>>, F::ArgumentMatcherTuple>::value));
 | 
				
			||||||
  CompileAssertTypesEqual<void(bool), F::MakeResultVoid>();  // NOLINT
 | 
					  EXPECT_TRUE((std::is_same<void(bool), F::MakeResultVoid>::value));  // NOLINT
 | 
				
			||||||
  CompileAssertTypesEqual<IgnoredValue(bool),  // NOLINT
 | 
					  EXPECT_TRUE((std::is_same<IgnoredValue(bool),                       // NOLINT
 | 
				
			||||||
      F::MakeResultIgnoredValue>();
 | 
					                            F::MakeResultIgnoredValue>::value));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST(FunctionTest, Binary) {
 | 
					TEST(FunctionTest, Binary) {
 | 
				
			||||||
  typedef Function<int(bool, const long&)> F;  // NOLINT
 | 
					  typedef Function<int(bool, const long&)> F;  // NOLINT
 | 
				
			||||||
  EXPECT_EQ(2u, F::ArgumentCount);
 | 
					  EXPECT_EQ(2u, F::ArgumentCount);
 | 
				
			||||||
  CompileAssertTypesEqual<int, F::Result>();
 | 
					  EXPECT_TRUE((std::is_same<int, F::Result>::value));
 | 
				
			||||||
  CompileAssertTypesEqual<bool, F::Arg<0>::type>();
 | 
					  EXPECT_TRUE((std::is_same<bool, F::Arg<0>::type>::value));
 | 
				
			||||||
  CompileAssertTypesEqual<const long&, F::Arg<1>::type>();  // NOLINT
 | 
					  EXPECT_TRUE((std::is_same<const long&, F::Arg<1>::type>::value));  // NOLINT
 | 
				
			||||||
  CompileAssertTypesEqual<std::tuple<bool, const long&>,  // NOLINT
 | 
					  EXPECT_TRUE((std::is_same<std::tuple<bool, const long&>,           // NOLINT
 | 
				
			||||||
                          F::ArgumentTuple>();
 | 
					                            F::ArgumentTuple>::value));
 | 
				
			||||||
  CompileAssertTypesEqual<
 | 
					  EXPECT_TRUE(
 | 
				
			||||||
      std::tuple<Matcher<bool>, Matcher<const long&> >,  // NOLINT
 | 
					      (std::is_same<std::tuple<Matcher<bool>, Matcher<const long&>>,  // NOLINT
 | 
				
			||||||
      F::ArgumentMatcherTuple>();
 | 
					                    F::ArgumentMatcherTuple>::value));
 | 
				
			||||||
  CompileAssertTypesEqual<void(bool, const long&), F::MakeResultVoid>();  // NOLINT
 | 
					  EXPECT_TRUE((std::is_same<void(bool, const long&),  // NOLINT
 | 
				
			||||||
  CompileAssertTypesEqual<IgnoredValue(bool, const long&),  // NOLINT
 | 
					                            F::MakeResultVoid>::value));
 | 
				
			||||||
      F::MakeResultIgnoredValue>();
 | 
					  EXPECT_TRUE((std::is_same<IgnoredValue(bool, const long&),  // NOLINT
 | 
				
			||||||
 | 
					                            F::MakeResultIgnoredValue>::value));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST(FunctionTest, LongArgumentList) {
 | 
					TEST(FunctionTest, LongArgumentList) {
 | 
				
			||||||
  typedef Function<char(bool, int, char*, int&, const long&)> F;  // NOLINT
 | 
					  typedef Function<char(bool, int, char*, int&, const long&)> F;  // NOLINT
 | 
				
			||||||
  EXPECT_EQ(5u, F::ArgumentCount);
 | 
					  EXPECT_EQ(5u, F::ArgumentCount);
 | 
				
			||||||
  CompileAssertTypesEqual<char, F::Result>();
 | 
					  EXPECT_TRUE((std::is_same<char, F::Result>::value));
 | 
				
			||||||
  CompileAssertTypesEqual<bool, F::Arg<0>::type>();
 | 
					  EXPECT_TRUE((std::is_same<bool, F::Arg<0>::type>::value));
 | 
				
			||||||
  CompileAssertTypesEqual<int, F::Arg<1>::type>();
 | 
					  EXPECT_TRUE((std::is_same<int, F::Arg<1>::type>::value));
 | 
				
			||||||
  CompileAssertTypesEqual<char*, F::Arg<2>::type>();
 | 
					  EXPECT_TRUE((std::is_same<char*, F::Arg<2>::type>::value));
 | 
				
			||||||
  CompileAssertTypesEqual<int&, F::Arg<3>::type>();
 | 
					  EXPECT_TRUE((std::is_same<int&, F::Arg<3>::type>::value));
 | 
				
			||||||
  CompileAssertTypesEqual<const long&, F::Arg<4>::type>();  // NOLINT
 | 
					  EXPECT_TRUE((std::is_same<const long&, F::Arg<4>::type>::value));  // NOLINT
 | 
				
			||||||
  CompileAssertTypesEqual<
 | 
					  EXPECT_TRUE(
 | 
				
			||||||
      std::tuple<bool, int, char*, int&, const long&>,  // NOLINT
 | 
					      (std::is_same<std::tuple<bool, int, char*, int&, const long&>,  // NOLINT
 | 
				
			||||||
      F::ArgumentTuple>();
 | 
					                    F::ArgumentTuple>::value));
 | 
				
			||||||
  CompileAssertTypesEqual<
 | 
					  EXPECT_TRUE(
 | 
				
			||||||
 | 
					      (std::is_same<
 | 
				
			||||||
          std::tuple<Matcher<bool>, Matcher<int>, Matcher<char*>, Matcher<int&>,
 | 
					          std::tuple<Matcher<bool>, Matcher<int>, Matcher<char*>, Matcher<int&>,
 | 
				
			||||||
                 Matcher<const long&> >,  // NOLINT
 | 
					                     Matcher<const long&>>,  // NOLINT
 | 
				
			||||||
      F::ArgumentMatcherTuple>();
 | 
					          F::ArgumentMatcherTuple>::value));
 | 
				
			||||||
  CompileAssertTypesEqual<void(bool, int, char*, int&, const long&),  // NOLINT
 | 
					  EXPECT_TRUE(
 | 
				
			||||||
                          F::MakeResultVoid>();
 | 
					      (std::is_same<void(bool, int, char*, int&, const long&),  // NOLINT
 | 
				
			||||||
  CompileAssertTypesEqual<
 | 
					                    F::MakeResultVoid>::value));
 | 
				
			||||||
      IgnoredValue(bool, int, char*, int&, const long&),  // NOLINT
 | 
					  EXPECT_TRUE((
 | 
				
			||||||
      F::MakeResultIgnoredValue>();
 | 
					      std::is_same<IgnoredValue(bool, int, char*, int&, const long&),  // NOLINT
 | 
				
			||||||
 | 
					                   F::MakeResultIgnoredValue>::value));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}  // namespace
 | 
					}  // namespace
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -847,15 +847,6 @@ class GTEST_API_ Random {
 | 
				
			|||||||
  GTEST_DISALLOW_COPY_AND_ASSIGN_(Random);
 | 
					  GTEST_DISALLOW_COPY_AND_ASSIGN_(Random);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Defining a variable of type CompileAssertTypesEqual<T1, T2> will cause a
 | 
					 | 
				
			||||||
// compiler error if T1 and T2 are different types.
 | 
					 | 
				
			||||||
template <typename T1, typename T2>
 | 
					 | 
				
			||||||
struct CompileAssertTypesEqual;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
template <typename T>
 | 
					 | 
				
			||||||
struct CompileAssertTypesEqual<T, T> {
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Turns const U&, U&, const U, and U all into U.
 | 
					// Turns const U&, U&, const U, and U all into U.
 | 
				
			||||||
#define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \
 | 
					#define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \
 | 
				
			||||||
  typename std::remove_const<typename std::remove_reference<T>::type>::type
 | 
					  typename std::remove_const<typename std::remove_reference<T>::type>::type
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -233,7 +233,6 @@ using testing::internal::AppendUserMessage;
 | 
				
			|||||||
using testing::internal::ArrayAwareFind;
 | 
					using testing::internal::ArrayAwareFind;
 | 
				
			||||||
using testing::internal::ArrayEq;
 | 
					using testing::internal::ArrayEq;
 | 
				
			||||||
using testing::internal::CodePointToUtf8;
 | 
					using testing::internal::CodePointToUtf8;
 | 
				
			||||||
using testing::internal::CompileAssertTypesEqual;
 | 
					 | 
				
			||||||
using testing::internal::CopyArray;
 | 
					using testing::internal::CopyArray;
 | 
				
			||||||
using testing::internal::CountIf;
 | 
					using testing::internal::CountIf;
 | 
				
			||||||
using testing::internal::EqFailure;
 | 
					using testing::internal::EqFailure;
 | 
				
			||||||
@@ -7102,18 +7101,12 @@ TEST(IsAProtocolMessageTest, ValueIsFalseWhenTypeIsNotAProtocolMessage) {
 | 
				
			|||||||
  EXPECT_FALSE(IsAProtocolMessage<const ConversionHelperBase>::value);
 | 
					  EXPECT_FALSE(IsAProtocolMessage<const ConversionHelperBase>::value);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Tests that CompileAssertTypesEqual compiles when the type arguments are
 | 
					 | 
				
			||||||
// equal.
 | 
					 | 
				
			||||||
TEST(CompileAssertTypesEqual, CompilesWhenTypesAreEqual) {
 | 
					 | 
				
			||||||
  CompileAssertTypesEqual<void, void>();
 | 
					 | 
				
			||||||
  CompileAssertTypesEqual<int*, int*>();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Tests GTEST_REMOVE_REFERENCE_AND_CONST_.
 | 
					// Tests GTEST_REMOVE_REFERENCE_AND_CONST_.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template <typename T1, typename T2>
 | 
					template <typename T1, typename T2>
 | 
				
			||||||
void TestGTestRemoveReferenceAndConst() {
 | 
					void TestGTestRemoveReferenceAndConst() {
 | 
				
			||||||
  CompileAssertTypesEqual<T1, GTEST_REMOVE_REFERENCE_AND_CONST_(T2)>();
 | 
					  static_assert(std::is_same<T1, GTEST_REMOVE_REFERENCE_AND_CONST_(T2)>::value,
 | 
				
			||||||
 | 
					                "GTEST_REMOVE_REFERENCE_AND_CONST_ failed.");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST(RemoveReferenceToConstTest, Works) {
 | 
					TEST(RemoveReferenceToConstTest, Works) {
 | 
				
			||||||
@@ -7128,7 +7121,8 @@ TEST(RemoveReferenceToConstTest, Works) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
template <typename T1, typename T2>
 | 
					template <typename T1, typename T2>
 | 
				
			||||||
void TestGTestReferenceToConst() {
 | 
					void TestGTestReferenceToConst() {
 | 
				
			||||||
  CompileAssertTypesEqual<T1, GTEST_REFERENCE_TO_CONST_(T2)>();
 | 
					  static_assert(std::is_same<T1, GTEST_REFERENCE_TO_CONST_(T2)>::value,
 | 
				
			||||||
 | 
					                "GTEST_REFERENCE_TO_CONST_ failed.");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST(GTestReferenceToConstTest, Works) {
 | 
					TEST(GTestReferenceToConstTest, Works) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user