[libcxx-commits] [PATCH] D107663: [libc++] Restore `basic_ios`'s implicit conversion to `bool` in C++03 mode.
Arthur O'Dwyer via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Aug 10 16:45:03 PDT 2021
Quuxplusone updated this revision to Diff 365630.
Quuxplusone added a comment.
Convert to `void*` instead of `const void*`. (This requires casting away const.)
Poke buildkite to make sure this last change didn't break anything in the test suite.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D107663/new/
https://reviews.llvm.org/D107663
Files:
libcxx/include/ios
libcxx/test/std/input.output/iostreams.base/ios/iostate.flags/bool.pass.cpp
Index: libcxx/test/std/input.output/iostreams.base/ios/iostate.flags/bool.pass.cpp
===================================================================
--- libcxx/test/std/input.output/iostreams.base/ios/iostate.flags/bool.pass.cpp
+++ libcxx/test/std/input.output/iostreams.base/ios/iostate.flags/bool.pass.cpp
@@ -27,7 +27,12 @@
static_assert((!std::is_convertible<std::ios, void*>::value), "");
static_assert((!std::is_convertible<std::ios, int>::value), "");
static_assert((!std::is_convertible<std::ios const&, int>::value), "");
- static_assert((!std::is_convertible<std::ios, bool>::value), "");
+#if TEST_STD_VER >= 11
+ static_assert(!std::is_convertible<std::ios, bool>::value, "");
+#else
+ static_assert(std::is_convertible<std::ios, bool>::value, "");
+ (void)(ios == 0); // SPEC2006 apparently relies on this to compile
+#endif
return 0;
}
Index: libcxx/include/ios
===================================================================
--- libcxx/include/ios
+++ libcxx/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();}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107663.365630.patch
Type: text/x-patch
Size: 1727 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210810/0ad79bfc/attachment-0001.bin>
More information about the libcxx-commits
mailing list