[libc++] Restore `basic_ios`'s implicit conversion to `bool` in C++03 mode.
efriedma noted that D104682 broke this test case, reduced from SPEC2006.
#include <istream>
bool a(std::istream a) {
return a.getline(0,0) == 0;
}
We can unbreak it by restoring the conversion to something-convertible-to-bool.
We chose `void*` in order to match libstdc++.
For more ancient history, see PR19460: https://bugs.llvm.org/show_bug.cgi?id=19460
Differential Revision: https://reviews.llvm.org/D107663
NOKEYCHECK=True
GitOrigin-RevId: c1a8f12873783e8f4827437f6b2dddadfc58109d
diff --git a/include/ios b/include/ios
index 3128bca..c9230d6 100644
--- a/include/ios
+++ b/include/ios
@@ -607,8 +607,15 @@
static_assert((is_same<_CharT, typename traits_type::char_type>::value),
"traits_type::char_type must be the same type as CharT");
+#ifdef _LIBCPP_CXX03_LANG
+ // Preserve the ability to compare with literal 0,
+ // and implicitly convert to bool, but not implicitly convert to int.
+ _LIBCPP_INLINE_VISIBILITY
+ operator void*() const {return fail() ? nullptr : (void*)this;}
+#else
_LIBCPP_INLINE_VISIBILITY
explicit operator bool() const {return !fail();}
+#endif
_LIBCPP_INLINE_VISIBILITY bool operator!() const {return fail();}
_LIBCPP_INLINE_VISIBILITY iostate rdstate() const {return ios_base::rdstate();}