google/googletest

explicit bool conversion for c++11 streams breaks previously valid code

GoogleCodeExporter opened this issue · 3 comments

In C++11, the standard streams do not have an `operator void*()`, but have an 
`explicit operator bool()` instead. This change breaks code like:

    std::stringstream ss;
    ASSERT_TRUE(ss);

In the expansion of `ASSERT_TRUE`, an `AssertionResult` is constructed from 
`ss`. Since it expects a boolean but `ss` requires an explicit conversion, 
compilation fails. While this is not caused by GoogleTest but rather by a 
change in the standard, it might be desirable to provide a workaround. I'm just 
highlighting the issue.

Original issue reported on code.google.com by louis.di...@gmail.com on 6 Apr 2013 at 3:33

Simply change  in 
https://code.google.com/p/googletest/source/browse/trunk/include/gtest/internal/
gtest-internal.h#1108

::testing::AssertionResult(expression))


to

::testing::AssertionResult(bool(expression)))

Original comment by virkony on 16 Apr 2014 at 12:18

Klaim commented

+1

Though I would have changed it to static_assert or

::testing::AssertionResult(expression ? true : false)
xmxwx commented

The issue has been already fixed since 8120f66.