summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/input.output/iostreams.base
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2016-12-30 14:05:52 +0000
committerEric Fiselier <eric@efcs.ca>2016-12-30 14:05:52 +0000
commit1b06dfe7b7e8514f823385352e7408f041e45fcf (patch)
tree58d2a223910fc42e2da2b26a6794034d30c7efd7 /libcxx/test/std/input.output/iostreams.base
parent56d0806644f37abc26d5ea9abf91114e52cd3fa7 (diff)
downloadbcm5719-llvm-1b06dfe7b7e8514f823385352e7408f041e45fcf.tar.gz
bcm5719-llvm-1b06dfe7b7e8514f823385352e7408f041e45fcf.zip
Recommit r290750: Fix PR19460 - std::ios is convertible to int.
There were two problems with the initial fix. 1. The added tests flushed out that we misconfigured _LIBCPP_EXPLICIT with GCC. 2. Because the boolean type was a member function template it caused weird link errors. I'm assuming due to the vague linkage rules. This time the bool type is a non-template member function pointer. That seems to have fixed the failing tests. Plus it will end up generating less symbols overall, since the bool type is no longer per instantiation. original commit message below ----------------------------- 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: 290754
Diffstat (limited to 'libcxx/test/std/input.output/iostreams.base')
-rw-r--r--libcxx/test/std/input.output/iostreams.base/ios/iostate.flags/bool.pass.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/libcxx/test/std/input.output/iostreams.base/ios/iostate.flags/bool.pass.cpp b/libcxx/test/std/input.output/iostreams.base/ios/iostate.flags/bool.pass.cpp
index 0de889e549c..4e3faa27c40 100644
--- a/libcxx/test/std/input.output/iostreams.base/ios/iostate.flags/bool.pass.cpp
+++ b/libcxx/test/std/input.output/iostreams.base/ios/iostate.flags/bool.pass.cpp
@@ -14,12 +14,21 @@
// operator unspecified-bool-type() const;
#include <ios>
+#include <type_traits>
#include <cassert>
+#include "test_macros.h"
+
int main()
{
std::ios ios(0);
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), "");
+#if TEST_STD_VER >= 11
+ static_assert((!std::is_convertible<std::ios, bool>::value), "");
+#endif
}
OpenPOWER on IntegriCloud