summaryrefslogtreecommitdiffstats
path: root/libcxx/include/ios
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2016-12-30 12:44:58 +0000
committerEric Fiselier <eric@efcs.ca>2016-12-30 12:44:58 +0000
commit2131a71c0525c556b73441dc905e3956e8e54f70 (patch)
tree24528f56b798a8a14a40fa8822a805e821f37687 /libcxx/include/ios
parenta8d45de6ce8afbb529a24887ec7d8d66c3b9e04a (diff)
downloadbcm5719-llvm-2131a71c0525c556b73441dc905e3956e8e54f70.tar.gz
bcm5719-llvm-2131a71c0525c556b73441dc905e3956e8e54f70.zip
Fix PR19460 - std::ios is convertible to int.
std::basic_ios has an operator bool(). In C++11 and later it is explicit, and only allows contextual implicit conversions. However explicit isn't available in C++03 which causes std::istream (et al) to have an implicit conversion to int. This can easily cause ambiguities when calling operator<< and operator>>. This patch uses a "bool-like" type in C++03 to work around this. The "bool-like" type is an arbitrary pointer to member function type. It will not convert to either int or void*, but will convert to bool. llvm-svn: 290750
Diffstat (limited to 'libcxx/include/ios')
-rw-r--r--libcxx/include/ios17
1 files changed, 15 insertions, 2 deletions
diff --git a/libcxx/include/ios b/libcxx/include/ios
index cbea478a74a..dfeb1f62eed 100644
--- a/libcxx/include/ios
+++ b/libcxx/include/ios
@@ -585,9 +585,22 @@ public:
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
+#if defined(_LIBCPP_CXX03_LANG)
+private:
+ struct __bool_tag {};
+ typedef void (basic_ios::*_BoolType)(__bool_tag) const;
+ void __true_value(__bool_tag) const {}
+
+public:
+ _LIBCPP_ALWAYS_INLINE
+ operator _BoolType() const {
+ return !fail() ? &basic_ios::__true_value : nullptr;
+ }
+#else
_LIBCPP_ALWAYS_INLINE
- _LIBCPP_EXPLICIT
- operator bool() const {return !fail();}
+ _LIBCPP_EXPLICIT operator bool() const {return !fail();}
+#endif
+
_LIBCPP_ALWAYS_INLINE bool operator!() const {return fail();}
_LIBCPP_ALWAYS_INLINE iostate rdstate() const {return ios_base::rdstate();}
_LIBCPP_ALWAYS_INLINE void clear(iostate __state = goodbit) {ios_base::clear(__state);}
OpenPOWER on IntegriCloud