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/gtest.h | |
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/gtest.h')
-rw-r--r-- | include/gtest/gtest.h | 40 |
1 files changed, 27 insertions, 13 deletions
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); } }; |