From bd6d5c37a0f4593df4a58545941bcb36e387284e Mon Sep 17 00:00:00 2001 From: bkoz Date: Tue, 2 Dec 2003 02:48:51 +0000 Subject: [PATCH] 2003-12-01 Benjamin Kosnik * 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@74151 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 10 +++ libstdc++-v3/include/bits/basic_ios.h | 5 +- libstdc++-v3/include/bits/istream.tcc | 98 ++++++++++++++-------- libstdc++-v3/include/bits/ostream.tcc | 39 ++++++--- .../testsuite/27_io/basic_ios/exceptions/char/2.cc | 59 +++++++++++++ libstdc++-v3/testsuite/testsuite_io.h | 9 +- 6 files changed, 168 insertions(+), 52 deletions(-) create mode 100644 libstdc++-v3/testsuite/27_io/basic_ios/exceptions/char/2.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 7b3acab..080f55a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,15 @@ 2003-12-01 Benjamin Kosnik + * 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 + * docs/html/17_intro/C++STYLE: Add exception bits. * include/bits/fstream.tcc: Add location info to exception strings. diff --git a/libstdc++-v3/include/bits/basic_ios.h b/libstdc++-v3/include/bits/basic_ios.h index 5ada6da..a9cb8d2 100644 --- a/libstdc++-v3/include/bits/basic_ios.h +++ b/libstdc++-v3/include/bits/basic_ios.h @@ -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 diff --git a/libstdc++-v3/include/bits/istream.tcc b/libstdc++-v3/include/bits/istream.tcc index 0d85cc1..abe7950 100644 --- a/libstdc++-v3/include/bits/istream.tcc +++ b/libstdc++-v3/include/bits/istream.tcc @@ -77,8 +77,8 @@ namespace std { _M_ok = false; __err |= ios_base::failbit; + __in.setstate(__err); } - __in.setstate(__err); } template @@ -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; } diff --git a/libstdc++-v3/include/bits/ostream.tcc b/libstdc++-v3/include/bits/ostream.tcc index c7da8c6..c8f7fc7 100644 --- a/libstdc++-v3/include/bits/ostream.tcc +++ b/libstdc++-v3/include/bits/ostream.tcc @@ -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 index 0000000..b9f938e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ios/exceptions/char/2.cc @@ -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 +#include + +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; +} diff --git a/libstdc++-v3/testsuite/testsuite_io.h b/libstdc++-v3/testsuite/testsuite_io.h index 294f427..e5e342e 100644 --- a/libstdc++-v3/testsuite/testsuite_io.h +++ b/libstdc++-v3/testsuite/testsuite_io.h @@ -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() -- 2.7.4