xinguai / googletest

Automatically exported from code.google.com/p/googletest
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

googlemock + protobuf + gcc4.4.0 #180

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I've been using gmock in conjunction with Google protobufs. I recently 
switched my compiler from gcc4.3.2 to gcc4.4.0

After making the compiler switch, I began noticing some peculiar behavior.  
It looks like both gmock and protobuf both define a "down_cast" template 
function.  Specifically inside these two files:

GMOCK/include/gmock/internal/gmock-port.h
PROTOBUF/include/google/protobuf/stubs/common.h

Now that I'm using gcc4.4.0, this compile error has been showing up.

../../GMOCK/include/gmock/gmock-spec-builders.h:1086: error: call of 
overloaded ‘down_cast(testing::internal::FunctionMockerBase<void(const 
RepeatedFieldInt&, MyDataStructure&)>* const)’ is ambiguous
../../GMOCK/include/gmock/internal/gmock-port.h:154: note: candidates are: 
To testing::internal::down_cast(From*) [with To = 
testing::internal::FunctionMocker<void(const RepeatedFieldInt&, 
MyDataStructure&)>*, From = 
testing::internal::FunctionMockerBase<void(const RepeatedFieldInt&, 
MyDataStructure&)>]
../../GMOCK/include/google/protobuf/stubs/common.h:269: note:                 
To google::protobuf::internal::down_cast(From*) [with To = 
testing::internal::FunctionMocker<void(const RepeatedFieldInt&, 
MyDataStructure&)>*, From = 
testing::internal::FunctionMockerBase<void(const RepeatedFieldInt&, 
SequencedUpdateMap&)>]
../../GMOCK/include/gmock/gmock-spec-builders.h: In member function 
‘testing::internal::FunctionMocker<F>& 
testing::internal::FunctionMockerBase<F>::RegisterOwner(const void*) [with 
F = void(const std::string&, MyDataStructure&)]’:
mocks/MockMyClass.h:194:   instantiated from here

I'm not sure what's causing this name conflict problem, since it didn't 
show up in gcc4.3.2.  

Just to test things out, I hacked the gmock-port.h code and renamed 
"down_cast" to "down_castt" to sidestep the problem.  After I renamed 
things this way, everything appears to work as expected, and this error 
goes away.  (It seems like namespaces should have taken care of this 
conflict - perhaps gcc4.4.0 has different namespace resolution rules?)

What steps will reproduce the problem?
1. Mock a function that takes a protobuf & as a parameter.
2. Compile with gcc4.4.0
3. down_cast overloading error will appear

What is the expected output? What do you see instead?

Expected output: No compile error.
Actual output: Compile error.

What version of the product are you using? On what operating system?

protobuf-2.1.0
gmock-1.1.0
gcc4.4.0
Fedora 11

Please provide any additional information below.

Just to be clear - this problem does not appear when using gcc4.3.2

Original issue reported on code.google.com by jeungs...@gmail.com on 6 Aug 2009 at 6:08

GoogleCodeExporter commented 9 years ago
(This is a gmock issue, not a gtest one.)

This problem should have been fixed in revision 128 of gmock:

http://code.google.com/p/googlemock/source/detail?r=128&path=/trunk/include/gmoc
k/gmock-spec-builders.h

It should be included in the next release of gmock.  Or you can check out the 
SVN
trunk and get the fix now.

Original comment by zhanyong...@gmail.com on 21 Aug 2009 at 12:20