aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerry Quinn <jlquinn@optonline.net>2003-03-09 04:19:52 +0000
committerJerry Quinn <jlquinn@gcc.gnu.org>2003-03-09 04:19:52 +0000
commit6f62fbd81ab52e09dee9c35b2e016893fc04082a (patch)
treef8374771f18cc2f7254a2fc57e9a9f3f757b5c1a
parent4f4ebda3297c76529829f827ac7b8d17b74d044c (diff)
downloadgcc-6f62fbd81ab52e09dee9c35b2e016893fc04082a.zip
gcc-6f62fbd81ab52e09dee9c35b2e016893fc04082a.tar.gz
gcc-6f62fbd81ab52e09dee9c35b2e016893fc04082a.tar.bz2
re PR libstdc++/9561 (ostream inserters rethrow exception of wrong type)
2003-03-08 Jerry Quinn <jlquinn@optonline.net> PR libstdc++/9561 * include/bits/basic_ios.h (_M_setstate): New. * include/bits/ostream.tcc (operator<<): Use it. * include/bits/istream.tcc (operator>>): Use it. * include/std/std_ostream.h (operator<<): Make friends. * include/std/std_istream.h (operator>>): Make friends. * testsuite/27_io/ostream_exception.cc, testsuite/27_io/istream_exception.cc: New tests. From-SVN: r64021
-rw-r--r--libstdc++-v3/ChangeLog11
-rw-r--r--libstdc++-v3/include/bits/basic_ios.h5
-rw-r--r--libstdc++-v3/include/bits/istream.tcc56
-rw-r--r--libstdc++-v3/include/bits/ostream.tcc34
-rw-r--r--libstdc++-v3/include/std/std_istream.h8
-rw-r--r--libstdc++-v3/include/std/std_ostream.h20
-rw-r--r--libstdc++-v3/testsuite/27_io/istream_exception.cc68
-rw-r--r--libstdc++-v3/testsuite/27_io/ostream_exception.cc66
8 files changed, 223 insertions, 45 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index c5a4dbc..81ac17e 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,14 @@
+2003-03-08 Jerry Quinn <jlquinn@optonline.net>
+
+ PR libstdc++/9561
+ * include/bits/basic_ios.h (_M_setstate): New.
+ * include/bits/ostream.tcc (operator<<): Use it.
+ * include/bits/istream.tcc (operator>>): Use it.
+ * include/std/std_ostream.h (operator<<): Make friends.
+ * include/std/std_istream.h (operator>>): Make friends.
+ * testsuite/27_io/ostream_exception.cc,
+ testsuite/27_io/istream_exception.cc: New tests.
+
2003-03-08 Benjamin Kosnik <bkoz@redhat.com>
* include/bits/locale_facets.tcc: Fix typo.
diff --git a/libstdc++-v3/include/bits/basic_ios.h b/libstdc++-v3/include/bits/basic_ios.h
index 7d0e47e..03b54b7 100644
--- a/libstdc++-v3/include/bits/basic_ios.h
+++ b/libstdc++-v3/include/bits/basic_ios.h
@@ -441,6 +441,11 @@ namespace std
void
_M_cache_locale(const locale& __loc);
+
+ // Internal state setter that won't throw, only set the state bits.
+ // Used to guarantee we don't throw when setting badbit.
+ void
+ _M_setstate(iostate __state) { _M_streambuf_state |= __state; }
};
} // namespace std
diff --git a/libstdc++-v3/include/bits/istream.tcc b/libstdc++-v3/include/bits/istream.tcc
index 0bd7fff..68295b4 100644
--- a/libstdc++-v3/include/bits/istream.tcc
+++ b/libstdc++-v3/include/bits/istream.tcc
@@ -122,7 +122,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -159,7 +159,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -186,7 +186,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -223,7 +223,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -250,7 +250,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -277,7 +277,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -304,7 +304,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -332,7 +332,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -359,7 +359,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -387,7 +387,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -414,7 +414,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -441,7 +441,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -468,7 +468,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -499,7 +499,7 @@ namespace std
{
// 27.6.2.5.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -531,7 +531,7 @@ namespace std
{
// 27.6.1.3 paragraph 1
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -565,7 +565,7 @@ namespace std
{
// 27.6.1.3 paragraph 1
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -604,7 +604,7 @@ namespace std
{
// 27.6.1.3 paragraph 1
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -647,7 +647,7 @@ namespace std
{
// 27.6.1.3 paragraph 1
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -698,7 +698,7 @@ namespace std
{
// 27.6.1.3 paragraph 1
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -739,7 +739,7 @@ namespace std
{
// 27.6.1.3 paragraph 1
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -763,7 +763,7 @@ namespace std
{
// 27.6.1.3 paragraph 1
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -790,7 +790,7 @@ namespace std
{
// 27.6.1.3 paragraph 1
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -826,7 +826,7 @@ namespace std
{
// 27.6.1.3 paragraph 1
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -856,7 +856,7 @@ namespace std
{
// 27.6.1.3 paragraph 1
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -887,7 +887,7 @@ namespace std
{
// 27.6.1.3 paragraph 1
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -922,7 +922,7 @@ namespace std
{
// 27.6.1.3 paragraph 1
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -998,7 +998,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- __in.setstate(ios_base::badbit);
+ __in._M_setstate(ios_base::badbit);
if ((__in.exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -1055,7 +1055,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- __in.setstate(ios_base::badbit);
+ __in._M_setstate(ios_base::badbit);
if ((__in.exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
diff --git a/libstdc++-v3/include/bits/ostream.tcc b/libstdc++-v3/include/bits/ostream.tcc
index a60dd72..64b37a4 100644
--- a/libstdc++-v3/include/bits/ostream.tcc
+++ b/libstdc++-v3/include/bits/ostream.tcc
@@ -70,7 +70,7 @@ namespace std
{
// 27.6.2.5.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -92,7 +92,7 @@ namespace std
{
// 27.6.2.5.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -114,7 +114,7 @@ namespace std
{
// 27.6.2.5.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -138,7 +138,7 @@ namespace std
{
// 27.6.2.5.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -166,7 +166,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -205,7 +205,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -231,7 +231,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -272,7 +272,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -298,7 +298,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -325,7 +325,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -351,7 +351,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -377,7 +377,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- this->setstate(ios_base::badbit);
+ this->_M_setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -499,7 +499,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- __out.setstate(ios_base::badbit);
+ __out._M_setstate(ios_base::badbit);
if ((__out.exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -535,7 +535,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- __out.setstate(ios_base::badbit);
+ __out._M_setstate(ios_base::badbit);
if ((__out.exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -570,7 +570,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- __out.setstate(ios_base::badbit);
+ __out._M_setstate(ios_base::badbit);
if ((__out.exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -619,7 +619,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- __out.setstate(ios_base::badbit);
+ __out._M_setstate(ios_base::badbit);
if ((__out.exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
@@ -658,7 +658,7 @@ namespace std
{
// 27.6.1.2.1 Common requirements.
// Turn this on without causing an ios::failure to be thrown.
- __out.setstate(ios_base::badbit);
+ __out._M_setstate(ios_base::badbit);
if ((__out.exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
}
diff --git a/libstdc++-v3/include/std/std_istream.h b/libstdc++-v3/include/std/std_istream.h
index aab3db3..fa97f72 100644
--- a/libstdc++-v3/include/std/std_istream.h
+++ b/libstdc++-v3/include/std/std_istream.h
@@ -73,6 +73,14 @@ namespace std
typedef num_get<_CharT, __istreambuf_iter> __numget_type;
typedef ctype<_CharT> __ctype_type;
+ template<typename _CharT2, typename _Traits2>
+ friend basic_istream<_CharT2, _Traits2>&
+ operator>>(basic_istream<_CharT2, _Traits2>&, _CharT2&);
+
+ template<typename _CharT2, typename _Traits2>
+ friend basic_istream<_CharT2, _Traits2>&
+ operator>>(basic_istream<_CharT2, _Traits2>&, _CharT2*);
+
protected:
// Data Members:
/**
diff --git a/libstdc++-v3/include/std/std_ostream.h b/libstdc++-v3/include/std/std_ostream.h
index 9f7c386..103b3fd 100644
--- a/libstdc++-v3/include/std/std_ostream.h
+++ b/libstdc++-v3/include/std/std_ostream.h
@@ -73,6 +73,26 @@ namespace std
typedef num_put<_CharT, __ostreambuf_iter> __numput_type;
typedef ctype<_CharT> __ctype_type;
+ template<typename _CharT2, typename _Traits2>
+ friend basic_ostream<_CharT2, _Traits2>&
+ operator<<(basic_ostream<_CharT2, _Traits2>&, _CharT2);
+
+ template<typename _Traits2>
+ friend basic_ostream<char, _Traits2>&
+ operator<<(basic_ostream<char, _Traits2>&, char);
+
+ template<typename _CharT2, typename _Traits2>
+ friend basic_ostream<_CharT2, _Traits2>&
+ operator<<(basic_ostream<_CharT2, _Traits2>&, const _CharT2*);
+
+ template<typename _Traits2>
+ friend basic_ostream<char, _Traits2>&
+ operator<<(basic_ostream<char, _Traits2>&, const char*);
+
+ template<typename _CharT2, typename _Traits2>
+ friend basic_ostream<_CharT2, _Traits2>&
+ operator<<(basic_ostream<_CharT2, _Traits2>&, const char*);
+
// [27.6.2.2] constructor/destructor
/**
* @brief Base constructor.
diff --git a/libstdc++-v3/testsuite/27_io/istream_exception.cc b/libstdc++-v3/testsuite/27_io/istream_exception.cc
new file mode 100644
index 0000000..2c3b121
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/istream_exception.cc
@@ -0,0 +1,68 @@
+// 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 <istream>
+#include <streambuf>
+#include <testsuite_hooks.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;
+
+ buf 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);
+ }
+
+ VERIFY(i == 0);
+}
+
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/ostream_exception.cc b/libstdc++-v3/testsuite/27_io/ostream_exception.cc
new file mode 100644
index 0000000..8c2b340
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/ostream_exception.cc
@@ -0,0 +1,66 @@
+// 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 <ostream>
+#include <streambuf>
+#include <testsuite_hooks.h>
+
+// libstdc++/9561
+struct foobar: std::exception { };
+
+struct buf: std::streambuf
+{
+ virtual int_type overflow (int_type) {
+ throw foobar ();
+ return -1;
+ }
+};
+
+void test01()
+{
+ using namespace std;
+ bool test = true;
+
+ buf b;
+ std::ostream strm (&b);
+ strm.exceptions (std::ios::badbit);
+
+ try {
+ strm << std::endl;
+ }
+ catch (foobar) {
+ // strm should throw foobar and not do anything else
+ VERIFY(strm.bad());
+ return;
+ }
+ catch (...) {
+ VERIFY(false);
+ return;
+ }
+
+ VERIFY(false);
+}
+
+
+int main()
+{
+ test01();
+ return 0;
+}