basic_ios.h (basic_ios::setstate): Revert.
authorBenjamin Kosnik <bkoz@redhat.com>
Tue, 2 Dec 2003 02:48:51 +0000 (02:48 +0000)
committerBenjamin Kosnik <bkoz@gcc.gnu.org>
Tue, 2 Dec 2003 02:48:51 +0000 (02:48 +0000)
2003-12-01  Benjamin Kosnik  <bkoz@redhat.com>

* include/bits/basic_ios.h (basic_ios::setstate): Revert.
* include/bits/istream.tcc: Only call setstate if __err != goodbit.
* include/bits/ostream.tcc: Same.
* testsuite/27_io/basic_ios/exceptions/char/2.cc: New.

* testsuite/testsuite_io.h (__gnu_test::fail_streambuf): Make
internal buffer non-static.

From-SVN: r74151

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/basic_ios.h
libstdc++-v3/include/bits/istream.tcc
libstdc++-v3/include/bits/ostream.tcc
libstdc++-v3/testsuite/27_io/basic_ios/exceptions/char/2.cc [new file with mode: 0644]
libstdc++-v3/testsuite/testsuite_io.h

index 7b3acabb8a35859abc89e70cae7fa06698d03ae7..080f55a21b7347a549ad119826f4ea77e98d39c0 100644 (file)
@@ -1,3 +1,13 @@
+2003-12-01  Benjamin Kosnik  <bkoz@redhat.com>
+
+       * include/bits/basic_ios.h (basic_ios::setstate): Revert.
+       * include/bits/istream.tcc: Only call setstate if __err != goodbit.
+       * include/bits/ostream.tcc: Same.
+       * testsuite/27_io/basic_ios/exceptions/char/2.cc: New.
+       
+       * testsuite/testsuite_io.h (__gnu_test::fail_streambuf): Make
+       internal buffer non-static.
+
 2003-12-01  Benjamin Kosnik  <bkoz@redhat.com>
 
        * docs/html/17_intro/C++STYLE: Add exception bits.
index 5ada6dab7b317f934daed6739d9a3b0811246bc9..a9cb8d25dd9de37c4cb5f4a4b29fcc1955585da9 100644 (file)
@@ -141,10 +141,7 @@ namespace std
       */
       void 
       setstate(iostate __state) 
-      {
-       if (__state != ios_base::goodbit)
-         this->clear(this->rdstate() | __state); 
-      }
+      { this->clear(this->rdstate() | __state); }
 
       // Flip the internal state on for the proper state bits, then re
       // throws the propagated exception if bit also set in
index 0d85cc1bda1593f683ce15910c95619980102901..abe795031df233b3248f612540021bc194f7b4e0 100644 (file)
@@ -77,8 +77,8 @@ namespace std
        {
          _M_ok = false;
          __err |= ios_base::failbit;
+         __in.setstate(__err);
        }
-      __in.setstate(__err);
     }
 
   template<typename _CharT, typename _Traits>
@@ -121,7 +121,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -151,7 +152,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -172,7 +174,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -202,7 +205,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -223,7 +227,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -244,7 +249,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -265,7 +271,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -287,7 +294,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -308,7 +316,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -330,7 +339,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -351,7 +361,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -372,7 +383,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -393,7 +405,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -417,7 +430,8 @@ namespace std
        }
       else if (!__sbout)
        __err |= ios_base::failbit;
-      this->setstate(__err);
+      if (__err)
+       this->setstate(__err);
       return *this;
     }
 
@@ -447,7 +461,8 @@ namespace std
        }
       if (!_M_gcount)
        __err |= ios_base::failbit;
-      this->setstate(__err);
+      if (__err)
+       this->setstate(__err);
       return __c;
     }
 
@@ -478,7 +493,8 @@ namespace std
        }
       if (!_M_gcount)
        __err |= ios_base::failbit;
-      this->setstate(__err);
+      if (__err)
+       this->setstate(__err);
       return *this;
     }
 
@@ -516,7 +532,8 @@ namespace std
       *__s = char_type();
       if (!_M_gcount)
        __err |= ios_base::failbit;
-      this->setstate(__err);
+      if (__err)
+       this->setstate(__err);
       return *this;
     }
 
@@ -554,7 +571,8 @@ namespace std
        }
       if (!_M_gcount)
        __err |= ios_base::failbit;
-      this->setstate(__err);
+      if (__err)
+       this->setstate(__err);
       return *this;
     }
 
@@ -602,7 +620,8 @@ namespace std
       *__s = char_type();
       if (!_M_gcount)
        __err |= ios_base::failbit;
-      this->setstate(__err);
+      if (__err)
+       this->setstate(__err);
       return *this;
     }
   
@@ -635,7 +654,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -659,7 +679,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        } 
       return __c;
     }
@@ -682,7 +703,8 @@ namespace std
            }       
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -712,7 +734,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return _M_gcount;
     }
@@ -739,7 +762,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -766,7 +790,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -796,7 +821,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return __ret;
     }
@@ -841,7 +867,8 @@ namespace std
        }
       catch(...)
        { this->_M_setstate(ios_base::badbit); }
-      this->setstate(__err);
+      if (__err)
+       this->setstate(__err);
       return *this;
     }
 
@@ -868,7 +895,8 @@ namespace std
        }
       catch(...)
        { this->_M_setstate(ios_base::badbit); }
-      this->setstate(__err);
+      if (__err)
+       this->setstate(__err);
       return *this;
     }
 
@@ -892,7 +920,8 @@ namespace std
            }
          catch(...)
            { __in._M_setstate(ios_base::badbit); }
-         __in.setstate(__err);
+         if (__err)
+           __in.setstate(__err);
        }
       return __in;
     }
@@ -947,7 +976,8 @@ namespace std
        }
       if (!__extracted)
        __err |= ios_base::failbit;
-      __in.setstate(__err);
+      if (__err)
+       __in.setstate(__err);
       return __in;
     }
 
@@ -1028,7 +1058,8 @@ namespace std
       // 211.  operator>>(istream&, string&) doesn't set failbit
       if (!__extracted)
        __err |= ios_base::failbit;
-      __in.setstate(__err);
+      if (__err)
+       __in.setstate(__err);
       return __in;
     }
 
@@ -1081,7 +1112,8 @@ namespace std
        }
       if ((!__extracted && !__testdelim) || __extracted == __n)
        __err |= ios_base::failbit;
-      __in.setstate(__err);
+      if (__err)
+       __in.setstate(__err);
       return __in;
     }
 
index c7da8c66011987e414907243274e6d03c6a08754..c8f7fc73c359cd36940ce1c976ccdc941d577481 100644 (file)
@@ -111,7 +111,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -143,7 +144,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -165,7 +167,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -199,7 +202,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -221,7 +225,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -244,7 +249,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -266,7 +272,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -288,7 +295,8 @@ namespace std
            }
          catch(...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;
     }
@@ -312,7 +320,8 @@ namespace std
        }
       else if (!__sbin)
        __err |= ios_base::badbit;
-      this->setstate(__err);
+      if (__err)
+       this->setstate(__err);
       return *this;
     }
 
@@ -339,7 +348,8 @@ namespace std
            }
          catch (...)
            { this->_M_setstate(ios_base::badbit); }
-         this->setstate(__err);
+         if (__err)
+           this->setstate(__err);
        }
       return *this;  
     }
@@ -383,7 +393,8 @@ namespace std
        }
       catch(...)
        { this->_M_setstate(ios_base::badbit); }
-      this->setstate(__err);
+      if (__err)
+       this->setstate(__err);
       return *this;
     }
   
@@ -424,7 +435,8 @@ namespace std
        }
       catch(...)
        { this->_M_setstate(ios_base::badbit); }
-      this->setstate(__err);
+      if (__err)
+       this->setstate(__err);
       return *this;
     }
 
@@ -450,7 +462,8 @@ namespace std
        }
       catch(...)
        { this->_M_setstate(ios_base::badbit); }
-      this->setstate(__err);
+      if (__err)
+       this->setstate(__err);
       return *this;
     }
 
diff --git a/libstdc++-v3/testsuite/27_io/basic_ios/exceptions/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ios/exceptions/char/2.cc
new file mode 100644 (file)
index 0000000..b9f938e
--- /dev/null
@@ -0,0 +1,59 @@
+// 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.
+
+// 27.4.4.2 basic_ios member functions
+
+#include <sstream>
+#include <testsuite_hooks.h>
+
+int main()
+{
+  using namespace std;
+  ostringstream stream;
+  
+  try 
+    {
+      stream.setstate(ios_base::failbit);
+      stream.exceptions(ios_base::failbit);
+      assert(false);
+    } 
+  catch (...) 
+    {
+      // Don't clear.
+    }
+
+  try
+    {
+      // Calls clear(rdstate()), which throws in this case.
+      stream.setstate(ios_base::goodbit);
+      assert(false);
+    }
+  catch (...) 
+    { }
+
+  return 0;
+}
index 294f4273662f3b6e38b0befafb9635a1cbfc93c5..e5e342eed149c99279a6aa7979efff81b567578a 100644 (file)
@@ -104,10 +104,15 @@ namespace __gnu_test
 
   struct fail_streambuf : std::streambuf
   {
+  private:
+    char p[2];
+
+  public:
     fail_streambuf()
     {
-      static char p[] = "s";
-      setg(p, p, p + 1);
+      p[0] = 's';
+      p[1] = char();
+      setg(p, p, p + 1); 
     }
 
     virtual int_type underflow()