I've run into the same problem recently with GTest 1.8.0, but only when using Visual Studio 2019 in C++17 mode. Visual Studio 2019 works fine in C++14 mode, and neither Clang nor GCC seem to have the same problem in C++17 mode.
The issue is that with C++17 there's a new overload in the standard library for the std::ostream::operator<<
that takes a nullptr_t
, but GTest also provides its own, so your compiler does not know which one to use.
If you have full control over your version of GTest then https://github.com/google/googletest/pull/1620/commits/f66ab00704cd47e4e63ef6d425ca14b9192aaebb is a change for GTest-1.8.0 that resolves the issue: It's not as easy as deleting the overload, because the function in question is a template whose other instantiations are still used. Instead, the solution is to define an explicit void PrintTo(std::nullptr_t, ::std::ostream* os)
function that will then automatically be used, no longer deferring to the ambiguous overloads.
When modifying GTest is not an option then the solutions mentioned in the other answers to not use EXPECT_EQ
/EXPECT_NE
when one parameter is a nullptr_t
are your best bet.
EXPECT_TRUE(ptr);
? – Fanny>
character render horribly when you put them in blockquotes. Better indent 4 spaces and render as code. I'd edit myself, but the mobile UI makes this tricky. – CryptogramEXPECT_NE
and read the first paragraphs for some background – Histrionicsusing namespace std;
somewhere? – UnworthyEXPECT_TRUE(ptr);
works. Thank you! – Chanticleernullptr
), and they interact with the old with the old features... in an unpredictable way. – Hypergolic