[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 18:49:52 PDT 2021
Quuxplusone updated this revision to Diff 365641.
Quuxplusone added a comment.
Welp, obviously that broke the existing test that tests `!std::is_convertible<std::istream&, void*>`.
So I propose we change the test, on the theory that "match libstdc++'s behavior exactly" is more important than "match libc++'s old behavior in some but not all obscure corner cases" (which is what I was trying to achieve with `operator const void*` in the original version of this PR). @ldionne, does this still seem reasonable to you?
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
@@ -24,10 +24,16 @@
assert(static_cast<bool>(ios) == !ios.fail());
ios.setstate(std::ios::failbit);
assert(static_cast<bool>(ios) == !ios.fail());
- 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, void*>::value, "");
+ static_assert(!std::is_convertible<std::ios, bool>::value, "");
+#else
+ static_assert(std::is_convertible<std::ios, void*>::value, "");
+ 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.365641.patch
Type: text/x-patch
Size: 2009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210811/aaf65ff6/attachment-0001.bin>
More information about the libcxx-commits
mailing list