diff options
author | Derek Mauro <dmauro@google.com> | 2022-04-21 20:22:38 (GMT) |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-04-21 20:23:32 (GMT) |
commit | b85864c64758dec007208e56af933fc3f52044ee (patch) | |
tree | 082332154a914ffe29776d83797b2820f0170870 /googlemock | |
parent | 8ccdb9d56d07b9169ecd17f1164f251a637c250e (diff) | |
download | googletest-b85864c64758dec007208e56af933fc3f52044ee.zip googletest-b85864c64758dec007208e56af933fc3f52044ee.tar.gz googletest-b85864c64758dec007208e56af933fc3f52044ee.tar.bz2 |
Eliminate the legacy GTEST_COMPILE_ASSERT_ macro
PiperOrigin-RevId: 443462203
Change-Id: I0c43f981663a7531ff5da4d4be01fb3d6762273d
Diffstat (limited to 'googlemock')
-rw-r--r-- | googlemock/include/gmock/gmock-actions.h | 18 | ||||
-rw-r--r-- | googlemock/include/gmock/gmock-matchers.h | 31 |
2 files changed, 23 insertions, 26 deletions
diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index 1038b02..e84670a 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -915,9 +915,8 @@ class ReturnAction { // and put the typedef both here (for use in assert statement) and // in the Impl class. But both definitions must be the same. typedef typename Function<F>::Result Result; - GTEST_COMPILE_ASSERT_( - !std::is_reference<Result>::value, - use_ReturnRef_instead_of_Return_to_return_a_reference); + static_assert(!std::is_reference<Result>::value, + "use ReturnRef instead of Return to return a reference"); static_assert(!std::is_void<Result>::value, "Can't use Return() on an action expected to return `void`."); return Action<F>(new Impl<R, F>(value_)); @@ -945,8 +944,8 @@ class ReturnAction { Result Perform(const ArgumentTuple&) override { return value_; } private: - GTEST_COMPILE_ASSERT_(!std::is_reference<Result>::value, - Result_cannot_be_a_reference_type); + static_assert(!std::is_reference<Result>::value, + "Result cannot be a reference type"); // We save the value before casting just in case it is being cast to a // wrapper type. R value_before_cast_; @@ -1020,8 +1019,8 @@ class ReturnRefAction { // Asserts that the function return type is a reference. This // catches the user error of using ReturnRef(x) when Return(x) // should be used, and generates some helpful error message. - GTEST_COMPILE_ASSERT_(std::is_reference<Result>::value, - use_Return_instead_of_ReturnRef_to_return_a_value); + static_assert(std::is_reference<Result>::value, + "use Return instead of ReturnRef to return a value"); return Action<F>(new Impl<F>(ref_)); } @@ -1062,9 +1061,8 @@ class ReturnRefOfCopyAction { // Asserts that the function return type is a reference. This // catches the user error of using ReturnRefOfCopy(x) when Return(x) // should be used, and generates some helpful error message. - GTEST_COMPILE_ASSERT_( - std::is_reference<Result>::value, - use_Return_instead_of_ReturnRefOfCopy_to_return_a_value); + static_assert(std::is_reference<Result>::value, + "use Return instead of ReturnRefOfCopy to return a value"); return Action<F>(new Impl<F>(value_)); } diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 9750d84..fb46715 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -533,19 +533,18 @@ inline Matcher<T> SafeMatcherCast(const Matcher<U>& matcher) { "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<T>::value || !std::is_reference<U>::value, - cannot_convert_non_reference_arg_to_reference); + static_assert(std::is_reference<T>::value || !std::is_reference<U>::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_( + static_assert( kTIsOther || kUIsOther || (internal::LosslessArithmeticConvertible<RawT, RawU>::value), - conversion_of_arithmetic_types_must_be_lossless); + "conversion of arithmetic types must be lossless"); return MatcherCast<T>(matcher); } @@ -678,9 +677,9 @@ bool TupleMatches(const MatcherTuple& matcher_tuple, const ValueTuple& value_tuple) { // Makes sure that matcher_tuple and value_tuple have the same // number of fields. - GTEST_COMPILE_ASSERT_(std::tuple_size<MatcherTuple>::value == - std::tuple_size<ValueTuple>::value, - matcher_and_value_have_different_numbers_of_fields); + static_assert(std::tuple_size<MatcherTuple>::value == + std::tuple_size<ValueTuple>::value, + "matcher and value have different numbers of fields"); return TuplePrefix<std::tuple_size<ValueTuple>::value>::Matches(matcher_tuple, value_tuple); } @@ -2570,9 +2569,9 @@ class WhenSortedByMatcher { // container and the RHS container respectively. template <typename TupleMatcher, typename RhsContainer> class PointwiseMatcher { - GTEST_COMPILE_ASSERT_( + static_assert( !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(RhsContainer)>::value, - use_UnorderedPointwise_with_hash_tables); + "use UnorderedPointwise with hash tables"); public: typedef internal::StlContainerView<RhsContainer> RhsView; @@ -2591,9 +2590,9 @@ class PointwiseMatcher { template <typename LhsContainer> operator Matcher<LhsContainer>() const { - GTEST_COMPILE_ASSERT_( + static_assert( !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)>::value, - use_UnorderedPointwise_with_hash_tables); + "use UnorderedPointwise with hash tables"); return Matcher<LhsContainer>( new Impl<const LhsContainer&>(tuple_matcher_, rhs_)); @@ -3725,10 +3724,10 @@ class ElementsAreMatcher { template <typename Container> operator Matcher<Container>() const { - GTEST_COMPILE_ASSERT_( + static_assert( !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>::value || ::std::tuple_size<MatcherTuple>::value < 2, - use_UnorderedElementsAre_with_hash_tables); + "use UnorderedElementsAre with hash tables"); typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; typedef typename internal::StlContainerView<RawContainer>::type View; @@ -3776,9 +3775,9 @@ class ElementsAreArrayMatcher { template <typename Container> operator Matcher<Container>() const { - GTEST_COMPILE_ASSERT_( + static_assert( !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>::value, - use_UnorderedElementsAreArray_with_hash_tables); + "use UnorderedElementsAreArray with hash tables"); return Matcher<Container>(new ElementsAreMatcherImpl<const Container&>( matchers_.begin(), matchers_.end())); |