aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/27_io/basic_istream
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2021-06-25 21:33:02 +0100
committerJonathan Wakely <jwakely@redhat.com>2021-06-28 13:34:49 +0100
commite5c422b7d8af6f42f8ab230133210742b7ac5661 (patch)
treef6a15d03dfdf5321b25267df14e1f92b575ec09a /libstdc++-v3/testsuite/27_io/basic_istream
parentb838641bb0d4de5b25128b54012155ab46f452d0 (diff)
downloadgcc-e5c422b7d8af6f42f8ab230133210742b7ac5661.zip
gcc-e5c422b7d8af6f42f8ab230133210742b7ac5661.tar.gz
gcc-e5c422b7d8af6f42f8ab230133210742b7ac5661.tar.bz2
libstdc++: Implement LWG 415 for std::ws
For C++11 std::ws changed to be an unformatted input function, meaning it constructs a sentry and sets badbit on exceptions. libstdc++-v3/ChangeLog: * doc/xml/manual/intro.xml: Document LWG 415 change. * doc/html/manual/bugs.html: Regenerate. * include/bits/istream.tcc (ws): Create sentry and catch exceptions. * testsuite/27_io/basic_istream/ws/char/lwg415.cc: New test. * testsuite/27_io/basic_istream/ws/wchar_t/lwg415.cc: New test.
Diffstat (limited to 'libstdc++-v3/testsuite/27_io/basic_istream')
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/ws/char/lwg415.cc77
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/ws/wchar_t/lwg415.cc77
2 files changed, 154 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/ws/char/lwg415.cc b/libstdc++-v3/testsuite/27_io/basic_istream/ws/char/lwg415.cc
new file mode 100644
index 0000000..fe6980d
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/ws/char/lwg415.cc
@@ -0,0 +1,77 @@
+#include <istream>
+
+// C++11 27.7.2.4 Standard basic_istream manipulators [istream.manip]
+//
+// LWG 415. behavior of std::ws
+// std::ws is an unformatted input function.
+
+#include <istream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+void
+test01()
+{
+ std::istream is(0);
+ VERIFY( is.rdstate() == std::ios_base::badbit );
+
+ is >> std::ws; // sentry should set failbit
+ VERIFY( is.rdstate() & std::ios_base::failbit );
+}
+
+void
+test02()
+{
+ __gnu_test::sync_streambuf buf;
+ std::istream is(&buf);
+
+ __gnu_test::sync_streambuf buf_tie;
+ std::ostream os_tie(&buf_tie);
+
+ // A sentry should be constructed so is.tie()->flush() should be called.
+ // The standard allows the flush to be deferred because the put area of
+ // is_tie is empty, but libstdc++ doesn't defer it.
+ is.tie(&os_tie);
+
+ is >> std::ws;
+
+ VERIFY( is.eof() );
+ VERIFY( !is.fail() );
+ VERIFY( ! buf.sync_called() );
+ VERIFY( buf_tie.sync_called() );
+}
+
+void
+test03()
+{
+ __gnu_test::fail_streambuf buf;
+ std::istream is(&buf);
+
+ char c;
+ is >> c >> std::ws;
+ VERIFY( is.rdstate() == std::ios_base::badbit );
+
+ is.clear();
+ is.exceptions(std::ios_base::badbit);
+
+ try
+ {
+ is >> std::ws;
+ VERIFY( false );
+ }
+ catch (const __gnu_test::underflow_error&)
+ {
+ VERIFY( is.rdstate() == std::ios_base::badbit );
+ }
+ catch (...)
+ {
+ VERIFY( false );
+ }
+}
+
+int main()
+{
+ test01();
+ test02();
+ test03();
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/ws/wchar_t/lwg415.cc b/libstdc++-v3/testsuite/27_io/basic_istream/ws/wchar_t/lwg415.cc
new file mode 100644
index 0000000..fd04009
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/ws/wchar_t/lwg415.cc
@@ -0,0 +1,77 @@
+#include <istream>
+
+// C++11 27.7.2.4 Standard basic_istream manipulators [istream.manip]
+//
+// LWG 415. behavior of std::ws
+// std::ws is an unformatted input function.
+
+#include <istream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+void
+test01()
+{
+ std::wistream is(0);
+ VERIFY( is.rdstate() == std::ios_base::badbit );
+
+ is >> std::ws; // sentry should set failbit
+ VERIFY( is.rdstate() & std::ios_base::failbit );
+}
+
+void
+test02()
+{
+ __gnu_test::sync_wstreambuf buf;
+ std::wistream is(&buf);
+
+ __gnu_test::sync_wstreambuf buf_tie;
+ std::wostream os_tie(&buf_tie);
+
+ // A sentry should be constructed so is.tie()->flush() should be called.
+ // The standard allows the flush to be deferred because the put area of
+ // is_tie is empty, but libstdc++ doesn't defer it.
+ is.tie(&os_tie);
+
+ is >> std::ws;
+
+ VERIFY( is.eof() );
+ VERIFY( !is.fail() );
+ VERIFY( ! buf.sync_called() );
+ VERIFY( buf_tie.sync_called() );
+}
+
+void
+test03()
+{
+ __gnu_test::fail_wstreambuf buf;
+ std::wistream is(&buf);
+
+ wchar_t c;
+ is >> c >> std::ws;
+ VERIFY( is.rdstate() == std::ios_base::badbit );
+
+ is.clear();
+ is.exceptions(std::ios_base::badbit);
+
+ try
+ {
+ is >> std::ws;
+ VERIFY( false );
+ }
+ catch (const __gnu_test::underflow_error&)
+ {
+ VERIFY( is.rdstate() == std::ios_base::badbit );
+ }
+ catch (...)
+ {
+ VERIFY( false );
+ }
+}
+
+int main()
+{
+ test01();
+ test02();
+ test03();
+}