Minor fix for gtest-printers_test.cc under Visual Studio 2010

37 views
Skip to first unread message

Douglas Greiman

unread,
Oct 14, 2011, 12:03:56 AM10/14/11
to Google C++ Testing Framework
Hi,

This test fails to compile on Visual Studio 2010 with the error:

[snip] 10.0\VC\include\tuple(127): error C2440: 'initializing' :
cannot convert from 'int' to 'void *'
[snip] 10.0\VC\include\tuple(127): error C2439:
'std::tr1::_Cons_node<_Car,_Cdr>::_Value' : member could not be
initialized

The problem seems to be some complicated template thing interacting
with the nullptr changes in C++11. A similar problem is described
here:

https://connect.microsoft.com/VisualStudio/feedback/details/520043/error-converting-from-null-to-a-pointer-type-in-std-pair

The fix is to add an explicit cast to (void*):

$ svn diff
Index: test/gtest-printers_test.cc
===================================================================
--- test/gtest-printers_test.cc (revision 602)
+++ test/gtest-printers_test.cc (working copy)
@@ -1004,7 +1004,7 @@
const char* const str = "8";
tuple<bool, char, short, testing::internal::Int32, // NOLINT
testing::internal::Int64, float, double, const char*, void*,
string>
- t10(false, 'a', 3, 4, 5, 1.5F, -2.5, str, NULL, "10");
+ t10(false, 'a', 3, 4, 5, 1.5F, -2.5, str,
static_cast<void*>(NULL), "10");
EXPECT_EQ("(false, 'a' (97, 0x61), 3, 4, 5, 1.5, -2.5, " +
PrintPointer(str) +
" pointing to \"8\", NULL, \"10\")",
Print(t10));

I, Douglas Greiman, release this diff to the public domain permanently
and irrevocably, etc.

Vlad Losev

unread,
Oct 16, 2011, 5:19:58 PM10/16/11
to Google C++ Testing Framework
Does using testing::internal::ImplicitCast_<> instead of static_cast<> work for you?

Douglas Greiman

unread,
Oct 19, 2011, 8:27:03 PM10/19/11
to Google C++ Testing Framework
Yes, that also seems to work fine.

Vlad Losev

unread,
Oct 24, 2011, 2:34:34 PM10/24/11
to Google C++ Testing Framework
Checked this into SVN as revision 603.
Reply all
Reply to author
Forward
0 new messages