diff options
author | Louis Dionne <ldionne@apple.com> | 2019-04-02 21:43:07 +0000 |
---|---|---|
committer | Louis Dionne <ldionne@apple.com> | 2019-04-02 21:43:07 +0000 |
commit | 1754774369ac8bd5b0d1e0cc88adc4acba9d2666 (patch) | |
tree | 555261ab4f3e2950e0d184f7204bd61092e0d7fc /libcxx/test/std/utilities | |
parent | fc5a176f6aae00b2848b337addb87c097a093627 (diff) | |
download | bcm5719-llvm-1754774369ac8bd5b0d1e0cc88adc4acba9d2666.tar.gz bcm5719-llvm-1754774369ac8bd5b0d1e0cc88adc4acba9d2666.zip |
[libc++] Fix error flags and exceptions propagated from input stream operations
Summary:
Before this patch, we would only ever throw an exception if the badbit
was set on the stream. The Standard is currently very unclear on how
exceptions should be propagated and what error flags should be set by
the input stream operations. This commit changes libc++ to behave under
a different (but valid) interpretation of the Standard. This interpretation
of the Standard matches what other implementations are doing.
I will submit a paper in San Diego to clarify the Standard such that the
interpretation used in this commit (and other implementations) is the only
possible one.
PR21586
PR15949
rdar://problem/15347558
Reviewers: mclow.lists, EricWF
Subscribers: christof, dexonsmith, cfe-commits
Differential Revision: https://reviews.llvm.org/D49863
llvm-svn: 357531
Diffstat (limited to 'libcxx/test/std/utilities')
-rw-r--r-- | libcxx/test/std/utilities/template.bitset/bitset.operators/stream_in.pass.cpp | 55 | ||||
-rw-r--r-- | libcxx/test/std/utilities/template.bitset/bitset.operators/stream_out.pass.cpp | 4 |
2 files changed, 50 insertions, 9 deletions
diff --git a/libcxx/test/std/utilities/template.bitset/bitset.operators/stream_in.pass.cpp b/libcxx/test/std/utilities/template.bitset/bitset.operators/stream_in.pass.cpp index 9abe19c7c87..1cb92ea3458 100644 --- a/libcxx/test/std/utilities/template.bitset/bitset.operators/stream_in.pass.cpp +++ b/libcxx/test/std/utilities/template.bitset/bitset.operators/stream_in.pass.cpp @@ -9,19 +9,60 @@ // test: // template <class charT, class traits, size_t N> -// basic_ostream<charT, traits>& -// operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x); +// basic_istream<charT, traits>& +// operator>>(basic_istream<charT, traits>& is, bitset<N>& x); #include <bitset> #include <sstream> #include <cassert> +#include "test_macros.h" int main(int, char**) { - std::istringstream in("01011010"); - std::bitset<8> b; - in >> b; - assert(b.to_ulong() == 0x5A); + { + std::istringstream in("01011010"); + std::bitset<8> b; + in >> b; + assert(b.to_ulong() == 0x5A); + } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + std::stringbuf sb; + std::istream is(&sb); + is.exceptions(std::ios::failbit); - return 0; + bool threw = false; + try { + std::bitset<8> b; + is >> b; + } catch (std::ios::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } + { + std::stringbuf sb; + std::istream is(&sb); + is.exceptions(std::ios::eofbit); + + bool threw = false; + try { + std::bitset<8> b; + is >> b; + } catch (std::ios::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } +#endif // TEST_HAS_NO_EXCEPTIONS + + return 0; } diff --git a/libcxx/test/std/utilities/template.bitset/bitset.operators/stream_out.pass.cpp b/libcxx/test/std/utilities/template.bitset/bitset.operators/stream_out.pass.cpp index 2c4ce1e4881..43c20f848bb 100644 --- a/libcxx/test/std/utilities/template.bitset/bitset.operators/stream_out.pass.cpp +++ b/libcxx/test/std/utilities/template.bitset/bitset.operators/stream_out.pass.cpp @@ -9,8 +9,8 @@ // test: // template <class charT, class traits, size_t N> -// basic_istream<charT, traits>& -// operator>>(basic_istream<charT, traits>& is, bitset<N>& x); +// basic_ostream<charT, traits>& +// operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x); #include <bitset> #include <sstream> |