summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite
diff options
context:
space:
mode:
authorbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>2003-11-27 08:14:25 +0000
committerbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>2003-11-27 08:14:25 +0000
commit92fe9461fd7f8b4302153af00ec14585f7c06903 (patch)
tree27f6d0d3d427d9db5da892e2b7f7f741d945f41a /libstdc++-v3/testsuite
parent23d75d32f1390ef02a2c8288ab5f048a5c233020 (diff)
downloadgcc-92fe9461fd7f8b4302153af00ec14585f7c06903.tar.gz
2003-11-26 Benjamin Kosnik <bkoz@redhat.com>
PR libstdc++/9371 PR libstdc++/9546 PR libstdc++/10093 PR libstdc++/10095 * include/bits/basic_ios.h (basic_ios::setstate): Elide if goodbit. (basic_ios::_M_setstate): Consolidate common error handling code. * include/bits/basic_ios.tcc: Tweak. * include/bits/fstream.tcc: Tweak. * include/bits/istream.tcc: Use _M_setstate for common exception handling. Move setstate calls after catch. (basic_istream::tellg): Check for exceptions thrown by streambuf virtual functions. (basic_istream::seekg): Same. * include/bits/ostream.tcc: Same, but for ostream. (basic_ostream::flush): Check for exceptions thrown by streambuf virtual functions. (basic_istream::tellp): Same. (basic_istream::seekp): Same. * include/bits/locale_facets.tcc: Tweak. * include/bits/streambuf.tcc: Tweak. (__copy_streambufs): Propagate exceptions. * testsuite/testsuite_io.h (fail_streambuf): New. (fail_num_get): New. (fail_num_put): New. (facet_error): New. (underflow_error): New. (overflow_error): New. (positioning_error): New. * testsuite/27_io/basic_istream/exceptions/char/9561.cc: Tweak. * testsuite/27_io/basic_istream/extractors_arithmetic/char/ exceptions_badbit_throw.cc, exceptions_failbit.cc, exceptions_failbit_throw.cc: New. * testsuite/27_io/basic_istream/extractors_other/char/ error_failbit.cc, exceptions_badbit_throw.cc, exceptions_failbit_throw.cc, exceptions_null.cc: New. * testsuite/27_io/basic_istream/seekg/char/exceptions_badbit_throw.cc: New. * testsuite/27_io/basic_istream/tellg/char/exceptions_badbit_throw.cc: New. * testsuite/27_io/basic_ostream/flush/char/exceptions_badbit_throw.cc: New. * testsuite/27_io/basic_ostream/inserters_arithmetic/char/ exceptions_badbit_throw.cc, exceptions_failbit_throw.cc: New. * testsuite/27_io/basic_ostream/inserters_other/char/ error_failbit.cc, exceptions_badbit_throw.cc, exceptions_failbit_throw.cc, exceptions_null.cc: New. * testsuite/27_io/basic_ostream/seekp/char/exceptions_badbit_throw.cc: New. * testsuite/27_io/basic_ostream/tellp/char/exceptions_badbit_throw.cc: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@73979 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/testsuite')
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/exceptions/char/9561.cc44
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_badbit_throw.cc76
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit.cc75
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit_throw.cc78
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/error_failbit.cc67
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_badbit_throw.cc79
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_failbit_throw.cc89
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_null.cc68
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/exceptions_badbit_throw.cc96
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/exceptions_badbit_throw.cc66
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/exceptions_badbit_throw.cc66
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_badbit_throw.cc74
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_failbit_throw.cc76
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_failbit.cc67
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_badbit_throw.cc79
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_failbit_throw.cc89
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_null.cc68
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/exceptions_badbit_throw.cc96
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/exceptions_badbit_throw.cc66
-rw-r--r--libstdc++-v3/testsuite/testsuite_io.h161
20 files changed, 1552 insertions, 28 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/exceptions/char/9561.cc b/libstdc++-v3/testsuite/27_io/basic_istream/exceptions/char/9561.cc
index 315b651c93c..ace6cdd56ed 100644
--- a/libstdc++-v3/testsuite/27_io/basic_istream/exceptions/char/9561.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/exceptions/char/9561.cc
@@ -21,44 +21,36 @@
#include <istream>
#include <streambuf>
#include <testsuite_hooks.h>
+#include <testsuite_io.h>
// libstdc++/9561
-struct foobar: std::exception { };
-
-struct buf: std::streambuf
-{
- virtual int_type underflow () {
- throw foobar ();
- return -1;
- }
- virtual int_type uflow () {
- throw foobar ();
- return -1;
- }
-};
-
void test01()
{
using namespace std;
bool test __attribute__((unused)) = true;
- buf b;
+ __gnu_test::fail_streambuf b;
std::istream strm (&b);
strm.exceptions (std::ios::badbit);
int i = 0;
- try {
- i = strm.get();
- }
- catch (foobar) {
- // strm should throw foobar and not do anything else
- VERIFY(strm.bad());
- }
- catch (...) {
- VERIFY(false);
- }
+ try
+ {
+ i = strm.get();
+ i = strm.get();
+ i = strm.get();
+ }
+ catch (__gnu_test::underflow_error&)
+ {
+ // strm should throw facet_error and not do anything else
+ VERIFY(strm.bad());
+ }
+ catch (...)
+ {
+ VERIFY(false);
+ }
- VERIFY(i == 0);
+ VERIFY(i == 's');
}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_badbit_throw.cc
new file mode 100644
index 00000000000..f7c43e2b630
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_badbit_throw.cc
@@ -0,0 +1,76 @@
+// 2003-03-08 Jerry Quinn <jlquinn@optonline.net>
+
+// Copyright (C) 2003 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+#include <locale>
+#include <sstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+// libstdc++/9561
+template<typename T>
+void test_badbit()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ locale loc(locale::classic(), new __gnu_test::fail_num_get);
+ istringstream stream("jaylib - champion sound");
+ stream.imbue(loc);
+
+ stream.exceptions(ios_base::badbit);
+ VERIFY( stream.rdstate() == ios_base::goodbit );
+
+ try
+ {
+ T i;
+ stream >> i;
+ VERIFY( false );
+ }
+ catch (const __gnu_test::facet_error&)
+ {
+ // stream should set badbit and rethrow facet_error.
+ VERIFY( stream.bad() );
+ VERIFY( (stream.rdstate() & ios_base::failbit) == 0 );
+ VERIFY( !stream.eof() );
+ }
+ catch (...)
+ {
+ VERIFY(false);
+ }
+}
+
+
+int main()
+{
+ test_badbit<bool>();
+ test_badbit<short>();
+ test_badbit<unsigned short>();
+ test_badbit<int>();
+ test_badbit<unsigned int>();
+ test_badbit<long>();
+ test_badbit<unsigned long>();
+
+ test_badbit<float>();
+ test_badbit<double>();
+
+ test_badbit<void*>();
+
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit.cc
new file mode 100644
index 00000000000..e2ffe3623d4
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit.cc
@@ -0,0 +1,75 @@
+// Copyright (C) 2003
+// Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/10093
+template<typename T>
+void test_failbit()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ istringstream stream("jaylib - champion sound");
+ stream.exceptions(ios_base::failbit);
+
+ try
+ {
+ T i;
+ stream >> i;
+ VERIFY( false );
+ }
+ catch (const ios_base::failure&)
+ {
+ // stream should set failbit and throw ios_base::failure.
+ VERIFY( stream.fail() );
+ VERIFY( !stream.bad() );
+ VERIFY( !stream.eof() );
+ }
+ catch(...)
+ { VERIFY( false ); }
+}
+
+int main()
+{
+ test_failbit<bool>();
+ test_failbit<short>();
+ test_failbit<unsigned short>();
+ test_failbit<int>();
+ test_failbit<unsigned int>();
+ test_failbit<long>();
+ test_failbit<unsigned long>();
+
+ test_failbit<float>();
+ test_failbit<double>();
+
+ test_failbit<void*>();
+
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit_throw.cc
new file mode 100644
index 00000000000..0b223bcbeef
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit_throw.cc
@@ -0,0 +1,78 @@
+// Copyright (C) 2003
+// Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <sstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+// libstdc++/10093
+template<typename T>
+void test_failbit()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ locale loc(locale::classic(), new __gnu_test::fail_num_get);
+ istringstream stream("jaylib - champion sound");
+ stream.imbue(loc);
+
+ stream.exceptions(ios_base::failbit);
+
+ try
+ {
+ T i;
+ stream >> i;
+ }
+ catch (const ios_base::failure&)
+ { VERIFY( false ); }
+ catch(...)
+ { VERIFY( false ); }
+
+ // stream should set badbit.
+ VERIFY( stream.bad() );
+ VERIFY( (stream.rdstate() & ios_base::failbit) == 0 );
+ VERIFY( !stream.eof() );
+}
+
+int main()
+{
+ test_failbit<bool>();
+ test_failbit<short>();
+ test_failbit<unsigned short>();
+ test_failbit<int>();
+ test_failbit<unsigned int>();
+ test_failbit<long>();
+ test_failbit<unsigned long>();
+
+ test_failbit<float>();
+ test_failbit<double>();
+
+ test_failbit<void*>();
+
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/error_failbit.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/error_failbit.cc
new file mode 100644
index 00000000000..2079b453995
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/error_failbit.cc
@@ -0,0 +1,67 @@
+// Copyright (C) 2003 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <istream>
+#include <streambuf>
+#include <sstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+using namespace std;
+
+void test6()
+{
+ bool test __attribute__((unused)) = true;
+ __gnu_test::fail_streambuf bib;
+ istream stream(&bib);
+ stringbuf sbuf("", ios_base::out);
+
+ stream >> &sbuf;
+
+ VERIFY(stream.rdstate() & ios_base::failbit);
+ VERIFY((stream.rdstate() & ios_base::badbit) == 0);
+}
+
+void test8()
+{
+ bool test __attribute__((unused)) = true;
+ istringstream stream("foo, bar, qux");
+ __gnu_test::fail_streambuf bob;
+
+ stream >> &bob;
+
+ VERIFY(stream.rdstate() & ios_base::failbit);
+ VERIFY((stream.rdstate() & ios_base::badbit) == 0);
+}
+
+// libstdc++/9371
+int main()
+{
+ test6();
+ test8();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_badbit_throw.cc
new file mode 100644
index 00000000000..86c0a8a1a92
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_badbit_throw.cc
@@ -0,0 +1,79 @@
+// Copyright (C) 2003 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <istream>
+#include <streambuf>
+#include <sstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+using namespace std;
+
+void test14()
+{
+ bool test __attribute__((unused)) = true;
+ __gnu_test::fail_streambuf bib;
+ istream stream(&bib);
+ stream.exceptions(ios_base::badbit);
+ stringbuf sbuf("", ios_base::out);
+
+ try
+ {
+ stream >> &sbuf;
+ }
+ catch (...)
+ { VERIFY(false); }
+
+ VERIFY(stream.rdstate() & ios_base::failbit);
+ VERIFY((stream.rdstate() & ios_base::badbit) == 0);
+}
+
+void test16()
+{
+ bool test __attribute__((unused)) = true;
+ istringstream stream("foo, bar, qux");
+ stream.exceptions(ios_base::badbit);
+ __gnu_test::fail_streambuf bob;
+
+ try
+ {
+ stream >> &bob;
+ }
+ catch (...)
+ { VERIFY(false); }
+
+ VERIFY(stream.rdstate() & ios_base::failbit);
+ VERIFY((stream.rdstate() & ios_base::badbit) == 0);
+}
+
+// libstdc++/9371
+int main()
+{
+ test14();
+ test16();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_failbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_failbit_throw.cc
new file mode 100644
index 00000000000..199750af0bd
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_failbit_throw.cc
@@ -0,0 +1,89 @@
+// Copyright (C) 2003 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <istream>
+#include <streambuf>
+#include <sstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+using namespace std;
+
+void test10()
+{
+ bool test __attribute__((unused)) = true;
+ __gnu_test::fail_streambuf bib;
+ istream stream(&bib);
+ stream.exceptions(ios_base::failbit);
+ stringbuf sbuf("", ios_base::out);
+
+ try
+ {
+ stream >> &sbuf;
+ VERIFY(false);
+ }
+ catch (ios_base::failure&)
+ { VERIFY(false); }
+ catch (__gnu_test::underflow_error&)
+ { }
+ catch (...)
+ { VERIFY(false); }
+
+ VERIFY(stream.rdstate() & ios_base::failbit);
+ VERIFY((stream.rdstate() & ios_base::badbit) == 0);
+}
+
+void test12()
+{
+ bool test __attribute__((unused)) = true;
+ istringstream stream("foo, bar, qux");
+ stream.exceptions(ios_base::failbit);
+ __gnu_test::fail_streambuf bob;
+
+ try
+ {
+ stream >> &bob;
+ VERIFY(false);
+ }
+ catch (ios_base::failure&)
+ { VERIFY(false); }
+ catch (__gnu_test::overflow_error&)
+ { }
+ catch (...)
+ { VERIFY(false); }
+
+ VERIFY(stream.rdstate() & ios_base::failbit);
+ VERIFY((stream.rdstate() & ios_base::badbit) == 0);
+}
+
+// libstdc++/9371
+int main()
+{
+ test10();
+ test12();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_null.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_null.cc
new file mode 100644
index 00000000000..8e012d13714
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_null.cc
@@ -0,0 +1,68 @@
+// Copyright (C) 2003 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <istream>
+#include <ostream>
+#include <streambuf>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+using namespace std;
+
+void test2()
+{
+ bool test __attribute__((unused)) = true;
+ istringstream stream;
+ stream >> static_cast<streambuf*>(NULL);
+ VERIFY(stream.rdstate() & ios_base::failbit);
+}
+
+void test4()
+{
+ bool test __attribute__((unused)) = true;
+ istringstream stream;
+ stream.exceptions(ios_base::failbit);
+
+ try
+ {
+ stream >> static_cast<streambuf*>(NULL);
+ VERIFY(false);
+ }
+ catch (ios_base::failure&)
+ {
+ }
+
+ VERIFY(stream.rdstate() & ios_base::failbit);
+}
+
+// libstdc++/9371
+int main()
+{
+ test2();
+ test4();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/exceptions_badbit_throw.cc
new file mode 100644
index 00000000000..bf893408064
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/exceptions_badbit_throw.cc
@@ -0,0 +1,96 @@
+// Copyright (C) 2003 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <istream>
+#include <streambuf>
+#include <sstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+using namespace std;
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ __gnu_test::fail_streambuf bib;
+ istream stream(&bib);
+ stream.exceptions(ios_base::badbit);
+
+ istream::pos_type pos;
+
+ try
+ {
+ stream.seekg(pos);
+ VERIFY( false );
+ }
+ catch (const __gnu_test::positioning_error&)
+ {
+ // stream should set badbit and rethrow facet_error.
+ VERIFY( stream.bad() );
+ VERIFY( (stream.rdstate() & ios_base::failbit) == 0 );
+ VERIFY( !stream.eof() );
+ }
+ catch (...)
+ {
+ VERIFY(false);
+ }
+}
+
+void test02()
+{
+ bool test __attribute__((unused)) = true;
+ __gnu_test::fail_streambuf bib;
+ istream stream(&bib);
+ stream.exceptions(ios_base::badbit);
+
+ istream::off_type off;
+
+ try
+ {
+ stream.seekg(off, ios_base::cur);
+ VERIFY( false );
+ }
+ catch (const __gnu_test::positioning_error&)
+ {
+ // stream should set badbit and rethrow facet_error.
+ VERIFY( stream.bad() );
+ VERIFY( (stream.rdstate() & ios_base::failbit) == 0 );
+ VERIFY( !stream.eof() );
+ }
+ catch (...)
+ {
+ VERIFY(false);
+ }
+}
+
+// libstdc++/9546
+int main()
+{
+ test01();
+ test02();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/exceptions_badbit_throw.cc
new file mode 100644
index 00000000000..bd90ab26ba7
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/exceptions_badbit_throw.cc
@@ -0,0 +1,66 @@
+// Copyright (C) 2003 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <istream>
+#include <streambuf>
+#include <sstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+using namespace std;
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ __gnu_test::fail_streambuf bib;
+ istream stream(&bib);
+ stream.exceptions(ios_base::badbit);
+
+ try
+ {
+ stream.tellg();
+ VERIFY( false );
+ }
+ catch (const __gnu_test::positioning_error&)
+ {
+ // stream should set badbit and rethrow facet_error.
+ VERIFY( stream.bad() );
+ VERIFY( (stream.rdstate() & ios_base::failbit) == 0 );
+ VERIFY( !stream.eof() );
+ }
+ catch (...)
+ {
+ VERIFY(false);
+ }
+}
+
+// libstdc++/9546
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/exceptions_badbit_throw.cc
new file mode 100644
index 00000000000..e8c5653189d
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/exceptions_badbit_throw.cc
@@ -0,0 +1,66 @@
+// Copyright (C) 2003 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <ostream>
+#include <streambuf>
+#include <sstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+using namespace std;
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ __gnu_test::fail_streambuf bib;
+ ostream stream(&bib);
+ stream.exceptions(ios_base::badbit);
+
+ try
+ {
+ stream.flush();
+ VERIFY( false );
+ }
+ catch (const __gnu_test::positioning_error&)
+ {
+ // stream should set badbit and rethrow facet_error.
+ VERIFY( stream.bad() );
+ VERIFY( (stream.rdstate() & ios_base::failbit) == 0 );
+ VERIFY( !stream.eof() );
+ }
+ catch (...)
+ {
+ VERIFY(false);
+ }
+}
+
+// libstdc++/9546
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_badbit_throw.cc
new file mode 100644
index 00000000000..a084dbdb7d4
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_badbit_throw.cc
@@ -0,0 +1,74 @@
+// 2003-03-08 Jerry Quinn <jlquinn@optonline.net>
+
+// Copyright (C) 2003 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+#include <locale>
+#include <sstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+// libstdc++/9561
+template<typename T>
+void test_badbit()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ locale loc(locale::classic(), new __gnu_test::fail_num_put);
+ ostringstream stream("jaylib - champion sound");
+ stream.imbue(loc);
+
+ stream.exceptions(ios_base::badbit);
+ VERIFY( stream.rdstate() == ios_base::goodbit );
+
+ try
+ {
+ T i;
+ stream << i;
+ VERIFY( false );
+ }
+ catch (const __gnu_test::facet_error&)
+ {
+ // stream should set badbit and rethrow facet_error.
+ VERIFY( stream.bad() );
+ VERIFY( (stream.rdstate() & ios_base::failbit) == 0 );
+ VERIFY( !stream.eof() );
+ }
+ catch (...)
+ {
+ VERIFY(false);
+ }
+}
+
+
+int main()
+{
+ test_badbit<bool>();
+ test_badbit<short>();
+ test_badbit<unsigned short>();
+ test_badbit<int>();
+ test_badbit<unsigned int>();
+ test_badbit<long>();
+ test_badbit<unsigned long>();
+
+ test_badbit<float>();
+ test_badbit<double>();
+
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_failbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_failbit_throw.cc
new file mode 100644
index 00000000000..a1fbe21178f
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_failbit_throw.cc
@@ -0,0 +1,76 @@
+// Copyright (C) 2003
+// Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <sstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+// libstdc++/10093
+template<typename T>
+void test_failbit()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ locale loc(locale::classic(), new __gnu_test::fail_num_put);
+ ostringstream stream("jaylib - champion sound");
+ stream.imbue(loc);
+
+ stream.exceptions(ios_base::failbit);
+
+ try
+ {
+ T i;
+ stream << i;
+ }
+ catch (const ios_base::failure&)
+ { VERIFY( false ); }
+ catch(...)
+ { VERIFY( false ); }
+
+ // stream should set badbit.
+ VERIFY( stream.bad() );
+ VERIFY( (stream.rdstate() & ios_base::failbit) == 0 );
+ VERIFY( !stream.eof() );
+}
+
+int main()
+{
+ test_failbit<bool>();
+ test_failbit<short>();
+ test_failbit<unsigned short>();
+ test_failbit<int>();
+ test_failbit<unsigned int>();
+ test_failbit<long>();
+ test_failbit<unsigned long>();
+
+ test_failbit<float>();
+ test_failbit<double>();
+
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_failbit.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_failbit.cc
new file mode 100644
index 00000000000..ce47b6f3989
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_failbit.cc
@@ -0,0 +1,67 @@
+// Copyright (C) 2003 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <ostream>
+#include <streambuf>
+#include <sstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+using namespace std;
+
+void test5()
+{
+ bool test __attribute__((unused)) = true;
+ __gnu_test::fail_streambuf bob;
+ ostream stream(&bob);
+ stringbuf sbuf("Foo, bar, qux", ios_base::in);
+
+ stream << &sbuf;
+
+ VERIFY(stream.rdstate() & ios_base::failbit);
+ VERIFY((stream.rdstate() & ios_base::badbit) == 0);
+}
+
+void test7()
+{
+ bool test __attribute__((unused)) = true;
+ ostringstream stream;
+ __gnu_test::fail_streambuf bib;
+
+ stream << &bib;
+
+ VERIFY(stream.rdstate() & ios_base::failbit);
+ VERIFY((stream.rdstate() & ios_base::badbit) == 0);
+}
+
+// libstdc++/9371
+int main()
+{
+ test5();
+ test7();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_badbit_throw.cc
new file mode 100644
index 00000000000..13ff248940b
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_badbit_throw.cc
@@ -0,0 +1,79 @@
+// Copyright (C) 2003 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <ostream>
+#include <streambuf>
+#include <sstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+using namespace std;
+
+void test13()
+{
+ bool test __attribute__((unused)) = true;
+ __gnu_test::fail_streambuf bob;
+ ostream stream(&bob);
+ stream.exceptions(ios_base::badbit);
+ stringbuf sbuf("Foo, bar, qux", ios_base::in);
+
+ try
+ {
+ stream << &sbuf;
+ }
+ catch (...)
+ { VERIFY(false); }
+
+ VERIFY(stream.rdstate() & ios_base::failbit);
+ VERIFY((stream.rdstate() & ios_base::badbit) == 0);
+}
+
+void test15()
+{
+ bool test __attribute__((unused)) = true;
+ ostringstream stream;
+ stream.exceptions(ios_base::badbit);
+ __gnu_test::fail_streambuf bib;
+
+ try
+ {
+ stream << &bib;
+ }
+ catch (...)
+ { VERIFY(false); }
+
+ VERIFY(stream.rdstate() & ios_base::failbit);
+ VERIFY((stream.rdstate() & ios_base::badbit) == 0);
+}
+
+// libstdc++/9371
+int main()
+{
+ test13();
+ test15();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_failbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_failbit_throw.cc
new file mode 100644
index 00000000000..5abaf92b804
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_failbit_throw.cc
@@ -0,0 +1,89 @@
+// Copyright (C) 2003 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <ostream>
+#include <streambuf>
+#include <sstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+using namespace std;
+
+void test9()
+{
+ bool test __attribute__((unused)) = true;
+ __gnu_test::fail_streambuf bob;
+ ostream stream(&bob);
+ stream.exceptions(ios_base::failbit);
+ stringbuf sbuf("Foo, bar, qux", ios_base::in);
+
+ try
+ {
+ stream << &sbuf;
+ VERIFY(false);
+ }
+ catch (ios_base::failure&)
+ { VERIFY(false); }
+ catch (__gnu_test::overflow_error&)
+ { }
+ catch (...)
+ { VERIFY(false); }
+
+ VERIFY(stream.rdstate() & ios_base::failbit);
+ VERIFY((stream.rdstate() & ios_base::badbit) == 0);
+}
+
+void test11()
+{
+ bool test __attribute__((unused)) = true;
+ ostringstream stream;
+ stream.exceptions(ios_base::failbit);
+ __gnu_test::fail_streambuf bib;
+
+ try
+ {
+ stream << &bib;
+ VERIFY(false);
+ }
+ catch (ios_base::failure&)
+ { VERIFY(false); }
+ catch (__gnu_test::underflow_error&)
+ { }
+ catch (...)
+ { VERIFY(false); }
+
+ VERIFY(stream.rdstate() & ios_base::failbit);
+ VERIFY((stream.rdstate() & ios_base::badbit) == 0);
+}
+
+// libstdc++/9371
+int main()
+{
+ test9();
+ test11();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_null.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_null.cc
new file mode 100644
index 00000000000..3f2de4d683b
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_null.cc
@@ -0,0 +1,68 @@
+// Copyright (C) 2003 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <istream>
+#include <ostream>
+#include <streambuf>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+using namespace std;
+
+void test1()
+{
+ bool test __attribute__((unused)) = true;
+ ostringstream stream;
+ stream << static_cast<streambuf*>(NULL);
+ VERIFY(stream.rdstate() & ios_base::badbit);
+}
+
+void test3()
+{
+ bool test __attribute__((unused)) = true;
+ ostringstream stream;
+ stream.exceptions(ios_base::badbit);
+
+ try
+ {
+ stream << static_cast<streambuf*>(NULL);
+ VERIFY(false);
+ }
+ catch (ios_base::failure&)
+ {
+ }
+
+ VERIFY(stream.rdstate() & ios_base::badbit);
+}
+
+// libstdc++/9371
+int main()
+{
+ test1();
+ test3();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/exceptions_badbit_throw.cc
new file mode 100644
index 00000000000..b0b30518eb0
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/exceptions_badbit_throw.cc
@@ -0,0 +1,96 @@
+// Copyright (C) 2003 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <ostream>
+#include <streambuf>
+#include <sstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+using namespace std;
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ __gnu_test::fail_streambuf bib;
+ ostream stream(&bib);
+ stream.exceptions(ios_base::badbit);
+
+ ostream::pos_type pos;
+
+ try
+ {
+ stream.seekp(pos);
+ VERIFY( false );
+ }
+ catch (const __gnu_test::positioning_error&)
+ {
+ // stream should set badbit and rethrow facet_error.
+ VERIFY( stream.bad() );
+ VERIFY( (stream.rdstate() & ios_base::failbit) == 0 );
+ VERIFY( !stream.eof() );
+ }
+ catch (...)
+ {
+ VERIFY(false);
+ }
+}
+
+void test02()
+{
+ bool test __attribute__((unused)) = true;
+ __gnu_test::fail_streambuf bib;
+ ostream stream(&bib);
+ stream.exceptions(ios_base::badbit);
+
+ ostream::off_type off;
+
+ try
+ {
+ stream.seekp(off, ios_base::cur);
+ VERIFY( false );
+ }
+ catch (const __gnu_test::positioning_error&)
+ {
+ // stream should set badbit and rethrow facet_error.
+ VERIFY( stream.bad() );
+ VERIFY( (stream.rdstate() & ios_base::failbit) == 0 );
+ VERIFY( !stream.eof() );
+ }
+ catch (...)
+ {
+ VERIFY(false);
+ }
+}
+
+// libstdc++/9546
+int main()
+{
+ test01();
+ test02();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/exceptions_badbit_throw.cc
new file mode 100644
index 00000000000..01d346ab7ba
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/exceptions_badbit_throw.cc
@@ -0,0 +1,66 @@
+// Copyright (C) 2003 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <ostream>
+#include <streambuf>
+#include <sstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+using namespace std;
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ __gnu_test::fail_streambuf bib;
+ ostream stream(&bib);
+ stream.exceptions(ios_base::badbit);
+
+ try
+ {
+ stream.tellp();
+ VERIFY( false );
+ }
+ catch (const __gnu_test::positioning_error&)
+ {
+ // stream should set badbit and rethrow facet_error.
+ VERIFY( stream.bad() );
+ VERIFY( (stream.rdstate() & ios_base::failbit) == 0 );
+ VERIFY( !stream.eof() );
+ }
+ catch (...)
+ {
+ VERIFY(false);
+ }
+}
+
+// libstdc++/9546
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/testsuite_io.h b/libstdc++-v3/testsuite/testsuite_io.h
index 86e1696845b..294f4273662 100644
--- a/libstdc++-v3/testsuite/testsuite_io.h
+++ b/libstdc++-v3/testsuite/testsuite_io.h
@@ -70,8 +70,7 @@ namespace __gnu_test
bool one = this->pbase() == NULL;
bool two = this->pptr() == NULL;
return one && two;
- }
-
+ }
};
// Used to check if basic_streambuf::pubsync() has been called.
@@ -97,6 +96,164 @@ namespace __gnu_test
return 0;
}
};
+
+ // Throws on all overflow and underflow calls.
+ struct underflow_error: std::exception { };
+ struct overflow_error: std::exception { };
+ struct positioning_error: std::exception { };
+
+ struct fail_streambuf : std::streambuf
+ {
+ fail_streambuf()
+ {
+ static char p[] = "s";
+ setg(p, p, p + 1);
+ }
+
+ virtual int_type underflow()
+ {
+ throw underflow_error();
+ return -1;
+ }
+
+ virtual int_type uflow()
+ {
+ throw underflow_error();
+ return -1;
+ }
+
+ virtual int_type
+ overflow(int_type)
+ {
+ throw overflow_error();
+ return -1;
+ }
+
+ virtual pos_type
+ seekoff(off_type, std::ios_base::seekdir, std::ios_base::openmode)
+ {
+ throw positioning_error();
+ return pos_type(off_type(-1));
+ }
+
+ virtual pos_type
+ seekpos(pos_type, std::ios_base::openmode)
+ {
+ throw positioning_error();
+ return pos_type(off_type(-1));
+ }
+
+ virtual int
+ sync()
+ {
+ throw positioning_error();
+ return 0;
+ }
+ };
+
+ // Facets that throw an exception for every virtual function.
+ struct facet_error: std::exception { };
+
+ class fail_num_get : public std::num_get<char>
+ {
+ typedef std::ios_base ios_base;
+
+ protected:
+ iter_type
+ do_get(iter_type a, iter_type, ios_base&, ios_base::iostate&, bool&) const
+ { throw facet_error(); return iter_type(); }
+
+ virtual iter_type
+ do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, long&) const
+ { throw facet_error(); return iter_type(); }
+
+ virtual iter_type
+ do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
+ unsigned short&) const
+ { throw facet_error(); return iter_type(); }
+
+ virtual iter_type
+ do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
+ unsigned int&) const
+ { throw facet_error(); return iter_type(); }
+
+ virtual iter_type
+ do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
+ unsigned long&) const
+ { throw facet_error(); return iter_type(); }
+
+#ifdef _GLIBCXX_USE_LONG_LONG
+ virtual iter_type
+ do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
+ long long&) const
+ { throw facet_error(); return iter_type(); }
+
+ virtual iter_type
+ do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
+ unsigned long long&) const
+ { throw facet_error(); return iter_type(); }
+#endif
+
+ virtual iter_type
+ do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
+ float&) const
+ { throw facet_error(); return iter_type(); }
+
+ virtual iter_type
+ do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
+ double&) const
+ { throw facet_error(); return iter_type(); }
+
+ virtual iter_type
+ do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
+ long double&) const
+ { throw facet_error(); return iter_type(); }
+
+ virtual iter_type
+ do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
+ void*&) const
+ { throw facet_error(); return iter_type(); }
+ };
+
+ class fail_num_put : public std::num_put<char>
+ {
+ typedef std::ios_base ios_base;
+
+ protected:
+ iter_type
+ do_put(iter_type, ios_base&, char_type __fill, bool __v) const
+ { throw facet_error(); return iter_type(NULL); }
+
+ virtual iter_type
+ do_put(iter_type, ios_base&, char_type __fill, long __v) const
+ { throw facet_error(); return iter_type(NULL); }
+
+ virtual iter_type
+ do_put(iter_type, ios_base&, char_type __fill, unsigned long) const
+ { throw facet_error(); return iter_type(NULL); }
+
+#ifdef _GLIBCXX_USE_LONG_LONG
+ virtual iter_type
+ do_put(iter_type, ios_base&, char_type __fill, long long __v) const
+ { throw facet_error(); return iter_type(NULL); }
+
+ virtual iter_type
+ do_put(iter_type, ios_base&, char_type __fill, unsigned long long) const
+ { throw facet_error(); return iter_type(NULL); }
+#endif
+
+ virtual iter_type
+ do_put(iter_type, ios_base&, char_type __fill, double __v) const
+ { throw facet_error(); return iter_type(NULL); }
+
+ virtual iter_type
+ do_put(iter_type, ios_base&, char_type __fill, long double __v) const
+ { throw facet_error(); return iter_type(NULL); }
+
+ virtual iter_type
+ do_put(iter_type, ios_base&, char_type __fill, const void* __v) const
+ { throw facet_error(); return iter_type(NULL); }
+ };
}; // namespace __gnu_test
#endif // _GLIBCXX_TESTSUITE_IO_H