diff options
author | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2011-01-10 18:17:59 (GMT) |
---|---|---|
committer | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2011-01-10 18:17:59 (GMT) |
commit | 48b1315108cdba8f37394aedb8098102ca00e8b9 (patch) | |
tree | c8d12776d79b243cb2c9dcb307965b6e4582959d /include/gtest | |
parent | afaefb0e30366cf8bedb41daf14dc9e17a5d1ff9 (diff) | |
download | googletest-48b1315108cdba8f37394aedb8098102ca00e8b9.zip googletest-48b1315108cdba8f37394aedb8098102ca00e8b9.tar.gz googletest-48b1315108cdba8f37394aedb8098102ca00e8b9.tar.bz2 |
Fixes GCC 4.6 warnings (patch by Jeffrey Yasskin).
Diffstat (limited to 'include/gtest')
-rw-r--r-- | include/gtest/gtest-typed-test.h | 6 | ||||
-rw-r--r-- | include/gtest/gtest.h | 40 | ||||
-rw-r--r-- | include/gtest/internal/gtest-internal.h | 9 |
3 files changed, 38 insertions, 17 deletions
diff --git a/include/gtest/gtest-typed-test.h b/include/gtest/gtest-typed-test.h index eb6b0b8..2d3b8bf 100644 --- a/include/gtest/gtest-typed-test.h +++ b/include/gtest/gtest-typed-test.h @@ -175,7 +175,7 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes); typedef gtest_TypeParam_ TypeParam; \ virtual void TestBody(); \ }; \ - bool gtest_##CaseName##_##TestName##_registered_ = \ + bool gtest_##CaseName##_##TestName##_registered_ GTEST_ATTRIBUTE_UNUSED_ = \ ::testing::internal::TypeParameterizedTest< \ CaseName, \ ::testing::internal::TemplateSel< \ @@ -229,7 +229,7 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes); typedef gtest_TypeParam_ TypeParam; \ virtual void TestBody(); \ }; \ - static bool gtest_##TestName##_defined_ = \ + static bool gtest_##TestName##_defined_ GTEST_ATTRIBUTE_UNUSED_ = \ GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).AddTestName(\ __FILE__, __LINE__, #CaseName, #TestName); \ } \ @@ -248,7 +248,7 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes); // since some compilers may choke on '>>' when passing a template // instance (e.g. Types<int>) #define INSTANTIATE_TYPED_TEST_CASE_P(Prefix, CaseName, Types) \ - bool gtest_##Prefix##_##CaseName = \ + bool gtest_##Prefix##_##CaseName GTEST_ATTRIBUTE_UNUSED_ = \ ::testing::internal::TypeParameterizedTestCase<CaseName, \ GTEST_CASE_NAMESPACE_(CaseName)::gtest_AllTests_, \ ::testing::internal::TypeList< Types >::type>::Register(\ diff --git a/include/gtest/gtest.h b/include/gtest/gtest.h index f7ed948..79e604c 100644 --- a/include/gtest/gtest.h +++ b/include/gtest/gtest.h @@ -1342,7 +1342,7 @@ class EqHelper { }; // This specialization is used when the first argument to ASSERT_EQ() -// is a null pointer literal. +// is a null pointer literal, like NULL, false, or 0. template <> class EqHelper<true> { public: @@ -1351,24 +1351,38 @@ class EqHelper<true> { // NOT a pointer, e.g. ASSERT_EQ(0, AnIntFunction()) or // EXPECT_EQ(false, a_bool). template <typename T1, typename T2> - static AssertionResult Compare(const char* expected_expression, - const char* actual_expression, - const T1& expected, - const T2& actual) { + static AssertionResult Compare( + const char* expected_expression, + const char* actual_expression, + const T1& expected, + const T2& actual, + // The following line prevents this overload from being considered if T2 + // is not a pointer type. We need this because ASSERT_EQ(NULL, my_ptr) + // expands to Compare("", "", NULL, my_ptr), which requires a conversion + // to match the Secret* in the other overload, which would otherwise make + // this template match better. + typename EnableIf<!is_pointer<T2>::value>::type* = 0) { return CmpHelperEQ(expected_expression, actual_expression, expected, actual); } - // This version will be picked when the second argument to - // ASSERT_EQ() is a pointer, e.g. ASSERT_EQ(NULL, a_pointer). - template <typename T1, typename T2> - static AssertionResult Compare(const char* expected_expression, - const char* actual_expression, - const T1& /* expected */, - T2* actual) { + // This version will be picked when the second argument to ASSERT_EQ() is a + // pointer, e.g. ASSERT_EQ(NULL, a_pointer). + template <typename T> + static AssertionResult Compare( + const char* expected_expression, + const char* actual_expression, + // We used to have a second template parameter instead of Secret*. That + // template parameter would deduce to 'long', making this a better match + // than the first overload even without the first overload's EnableIf. + // Unfortunately, gcc with -Wconversion-null warns when "passing NULL to + // non-pointer argument" (even a deduced integral argument), so the old + // implementation caused warnings in user code. + Secret* /* expected (NULL) */, + T* actual) { // We already know that 'expected' is a null pointer. return CmpHelperEQ(expected_expression, actual_expression, - static_cast<T2*>(NULL), actual); + static_cast<T*>(NULL), actual); } }; diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 3307855..2c08238 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -919,6 +919,13 @@ typedef char IsNotContainer; template <class C> IsNotContainer IsContainerTest(...) { return '\0'; } +// EnableIf<condition>::type is void when 'Cond' is true, and +// undefined when 'Cond' is false. To use SFINAE to make a function +// overload only apply when a particular expression is true, add +// "typename EnableIf<expression>::type* = 0" as the last parameter. +template<bool> struct EnableIf; +template<> struct EnableIf<true> { typedef void type; }; // NOLINT + // Utilities for native arrays. // ArrayEq() compares two k-dimensional native arrays using the @@ -1182,7 +1189,7 @@ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\ private:\ virtual void TestBody();\ - static ::testing::TestInfo* const test_info_;\ + static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_;\ GTEST_DISALLOW_COPY_AND_ASSIGN_(\ GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\ };\ |