Strange gmock compile error when using a forward declared class (Part 2)

417 views
Skip to first unread message

Mike

unread,
Mar 24, 2010, 10:47:40 PM3/24/10
to Google C++ Mocking Framework
I'm trying to figure out how I can modify gmock-printers.h, so that
when it tries to print an argument in a mock method that uses an
incomplete type, it will just print "incomplete type" instead of
aborting with a syntax error. I'm not much of a meta-template
programming wizard, but I looked at tr1's type_traits and boost's
type_traits to see if there was something like a "is_complete<T>"
template, but couldn't find it. Is this even possible (detecting an
incomplete type at compile time)?

Mike

Zhanyong Wan (λx.x x)

unread,
Mar 25, 2010, 12:44:48 AM3/25/10
to Mike, Google C++ Mocking Framework
Hi,

I doubt this is possible. Even if it is, it's not a good idea as it
seems to be. If what you described is implemented, the behavior of
the mock will depends on the order of #includes. If the header
defining your type is #included before the mock class, you'll see the
value printed correctly. Otherwise you'll see "incomplete type".

This inconsistency itself may not be too bad, until you think about
what happens if you link two .cpp files together. If the #include
orders are different in the two files, you violate C++'s dreaded
One-Definition Rule. The result, is Undefined Behavior. All hell can
break loose.

My suggestion is to just #include the necessary headers for your mock
class definition.

--
Zhanyong

Reply all
Reply to author
Forward
0 new messages