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 | |
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')
40 files changed, 1962 insertions, 159 deletions
diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/bool.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/bool.pass.cpp index 799ec5eaeb5..e9df54f417f 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/bool.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/bool.pass.cpp @@ -15,6 +15,7 @@ #include <istream> #include <cassert> +#include "test_macros.h" template <class CharT> struct testbuf @@ -75,6 +76,44 @@ int main(int, char**) assert(!is.eof()); assert(!is.fail()); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::failbit); + + bool threw = false; + try { + bool n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + bool n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } +#endif // TEST_HAS_NO_EXCEPTIONS - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/double.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/double.pass.cpp index 9f9872d9ef8..615765c7c6e 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/double.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/double.pass.cpp @@ -15,6 +15,7 @@ #include <istream> #include <cassert> +#include "test_macros.h" template <class CharT> struct testbuf @@ -75,6 +76,44 @@ int main(int, char**) assert(!is.eof()); assert(!is.fail()); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::failbit); + + bool threw = false; + try { + double n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + double n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } +#endif // TEST_HAS_NO_EXCEPTIONS - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/float.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/float.pass.cpp index c2b937a89cf..72fd7ed27a7 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/float.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/float.pass.cpp @@ -15,6 +15,7 @@ #include <istream> #include <cassert> +#include "test_macros.h" template <class CharT> struct testbuf @@ -75,6 +76,44 @@ int main(int, char**) assert(!is.eof()); assert(!is.fail()); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::failbit); + + bool threw = false; + try { + float n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + float n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } +#endif // TEST_HAS_NO_EXCEPTIONS - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/int.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/int.pass.cpp index 702287be79e..d099fa82c5f 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/int.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/int.pass.cpp @@ -16,6 +16,7 @@ #include <istream> #include <limits> #include <cassert> +#include "test_macros.h" template <class CharT> struct testbuf @@ -76,6 +77,44 @@ int main(int, char**) assert(!is.eof()); assert( is.fail()); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::failbit); + + bool threw = false; + try { + int n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + int n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } +#endif // TEST_HAS_NO_EXCEPTIONS - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/long.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/long.pass.cpp index 9f9118cbcdc..a517406b5a5 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/long.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/long.pass.cpp @@ -15,6 +15,7 @@ #include <istream> #include <cassert> +#include "test_macros.h" template <class CharT> struct testbuf @@ -75,6 +76,44 @@ int main(int, char**) assert(!is.eof()); assert(!is.fail()); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::failbit); + + bool threw = false; + try { + long n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + long n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } +#endif // TEST_HAS_NO_EXCEPTIONS - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/long_double.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/long_double.pass.cpp index bdd30190a5b..769e9a33847 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/long_double.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/long_double.pass.cpp @@ -15,6 +15,7 @@ #include <istream> #include <cassert> +#include "test_macros.h" template <class CharT> struct testbuf @@ -75,6 +76,44 @@ int main(int, char**) assert(!is.eof()); assert(!is.fail()); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::failbit); + + bool threw = false; + try { + long double n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + long double n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } +#endif // TEST_HAS_NO_EXCEPTIONS - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/long_long.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/long_long.pass.cpp index 1612468f4d7..dff93d169aa 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/long_long.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/long_long.pass.cpp @@ -15,6 +15,7 @@ #include <istream> #include <cassert> +#include "test_macros.h" template <class CharT> struct testbuf @@ -75,6 +76,44 @@ int main(int, char**) assert(!is.eof()); assert(!is.fail()); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::failbit); + + bool threw = false; + try { + long long n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + long long n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } +#endif // TEST_HAS_NO_EXCEPTIONS - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/pointer.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/pointer.pass.cpp index 0893d8cdec2..f88be1b18ab 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/pointer.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/pointer.pass.cpp @@ -19,6 +19,7 @@ #include <istream> #include <cassert> +#include "test_macros.h" template <class CharT> struct testbuf @@ -97,6 +98,44 @@ int main(int, char**) assert( is.eof()); assert(!is.fail()); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::failbit); + + bool threw = false; + try { + void* n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + void* n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } +#endif // TEST_HAS_NO_EXCEPTIONS - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/short.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/short.pass.cpp index a0d96c3983f..56ab5843a49 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/short.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/short.pass.cpp @@ -16,6 +16,7 @@ #include <istream> #include <limits> #include <cassert> +#include "test_macros.h" template <class CharT> struct testbuf @@ -76,6 +77,44 @@ int main(int, char**) assert(!is.eof()); assert( is.fail()); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::failbit); + + bool threw = false; + try { + short n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + short n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } +#endif // TEST_HAS_NO_EXCEPTIONS - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_int.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_int.pass.cpp index 578cfcf0cc4..79d3dcb8d18 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_int.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_int.pass.cpp @@ -15,6 +15,7 @@ #include <istream> #include <cassert> +#include "test_macros.h" template <class CharT> struct testbuf @@ -75,6 +76,44 @@ int main(int, char**) assert(!is.eof()); assert(!is.fail()); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::failbit); + + bool threw = false; + try { + unsigned int n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + unsigned int n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } +#endif // TEST_HAS_NO_EXCEPTIONS - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_long.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_long.pass.cpp index f1c150d7920..10e2fab9b27 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_long.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_long.pass.cpp @@ -15,6 +15,7 @@ #include <istream> #include <cassert> +#include "test_macros.h" template <class CharT> struct testbuf @@ -75,6 +76,44 @@ int main(int, char**) assert(!is.eof()); assert(!is.fail()); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::failbit); + + bool threw = false; + try { + unsigned long n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + unsigned long n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } +#endif // TEST_HAS_NO_EXCEPTIONS - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_long_long.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_long_long.pass.cpp index 068d31ac8fb..9a73e87204a 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_long_long.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_long_long.pass.cpp @@ -15,6 +15,7 @@ #include <istream> #include <cassert> +#include "test_macros.h" template <class CharT> struct testbuf @@ -75,6 +76,44 @@ int main(int, char**) assert(!is.eof()); assert(!is.fail()); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::failbit); + + bool threw = false; + try { + unsigned long long n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + unsigned long long n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } +#endif // TEST_HAS_NO_EXCEPTIONS - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_short.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_short.pass.cpp index 9906bbeac8d..c4d95f5c1e7 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_short.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_short.pass.cpp @@ -15,6 +15,7 @@ #include <istream> #include <cassert> +#include "test_macros.h" template <class CharT> struct testbuf @@ -75,6 +76,44 @@ int main(int, char**) assert(!is.eof()); assert(!is.fail()); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::failbit); + + bool threw = false; + try { + unsigned short n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + unsigned short n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } +#endif // TEST_HAS_NO_EXCEPTIONS - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/chart.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/chart.pass.cpp index cbb606cdcff..15f26fcaaa3 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/chart.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/chart.pass.cpp @@ -13,6 +13,7 @@ #include <istream> #include <cassert> +#include "test_macros.h" template <class CharT> struct testbuf @@ -83,6 +84,80 @@ int main(int, char**) assert(!is.fail()); assert(c == L'c'); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::failbit); + + bool threw = false; + try { + char n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } + { + testbuf<wchar_t> sb; + std::basic_istream<wchar_t> is(&sb); + is.exceptions(std::ios_base::failbit); + + bool threw = false; + try { + wchar_t n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + char n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } + { + testbuf<wchar_t> sb; + std::basic_istream<wchar_t> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + wchar_t n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } +#endif // TEST_HAS_NO_EXCEPTIONS - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/signed_char.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/signed_char.pass.cpp index bd06de6a07b..d5ae9098213 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/signed_char.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/signed_char.pass.cpp @@ -13,6 +13,7 @@ #include <istream> #include <cassert> +#include "test_macros.h" template <class CharT> struct testbuf @@ -66,6 +67,44 @@ int main(int, char**) assert(!is.fail()); assert(c == 'c'); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::failbit); + + bool threw = false; + try { + signed char n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + signed char n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } +#endif // TEST_HAS_NO_EXCEPTIONS - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/signed_char_pointer.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/signed_char_pointer.pass.cpp index d5128339a71..64ff48d2973 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/signed_char_pointer.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/signed_char_pointer.pass.cpp @@ -13,6 +13,7 @@ #include <istream> #include <cassert> +#include "test_macros.h" template <class CharT> struct testbuf @@ -103,6 +104,46 @@ int main(int, char**) assert(std::string((char*)s) == ""); } #endif +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::failbit); + + bool threw = false; + try { + signed char s[20]; + is.width(10); + is >> s; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + signed char s[20]; + is.width(10); + is >> s; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } +#endif - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/streambuf.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/streambuf.pass.cpp index 9feb826906f..bf244e1e8d3 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/streambuf.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/streambuf.pass.cpp @@ -11,11 +11,13 @@ // template <class charT, class traits = char_traits<charT> > // class basic_istream; -// basic_istream<charT,traits>& operator<<(basic_streambuf<charT,traits>* sb); +// basic_istream<charT,traits>& operator>>(basic_streambuf<charT,traits>* sb); #include <istream> #include <cassert> +#include "test_macros.h" + template <class CharT> class testbuf : public std::basic_streambuf<CharT> @@ -65,6 +67,104 @@ int main(int, char**) assert(sb2.str() == "testing..."); assert(is.gcount() == 10); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb(" "); + std::basic_istream<char> is(&sb); + testbuf<char> sb2; + is.exceptions(std::istream::eofbit); + bool threw = false; + try { + is >> &sb2; + } catch (std::ios_base::failure&) { + threw = true; + } + assert(threw); + assert(!is.bad()); + assert( is.eof()); + assert(!is.fail()); + } + { + testbuf<wchar_t> sb(L" "); + std::basic_istream<wchar_t> is(&sb); + testbuf<wchar_t> sb2; + is.exceptions(std::istream::eofbit); + bool threw = false; + try { + is >> &sb2; + } catch (std::ios_base::failure&) { + threw = true; + } + assert(threw); + assert(!is.bad()); + assert( is.eof()); + assert(!is.fail()); + } + + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + testbuf<char> sb2; + is.exceptions(std::istream::failbit); + bool threw = false; + try { + is >> &sb2; + } catch (std::ios_base::failure&) { + threw = true; + } + assert(threw); + assert(!is.bad()); + assert( is.eof()); + assert( is.fail()); + } + { + testbuf<wchar_t> sb; + std::basic_istream<wchar_t> is(&sb); + testbuf<wchar_t> sb2; + is.exceptions(std::istream::failbit); + bool threw = false; + try { + is >> &sb2; + } catch (std::ios_base::failure&) { + threw = true; + } + assert(threw); + assert(!is.bad()); + assert( is.eof()); + assert( is.fail()); + } + + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::istream::failbit); + bool threw = false; + try { + is >> static_cast<testbuf<char>*>(0); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(threw); + assert(!is.bad()); + assert(!is.eof()); + assert( is.fail()); + } + { + testbuf<wchar_t> sb; + std::basic_istream<wchar_t> is(&sb); + is.exceptions(std::istream::failbit); + bool threw = false; + try { + is >> static_cast<testbuf<wchar_t>*>(0); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(threw); + assert(!is.bad()); + assert(!is.eof()); + assert( is.fail()); + } +#endif - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/unsigned_char.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/unsigned_char.pass.cpp index 3eceaaeb63f..8d86d11c1ae 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/unsigned_char.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/unsigned_char.pass.cpp @@ -13,6 +13,7 @@ #include <istream> #include <cassert> +#include "test_macros.h" template <class CharT> struct testbuf @@ -66,6 +67,44 @@ int main(int, char**) assert(!is.fail()); assert(c == 'c'); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::failbit); + + bool threw = false; + try { + unsigned char n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + unsigned char n = 0; + is >> n; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } +#endif // TEST_HAS_NO_EXCEPTIONS - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/unsigned_char_pointer.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/unsigned_char_pointer.pass.cpp index 14b2993148d..7e4bf41c966 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/unsigned_char_pointer.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/unsigned_char_pointer.pass.cpp @@ -13,6 +13,7 @@ #include <istream> #include <cassert> +#include "test_macros.h" template <class CharT> struct testbuf @@ -103,6 +104,46 @@ int main(int, char**) assert(std::string((char*)s) == ""); } #endif +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::failbit); + + bool threw = false; + try { + unsigned char s[20]; + is.width(10); + is >> s; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + unsigned char s[20]; + is.width(10); + is >> s; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } +#endif // TEST_HAS_NO_EXCEPTIONS - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/wchar_t_pointer.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/wchar_t_pointer.pass.cpp index f0a9e0710fb..117a0ba83e3 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/wchar_t_pointer.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/wchar_t_pointer.pass.cpp @@ -13,6 +13,7 @@ #include <istream> #include <cassert> +#include "test_macros.h" template <class CharT> struct testbuf @@ -114,6 +115,84 @@ int main(int, char**) assert(std::string(s) == ""); } #endif +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::failbit); + + bool threw = false; + try { + char s[20]; + is.width(10); + is >> s; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } + { + testbuf<wchar_t> sb; + std::wistream is(&sb); + is.exceptions(std::ios_base::failbit); + + bool threw = false; + try { + wchar_t s[20]; + is.width(10); + is >> s; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + char s[20]; + is.width(10); + is >> s; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } + { + testbuf<wchar_t> sb; + std::wistream is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + wchar_t s[20]; + is.width(10); + is >> s; + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(is.fail()); + assert(is.eof()); + assert(threw); + } +#endif // TEST_HAS_NO_EXCEPTIONS - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.manip/ws.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.manip/ws.pass.cpp index 6786ebf4ca0..0eaf58b69b3 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.manip/ws.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.manip/ws.pass.cpp @@ -14,6 +14,7 @@ #include <istream> #include <cassert> +#include "test_macros.h" template <class CharT> struct testbuf @@ -75,6 +76,42 @@ int main(int, char**) assert(is.eof()); assert(is.fail()); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb(" "); + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + std::ws(is); + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(!is.fail()); + assert( is.eof()); + assert(threw); + } + { + testbuf<wchar_t> sb(L" "); + std::basic_istream<wchar_t> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + std::ws(is); + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(!is.fail()); + assert( is.eof()); + assert(threw); + } +#endif - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get.pass.cpp index 40a04174133..788e215c8ee 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get.pass.cpp @@ -12,6 +12,7 @@ #include <istream> #include <cassert> +#include "test_macros.h" template <class CharT> struct testbuf @@ -96,6 +97,50 @@ int main(int, char**) assert(c == L'c'); assert(is.gcount() == 1); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb("rrrrrrrrr"); + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + while (true) { + is.get(); + if (is.eof()) + break; + } + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert( is.fail()); + assert( is.eof()); + assert(threw); + } + { + testbuf<wchar_t> sb(L"rrrrrrrrr"); + std::basic_istream<wchar_t> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + while (true) { + is.get(); + if (is.eof()) + break; + } + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert( is.fail()); + assert( is.eof()); + assert(threw); + } +#endif - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_chart.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_chart.pass.cpp index ae31c9be06d..7b5e56dec43 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_chart.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_chart.pass.cpp @@ -12,6 +12,7 @@ #include <istream> #include <cassert> +#include "test_macros.h" template <class CharT> struct testbuf @@ -99,6 +100,52 @@ int main(int, char**) assert(c == L'c'); assert(is.gcount() == 1); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb("rrrrrrrrr"); + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + while (true) { + char c; + is.get(c); + if (is.eof()) + break; + } + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert( is.fail()); + assert( is.eof()); + assert(threw); + } + { + testbuf<wchar_t> sb(L"rrrrrrrrr"); + std::basic_istream<wchar_t> is(&sb); + is.exceptions(std::ios_base::eofbit); + + bool threw = false; + try { + while (true) { + wchar_t c; + is.get(c); + if (is.eof()) + break; + } + } catch (std::ios_base::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert( is.fail()); + assert( is.eof()); + assert(threw); + } +#endif - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_pointer_size.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_pointer_size.pass.cpp index 149392cae3f..2a88b726139 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_pointer_size.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_pointer_size.pass.cpp @@ -84,26 +84,6 @@ int main(int, char**) assert(std::string(s) == ""); assert(is.gcount() == 0); } -#ifndef TEST_HAS_NO_EXCEPTIONS - { - testbuf<char> sb(" "); - std::istream is(&sb); - char s[5] = "test"; - is.exceptions(std::istream::eofbit | std::istream::badbit); - try - { - is.get(s, 5); - assert(false); - } - catch (std::ios_base::failure&) - { - } - assert( is.eof()); - assert( is.fail()); - assert(std::string(s) == " "); - assert(is.gcount() == 1); - } -#endif { testbuf<wchar_t> sb(L" \n \n "); std::wistream is(&sb); @@ -140,23 +120,78 @@ int main(int, char**) } #ifndef TEST_HAS_NO_EXCEPTIONS { + testbuf<char> sb(" "); + std::basic_istream<char> is(&sb); + char s[5] = "test"; + is.exceptions(std::ios_base::eofbit); + bool threw = false; + try { + is.get(s, 5); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(!is.bad()); + assert( is.eof()); + assert(!is.fail()); + assert(threw); + assert(std::string(s) == " "); + assert(is.gcount() == 1); + } + { testbuf<wchar_t> sb(L" "); - std::wistream is(&sb); + std::basic_istream<wchar_t> is(&sb); wchar_t s[5] = L"test"; - is.exceptions(std::wistream::eofbit | std::wistream::badbit); - try - { + is.exceptions(std::ios_base::eofbit); + bool threw = false; + try { is.get(s, 5); - assert(false); - } - catch (std::ios_base::failure&) - { + } catch (std::ios_base::failure&) { + threw = true; } + assert(!is.bad()); assert( is.eof()); - assert( is.fail()); + assert(!is.fail()); + assert(threw); assert(std::wstring(s) == L" "); assert(is.gcount() == 1); } + + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + char s[5] = "test"; + is.exceptions(std::ios_base::failbit); + bool threw = false; + try { + is.get(s, 5); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(!is.bad()); + assert( is.eof()); + assert( is.fail()); + assert(threw); + assert(std::basic_string<char>(s) == ""); + assert(is.gcount() == 0); + } + { + testbuf<wchar_t> sb; + std::basic_istream<wchar_t> is(&sb); + wchar_t s[5] = L"test"; + is.exceptions(std::ios_base::failbit); + bool threw = false; + try { + is.get(s, 5); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(!is.bad()); + assert( is.eof()); + assert( is.fail()); + assert(threw); + assert(std::basic_string<wchar_t>(s) == L""); + assert(is.gcount() == 0); + } #endif return 0; diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_pointer_size_chart.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_pointer_size_chart.pass.cpp index e7c96d6a266..df8ccc8127a 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_pointer_size_chart.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_pointer_size_chart.pass.cpp @@ -84,26 +84,6 @@ int main(int, char**) assert(std::string(s) == ""); assert(is.gcount() == 0); } -#ifndef TEST_HAS_NO_EXCEPTIONS - { - testbuf<char> sb(" "); - std::istream is(&sb); - char s[5] = "test"; - is.exceptions(std::istream::eofbit | std::istream::badbit); - try - { - is.get(s, 5, '*'); - assert(false); - } - catch (std::ios_base::failure&) - { - } - assert( is.eof()); - assert( is.fail()); - assert(std::string(s) == " "); - assert(is.gcount() == 1); - } -#endif { testbuf<wchar_t> sb(L" * * "); std::wistream is(&sb); @@ -140,22 +120,77 @@ int main(int, char**) } #ifndef TEST_HAS_NO_EXCEPTIONS { + testbuf<char> sb(" "); + std::basic_istream<char> is(&sb); + char s[5] = "test"; + is.exceptions(std::ios_base::eofbit); + bool threw = false; + try { + is.get(s, 5, '*'); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(!is.bad()); + assert( is.eof()); + assert(!is.fail()); + assert(threw); + assert(std::basic_string<char>(s) == " "); + assert(is.gcount() == 1); + } + { testbuf<wchar_t> sb(L" "); - std::wistream is(&sb); + std::basic_istream<wchar_t> is(&sb); wchar_t s[5] = L"test"; - is.exceptions(std::wistream::eofbit | std::wistream::badbit); - try - { + is.exceptions(std::ios_base::eofbit); + bool threw = false; + try { is.get(s, 5, L'*'); - assert(false); + } catch (std::ios_base::failure&) { + threw = true; } - catch (std::ios_base::failure&) - { + assert(!is.bad()); + assert( is.eof()); + assert(!is.fail()); + assert(threw); + assert(std::basic_string<wchar_t>(s) == L" "); + assert(is.gcount() == 1); + } + + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + char s[5] = "test"; + is.exceptions(std::ios_base::failbit); + bool threw = false; + try { + is.get(s, 5, '*'); + } catch (std::ios_base::failure&) { + threw = true; } + assert(!is.bad()); assert( is.eof()); assert( is.fail()); - assert(std::wstring(s) == L" "); - assert(is.gcount() == 1); + assert(threw); + assert(std::basic_string<char>(s) == ""); + assert(is.gcount() == 0); + } + { + testbuf<wchar_t> sb; + std::basic_istream<wchar_t> is(&sb); + wchar_t s[5] = L"test"; + is.exceptions(std::ios_base::failbit); + bool threw = false; + try { + is.get(s, 5, L'*'); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(!is.bad()); + assert( is.eof()); + assert( is.fail()); + assert(threw); + assert(std::basic_string<wchar_t>(s) == L""); + assert(is.gcount() == 0); } #endif diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_streambuf.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_streambuf.pass.cpp index dda59d7ff50..f34873c04e0 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_streambuf.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_streambuf.pass.cpp @@ -13,6 +13,8 @@ #include <istream> #include <cassert> +#include "test_macros.h" + template <class CharT> class testbuf : public std::basic_streambuf<CharT> @@ -84,6 +86,73 @@ int main(int, char**) assert(!is.fail()); assert(is.gcount() == 3); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb(" "); + std::basic_istream<char> is(&sb); + testbuf<char> sb2; + is.exceptions(std::ios_base::eofbit); + bool threw = false; + try { + is.get(sb2); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(threw); + assert(!is.bad()); + assert( is.eof()); + assert(!is.fail()); + } + { + testbuf<wchar_t> sb(L" "); + std::basic_istream<wchar_t> is(&sb); + testbuf<wchar_t> sb2; + is.exceptions(std::ios_base::eofbit); + bool threw = false; + try { + is.get(sb2); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(threw); + assert(!is.bad()); + assert( is.eof()); + assert(!is.fail()); + } + + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + testbuf<char> sb2; + is.exceptions(std::ios_base::eofbit); + bool threw = false; + try { + is.get(sb2); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(threw); + assert(!is.bad()); + assert( is.eof()); + assert( is.fail()); + } + { + testbuf<wchar_t> sb; + std::basic_istream<wchar_t> is(&sb); + testbuf<wchar_t> sb2; + is.exceptions(std::ios_base::eofbit); + bool threw = false; + try { + is.get(sb2); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(threw); + assert(!is.bad()); + assert( is.eof()); + assert( is.fail()); + } +#endif - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_streambuf_chart.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_streambuf_chart.pass.cpp index a1e46c2336c..adef49b8f43 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_streambuf_chart.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_streambuf_chart.pass.cpp @@ -13,6 +13,7 @@ #include <istream> #include <cassert> +#include "test_macros.h" template <class CharT> class testbuf @@ -85,6 +86,73 @@ int main(int, char**) assert(!is.fail()); assert(is.gcount() == 3); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb(" "); + std::basic_istream<char> is(&sb); + testbuf<char> sb2; + is.exceptions(std::ios_base::eofbit); + bool threw = false; + try { + is.get(sb2, '*'); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(threw); + assert(!is.bad()); + assert( is.eof()); + assert(!is.fail()); + } + { + testbuf<wchar_t> sb(L" "); + std::basic_istream<wchar_t> is(&sb); + testbuf<wchar_t> sb2; + is.exceptions(std::ios_base::eofbit); + bool threw = false; + try { + is.get(sb2, L'*'); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(threw); + assert(!is.bad()); + assert( is.eof()); + assert(!is.fail()); + } + + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + testbuf<char> sb2; + is.exceptions(std::ios_base::eofbit); + bool threw = false; + try { + is.get(sb2, '*'); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(threw); + assert(!is.bad()); + assert( is.eof()); + assert( is.fail()); + } + { + testbuf<wchar_t> sb; + std::basic_istream<wchar_t> is(&sb); + testbuf<wchar_t> sb2; + is.exceptions(std::ios_base::eofbit); + bool threw = false; + try { + is.get(sb2, L'*'); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(threw); + assert(!is.bad()); + assert( is.eof()); + assert( is.fail()); + } +#endif - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size.pass.cpp index 9c91053ebdb..de54bf429a8 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size.pass.cpp @@ -76,26 +76,6 @@ int main(int, char**) assert(std::string(s) == ""); assert(is.gcount() == 0); } -#ifndef TEST_HAS_NO_EXCEPTIONS - { - testbuf<char> sb(" "); - std::istream is(&sb); - char s[5] = "test"; - is.exceptions(std::istream::eofbit | std::istream::badbit); - try - { - is.getline(s, 5); - assert(false); - } - catch (std::ios_base::failure&) - { - } - assert( is.eof()); - assert( is.fail()); - assert(std::string(s) == " "); - assert(is.gcount() == 1); - } -#endif { testbuf<wchar_t> sb(L" \n \n "); std::wistream is(&sb); @@ -124,22 +104,77 @@ int main(int, char**) } #ifndef TEST_HAS_NO_EXCEPTIONS { + testbuf<char> sb(" "); + std::basic_istream<char> is(&sb); + char s[5] = "test"; + is.exceptions(std::ios_base::eofbit); + bool threw = false; + try { + is.getline(s, 5); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(!is.bad()); + assert( is.eof()); + assert(!is.fail()); + assert(threw); + assert(std::basic_string<char>(s) == " "); + assert(is.gcount() == 1); + } + { testbuf<wchar_t> sb(L" "); - std::wistream is(&sb); + std::basic_istream<wchar_t> is(&sb); wchar_t s[5] = L"test"; - is.exceptions(std::wistream::eofbit | std::wistream::badbit); - try - { + is.exceptions(std::ios_base::eofbit); + bool threw = false; + try { is.getline(s, 5); - assert(false); + } catch (std::ios_base::failure&) { + threw = true; } - catch (std::ios_base::failure&) - { + assert(!is.bad()); + assert( is.eof()); + assert(!is.fail()); + assert(threw); + assert(std::basic_string<wchar_t>(s) == L" "); + assert(is.gcount() == 1); + } + + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + char s[5] = "test"; + is.exceptions(std::ios_base::eofbit); + bool threw = false; + try { + is.getline(s, 5); + } catch (std::ios_base::failure&) { + threw = true; } + assert(!is.bad()); assert( is.eof()); assert( is.fail()); - assert(std::wstring(s) == L" "); - assert(is.gcount() == 1); + assert(threw); + assert(std::basic_string<char>(s) == ""); + assert(is.gcount() == 0); + } + { + testbuf<wchar_t> sb; + std::basic_istream<wchar_t> is(&sb); + wchar_t s[5] = L"test"; + is.exceptions(std::ios_base::eofbit); + bool threw = false; + try { + is.getline(s, 5); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(!is.bad()); + assert( is.eof()); + assert( is.fail()); + assert(threw); + assert(std::basic_string<wchar_t>(s) == L""); + assert(is.gcount() == 0); } #endif diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size_chart.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size_chart.pass.cpp index bee1976e95e..de191672591 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size_chart.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/getline_pointer_size_chart.pass.cpp @@ -76,26 +76,6 @@ int main(int, char**) assert(std::string(s) == ""); assert(is.gcount() == 0); } -#ifndef TEST_HAS_NO_EXCEPTIONS - { - testbuf<char> sb(" "); - std::istream is(&sb); - char s[5] = "test"; - is.exceptions(std::istream::eofbit | std::istream::badbit); - try - { - is.getline(s, 5, '*'); - assert(false); - } - catch (std::ios_base::failure&) - { - } - assert( is.eof()); - assert( is.fail()); - assert(std::string(s) == " "); - assert(is.gcount() == 1); - } -#endif { testbuf<wchar_t> sb(L" * * "); std::wistream is(&sb); @@ -124,22 +104,77 @@ int main(int, char**) } #ifndef TEST_HAS_NO_EXCEPTIONS { + testbuf<char> sb(" "); + std::basic_istream<char> is(&sb); + char s[5] = "test"; + is.exceptions(std::ios_base::eofbit); + bool threw = false; + try { + is.getline(s, 5, '*'); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(!is.bad()); + assert( is.eof()); + assert(!is.fail()); + assert(threw); + assert(std::basic_string<char>(s) == " "); + assert(is.gcount() == 1); + } + { testbuf<wchar_t> sb(L" "); - std::wistream is(&sb); + std::basic_istream<wchar_t> is(&sb); wchar_t s[5] = L"test"; - is.exceptions(std::wistream::eofbit | std::wistream::badbit); - try - { + is.exceptions(std::ios_base::eofbit); + bool threw = false; + try { is.getline(s, 5, L'*'); - assert(false); + } catch (std::ios_base::failure&) { + threw = true; } - catch (std::ios_base::failure&) - { + assert(!is.bad()); + assert( is.eof()); + assert(!is.fail()); + assert(threw); + assert(std::basic_string<wchar_t>(s) == L" "); + assert(is.gcount() == 1); + } + + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + char s[5] = "test"; + is.exceptions(std::ios_base::eofbit); + bool threw = false; + try { + is.getline(s, 5, '*'); + } catch (std::ios_base::failure&) { + threw = true; } + assert(!is.bad()); assert( is.eof()); assert( is.fail()); - assert(std::wstring(s) == L" "); - assert(is.gcount() == 1); + assert(threw); + assert(std::basic_string<char>(s) == ""); + assert(is.gcount() == 0); + } + { + testbuf<wchar_t> sb; + std::basic_istream<wchar_t> is(&sb); + wchar_t s[5] = L"test"; + is.exceptions(std::ios_base::eofbit); + bool threw = false; + try { + is.getline(s, 5, L'*'); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(!is.bad()); + assert( is.eof()); + assert( is.fail()); + assert(threw); + assert(std::basic_string<wchar_t>(s) == L""); + assert(is.gcount() == 0); } #endif diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore.pass.cpp index 7f6348b01a4..62831626371 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore.pass.cpp @@ -14,6 +14,8 @@ #include <istream> #include <cassert> +#include "test_macros.h" + template <class CharT> struct testbuf : public std::basic_streambuf<CharT> @@ -72,6 +74,38 @@ int main(int, char**) assert(!is.fail()); assert(is.gcount() == 6); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb(" "); + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + bool threw = false; + try { + is.ignore(5); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(threw); + assert(!is.bad()); + assert( is.eof()); + assert(!is.fail()); + } + { + testbuf<wchar_t> sb(L" "); + std::basic_istream<wchar_t> is(&sb); + is.exceptions(std::ios_base::eofbit); + bool threw = false; + try { + is.ignore(5); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(threw); + assert(!is.bad()); + assert( is.eof()); + assert(!is.fail()); + } +#endif - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/peek.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/peek.pass.cpp index 17943463e90..2d099322ad8 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/peek.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/peek.pass.cpp @@ -12,6 +12,7 @@ #include <istream> #include <cassert> +#include "test_macros.h" template <class CharT> struct testbuf @@ -65,6 +66,38 @@ int main(int, char**) assert(!is.fail()); assert(is.gcount() == 0); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + bool threw = false; + try { + is.peek(); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(threw); + assert(!is.bad()); + assert( is.eof()); + assert(!is.fail()); + } + { + testbuf<wchar_t> sb; + std::basic_istream<wchar_t> is(&sb); + is.exceptions(std::ios_base::eofbit); + bool threw = false; + try { + is.peek(); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(threw); + assert(!is.bad()); + assert( is.eof()); + assert(!is.fail()); + } +#endif - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/putback.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/putback.pass.cpp index 4ca3a8c0edb..588c0a6def5 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/putback.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/putback.pass.cpp @@ -13,6 +13,8 @@ #include <istream> #include <cassert> +#include "test_macros.h" + template <class CharT> struct testbuf : public std::basic_streambuf<CharT> @@ -85,6 +87,38 @@ int main(int, char**) assert(is.bad()); assert(is.gcount() == 0); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::badbit); + bool threw = false; + try { + is.putback('x'); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(threw); + assert( is.bad()); + assert(!is.eof()); + assert( is.fail()); + } + { + testbuf<wchar_t> sb; + std::basic_istream<wchar_t> is(&sb); + is.exceptions(std::ios_base::badbit); + bool threw = false; + try { + is.putback(L'x'); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(threw); + assert( is.bad()); + assert(!is.eof()); + assert( is.fail()); + } +#endif - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/read.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/read.pass.cpp index 9296e0bfb2e..0ae8bcfe161 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/read.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/read.pass.cpp @@ -12,6 +12,7 @@ #include <istream> #include <cassert> +#include "test_macros.h" template <class CharT> struct testbuf @@ -77,6 +78,40 @@ int main(int, char**) assert( is.fail()); assert(is.gcount() == 0); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + char s[10]; + bool threw = false; + try { + is.read(s, 5); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(threw); + assert(!is.bad()); + assert( is.eof()); + assert( is.fail()); + } + { + testbuf<wchar_t> sb; + std::basic_istream<wchar_t> is(&sb); + is.exceptions(std::ios_base::eofbit); + wchar_t s[10]; + bool threw = false; + try { + is.read(s, 5); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(threw); + assert(!is.bad()); + assert( is.eof()); + assert( is.fail()); + } +#endif - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/sync.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/sync.pass.cpp index 43ddd811080..ff22e9876f5 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/sync.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/sync.pass.cpp @@ -13,6 +13,8 @@ #include <istream> #include <cassert> +#include "test_macros.h" + int sync_called = 0; template <class CharT> @@ -46,6 +48,41 @@ protected: } }; +#ifndef TEST_HAS_NO_EXCEPTIONS +struct testbuf_exception { }; + +template <class CharT> +struct throwing_testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + throwing_testbuf() {} + throwing_testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } + + CharT* eback() const {return base::eback();} + CharT* gptr() const {return base::gptr();} + CharT* egptr() const {return base::egptr();} + +protected: + virtual int sync() + { + throw testbuf_exception(); + return 5; + } +}; +#endif // TEST_HAS_NO_EXCEPTIONS + int main(int, char**) { { @@ -60,6 +97,36 @@ int main(int, char**) assert(is.sync() == 0); assert(sync_called == 2); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + throwing_testbuf<char> sb(" 123456789"); + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::badbit); + bool threw = false; + try { + is.sync(); + } catch (testbuf_exception const&) { + threw = true; + } + assert( is.bad()); + assert(!is.eof()); + assert( is.fail()); + } + { + throwing_testbuf<wchar_t> sb(L" 123456789"); + std::basic_istream<wchar_t> is(&sb); + is.exceptions(std::ios_base::badbit); + bool threw = false; + try { + is.sync(); + } catch (testbuf_exception const&) { + threw = true; + } + assert( is.bad()); + assert(!is.eof()); + assert( is.fail()); + } +#endif - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/unget.pass.cpp b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/unget.pass.cpp index ca00af4e3c3..b48ff86fbaa 100644 --- a/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/unget.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/unget.pass.cpp @@ -13,6 +13,8 @@ #include <istream> #include <cassert> +#include "test_macros.h" + template <class CharT> struct testbuf : public std::basic_streambuf<CharT> @@ -77,6 +79,38 @@ int main(int, char**) assert(is.bad()); assert(is.gcount() == 0); } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + testbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::badbit); + bool threw = false; + try { + is.unget(); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(threw); + assert( is.bad()); + assert(!is.eof()); + assert( is.fail()); + } + { + testbuf<wchar_t> sb; + std::basic_istream<wchar_t> is(&sb); + is.exceptions(std::ios_base::badbit); + bool threw = false; + try { + is.unget(); + } catch (std::ios_base::failure&) { + threw = true; + } + assert(threw); + assert( is.bad()); + assert(!is.eof()); + assert( is.fail()); + } +#endif - return 0; + return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string.io/get_line.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string.io/get_line.pass.cpp index 8e663cb4f60..6069f8e377e 100644 --- a/libcxx/test/std/strings/basic.string/string.nonmembers/string.io/get_line.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string.io/get_line.pass.cpp @@ -18,6 +18,7 @@ #include <cassert> #include "min_allocator.h" +#include "test_macros.h" int main(int, char**) { @@ -77,6 +78,85 @@ int main(int, char**) assert(s == L" ghij"); } #endif +#ifndef TEST_HAS_NO_EXCEPTIONS + { + std::basic_stringbuf<char> sb("hello"); + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::eofbit); + + std::basic_string<char> s; + bool threw = false; + try { + std::getline(is, s); + } catch (std::ios::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(!is.fail()); + assert( is.eof()); + assert(threw); + assert(s == "hello"); + } + { + std::basic_stringbuf<wchar_t> sb(L"hello"); + std::basic_istream<wchar_t> is(&sb); + is.exceptions(std::ios_base::eofbit); + + std::basic_string<wchar_t> s; + bool threw = false; + try { + std::getline(is, s); + } catch (std::ios::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(!is.fail()); + assert( is.eof()); + assert(threw); + assert(s == L"hello"); + } + + { + std::basic_stringbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios_base::failbit); + + std::basic_string<char> s; + bool threw = false; + try { + std::getline(is, s); + } catch (std::ios::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert( is.fail()); + assert( is.eof()); + assert(threw); + assert(s == ""); + } + { + std::basic_stringbuf<wchar_t> sb; + std::basic_istream<wchar_t> is(&sb); + is.exceptions(std::ios_base::failbit); + + std::basic_string<wchar_t> s; + bool threw = false; + try { + std::getline(is, s); + } catch (std::ios::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert( is.fail()); + assert( is.eof()); + assert(threw); + assert(s == L""); + } +#endif // TEST_HAS_NO_EXCEPTIONS - return 0; + return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.nonmembers/string.io/get_line_delim.pass.cpp b/libcxx/test/std/strings/basic.string/string.nonmembers/string.io/get_line_delim.pass.cpp index b081b55c920..d7d271bf02c 100644 --- a/libcxx/test/std/strings/basic.string/string.nonmembers/string.io/get_line_delim.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.nonmembers/string.io/get_line_delim.pass.cpp @@ -18,6 +18,7 @@ #include <cassert> #include "min_allocator.h" +#include "test_macros.h" int main(int, char**) { @@ -89,6 +90,84 @@ int main(int, char**) assert(s == L" ghij"); } #endif +#ifndef TEST_HAS_NO_EXCEPTIONS + { + std::basic_stringbuf<char> sb("hello"); + std::basic_istream<char> is(&sb); + is.exceptions(std::ios::eofbit); + + std::basic_string<char> s; + bool threw = false; + try { + std::getline(is, s, '\n'); + } catch (std::ios::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(!is.fail()); + assert( is.eof()); + assert(threw); + assert(s == "hello"); + } + { + std::basic_stringbuf<wchar_t> sb(L"hello"); + std::basic_istream<wchar_t> is(&sb); + is.exceptions(std::ios::eofbit); + + std::basic_string<wchar_t> s; + bool threw = false; + try { + std::getline(is, s, L'\n'); + } catch (std::ios::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert(!is.fail()); + assert( is.eof()); + assert(threw); + assert(s == L"hello"); + } + { + std::basic_stringbuf<char> sb; + std::basic_istream<char> is(&sb); + is.exceptions(std::ios::failbit); + + std::basic_string<char> s; + bool threw = false; + try { + std::getline(is, s, '\n'); + } catch (std::ios::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert( is.fail()); + assert( is.eof()); + assert(threw); + assert(s == ""); + } + { + std::basic_stringbuf<wchar_t> sb; + std::basic_istream<wchar_t> is(&sb); + is.exceptions(std::ios::failbit); + + std::basic_string<wchar_t> s; + bool threw = false; + try { + std::getline(is, s, L'\n'); + } catch (std::ios::failure const&) { + threw = true; + } + + assert(!is.bad()); + assert( is.fail()); + assert( is.eof()); + assert(threw); + assert(s == L""); + } +#endif // TEST_HAS_NO_EXCEPTIONS - return 0; + return 0; } 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; 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> |