chyh1990 / googletest

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

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

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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