diff options
author | Louis Dionne <ldionne@apple.com> | 2019-04-05 16:33:37 +0000 |
---|---|---|
committer | Louis Dionne <ldionne@apple.com> | 2019-04-05 16:33:37 +0000 |
commit | 396145d0da19e49557b541fca2b97d48757fe3dc (patch) | |
tree | 71d2aef2d2a98fd2e4318a44cd9e6842483202c9 /libcxx/test/std/strings/basic.string/string.nonmembers/string.io/stream_extract.pass.cpp | |
parent | bbeca849d7ba8e5506bf0c1204590717deac6d7a (diff) | |
download | bcm5719-llvm-396145d0da19e49557b541fca2b97d48757fe3dc.tar.gz bcm5719-llvm-396145d0da19e49557b541fca2b97d48757fe3dc.zip |
[libc++] Fix error flags and exceptions propagated from input stream operations
Summary:
This is a re-application of r357533 and r357531. They had been reverted
because we thought the commits broke the LLDB data formatters, but it
turns out this was because only r357531 had been included in the CI
run.
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.
This effectively implements the wording in p1264r0. It hasn't been voted
into the Standard yet, however there is wide agreement that the fix is
correct and it's just a matter of time before the fix is standardized.
PR21586
PR15949
rdar://problem/15347558
Reviewers: mclow.lists, EricWF
Subscribers: christof, dexonsmith, cfe-commits
Differential Revision: https://reviews.llvm.org/D49863
llvm-svn: 357775
Diffstat (limited to 'libcxx/test/std/strings/basic.string/string.nonmembers/string.io/stream_extract.pass.cpp')
-rw-r--r-- | libcxx/test/std/strings/basic.string/string.nonmembers/string.io/stream_extract.pass.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string.io/stream_extract.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string.io/stream_extract.pass.cpp index 389701d1d51..92061e2c476 100644 --- a/libcxx/test/std/strings/basic.string/string.nonmembers/string.io/stream_extract.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string.io/stream_extract.pass.cpp @@ -18,6 +18,7 @@ #include <cassert> #include "min_allocator.h" +#include "test_macros.h" int main(int, char**) { @@ -65,6 +66,44 @@ int main(int, char**) in >> s; assert(in.fail()); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + std::stringbuf sb; + std::istream is(&sb); + is.exceptions(std::ios::failbit); + + bool threw = false; + try { + std::string s; + is >> s; + } 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::string s; + is >> s; + } catch (std::ios::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } +#endif // TEST_HAS_NO_EXCEPTIONS #if TEST_STD_VER >= 11 { typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; |