This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] PR libstdc++/9561, take 2


Here's the revised PR 9561 patch.  Hopefully this is good.  I'm heading out of
town this week so if it needs more work, it will have to wait or someone else
will have to finish it.

Later,
Jerry


2003-03-08  Jerry Quinn  <jlquinn at optonline dot 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.

diff -r -u -N libstdc++.33.postcache/include/bits/basic_ios.h libstdc++-v3/include/bits/basic_ios.h
--- libstdc++.33.postcache/include/bits/basic_ios.h	Sat Mar  8 11:18:16 2003
+++ libstdc++-v3/include/bits/basic_ios.h	Sat Mar  8 01:46:31 2003
@@ -439,6 +439,11 @@
       void
       _M_cache_facets(const locale& __loc);
 #endif
+ 
+       // 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 -r -u -N libstdc++.33.postcache/include/bits/istream.tcc libstdc++-v3/include/bits/istream.tcc
--- libstdc++.33.postcache/include/bits/istream.tcc	Sun Mar  2 23:05:09 2003
+++ libstdc++-v3/include/bits/istream.tcc	Sat Mar  8 10:33:43 2003
@@ -122,7 +122,7 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	     {
 	       // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 -r -u -N libstdc++.33.postcache/include/bits/ostream.tcc libstdc++-v3/include/bits/ostream.tcc
--- libstdc++.33.postcache/include/bits/ostream.tcc	Sun Mar  2 23:05:09 2003
+++ libstdc++-v3/include/bits/ostream.tcc	Sat Mar  8 01:39:37 2003
@@ -70,7 +70,7 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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 @@
 	    {
 	      // 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;
 	    }
@@ -165,7 +165,7 @@
 	    {
 	      // 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;
 	    }
@@ -202,7 +202,7 @@
 	    {
 	      // 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;
 	    }
@@ -227,7 +227,7 @@
 	    {
 	      // 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;
 	    }
@@ -266,7 +266,7 @@
 	    {
 	      // 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;
 	    }
@@ -291,7 +291,7 @@
 	    {
 	      // 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;
 	    }
@@ -317,7 +317,7 @@
 	    {
 	      // 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;
 	    }
@@ -342,7 +342,7 @@
 	    {
 	      // 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;
 	    }
@@ -367,7 +367,7 @@
 	    {
 	      // 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;
 	    }
@@ -493,7 +493,7 @@
 	    {
 	      // 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;
 	    }
@@ -529,7 +529,7 @@
 	    {
 	      // 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;
 	    }
@@ -564,7 +564,7 @@
 	    {
 	      // 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;
 	    }
@@ -613,7 +613,7 @@
 	    {
 	      // 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;
 	    }
@@ -652,7 +652,7 @@
 	    {
 	      // 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 -r -u -N libstdc++.33.postcache/include/std/std_istream.h libstdc++-v3/include/std/std_istream.h
--- libstdc++.33.postcache/include/std/std_istream.h	Sun Mar  2 23:05:13 2003
+++ libstdc++-v3/include/std/std_istream.h	Sat Mar  8 11:29:16 2003
@@ -73,6 +73,14 @@
       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 -r -u -N libstdc++.33.postcache/include/std/std_ostream.h libstdc++-v3/include/std/std_ostream.h
--- libstdc++.33.postcache/include/std/std_ostream.h	Sun Mar  2 23:05:13 2003
+++ libstdc++-v3/include/std/std_ostream.h	Sat Mar  8 11:20:01 2003
@@ -73,6 +73,26 @@
       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 -r -u -N libstdc++.33.postcache/testsuite/27_io/istream_exception.cc libstdc++-v3/testsuite/27_io/istream_exception.cc
--- libstdc++.33.postcache/testsuite/27_io/istream_exception.cc	Wed Dec 31 19:00:00 1969
+++ libstdc++-v3/testsuite/27_io/istream_exception.cc	Sat Mar  8 10:47:43 2003
@@ -0,0 +1,68 @@
+// 2003-03-08  Jerry Quinn  <jlquinn at optonline dot 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 -r -u -N libstdc++.33.postcache/testsuite/27_io/ostream_exception.cc libstdc++-v3/testsuite/27_io/ostream_exception.cc
--- libstdc++.33.postcache/testsuite/27_io/ostream_exception.cc	Wed Dec 31 19:00:00 1969
+++ libstdc++-v3/testsuite/27_io/ostream_exception.cc	Sat Mar  8 10:45:56 2003
@@ -0,0 +1,66 @@
+// 2003-03-08  Jerry Quinn  <jlquinn at optonline dot 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;
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]