I'm using Google Test v1.7
I've created a custom operator ==
which ASSERT_EQ
can't find, but which can be found if used directly. Here's the code
#include <vector>
#include <deque>
#include "gtest/gtest.h"
template< typename T> struct bar { T b; };
template< typename T>
bool operator == ( const std::vector<T>& v, const bar<T>& b ) { return false; }
template< typename T>
bool operator==( const std::vector<T>& v , const std::deque<T>& d) { return false; }
TEST( A, B ) {
std::vector<char> vec;
std::deque<char> deq;
bar<char> b;
// compiles
ASSERT_EQ( vec, b );
// compiles
vec == deq;
// doesn't compile
ASSERT_EQ( vec, deq );
}
The ASSERT_EQ( vec, deq )
line results in the following message from Apple 6.0 clang:
test/gtest.h:18861:16: error: invalid operands to binary expression ('const std::__1::vector<char, std::__1::allocator<char> >' and 'const
std::__1::deque<char, std::__1::allocator<char> >')
if (expected == actual) {
~~~~~~~~ ^ ~~~~~~
../x86_64-linux_debian-7/tests/gtest/gtest.h:18897:12: note: in instantiation of function template specialization 'testing::internal::CmpHelperEQ<std::__1::vector<char,
std::__1::allocator<char> >, std::__1::deque<char, std::__1::allocator<char> > >' requested here
return CmpHelperEQ(expected_expression, actual_expression, expected,
^
tst.cc:27:5: note: in instantiation of function template specialization 'testing::internal::EqHelper<false>::Compare<std::__1::vector<char, std::__1::allocator<char> >,
std::__1::deque<char, std::__1::allocator<char> > >' requested here
ASSERT_EQ( vec, deq );
^
while gcc 4.7.2 lists all of the templates it tried and failed to make expected == actual
work, ignoring the one I provided.
What I don't understand is why
ASSERT_EQ( vec, b )
finds the providedoperator ==
; andvec == deq
compiles; butASSERT_EQ( vec, deq )
doesn't.
Could someone please shine some light on this? It's got to be something blazingly obvious, but I can't see it.