[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
Wed Aug 11 10:39:56 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc1a8f1287378: [libc++] Restore `basic_ios`'s implicit conversion to `bool` in C++03 mode. (authored by arthur.j.odwyer).
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.365796.patch
Type: text/x-patch
Size: 2009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210811/18104db5/attachment-0001.bin>
More information about the libcxx-commits
mailing list