Fixes GCC 4.6 warnings (patch by Jeffrey Yasskin).
This commit is contained in:
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user