Commit 6b98580b by Benjamin Kosnik Committed by Benjamin Kosnik

basic_ios.h (basic_ios::setstate): Revert.


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
parent b3538cf2
2003-12-01 Benjamin Kosnik <bkoz@redhat.com> 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. * docs/html/17_intro/C++STYLE: Add exception bits.
* include/bits/fstream.tcc: Add location info to exception strings. * include/bits/fstream.tcc: Add location info to exception strings.
......
...@@ -141,10 +141,7 @@ namespace std ...@@ -141,10 +141,7 @@ namespace std
*/ */
void void
setstate(iostate __state) setstate(iostate __state)
{ { this->clear(this->rdstate() | __state); }
if (__state != ios_base::goodbit)
this->clear(this->rdstate() | __state);
}
// Flip the internal state on for the proper state bits, then re // Flip the internal state on for the proper state bits, then re
// throws the propagated exception if bit also set in // throws the propagated exception if bit also set in
......
...@@ -77,8 +77,8 @@ namespace std ...@@ -77,8 +77,8 @@ namespace std
{ {
_M_ok = false; _M_ok = false;
__err |= ios_base::failbit; __err |= ios_base::failbit;
__in.setstate(__err);
} }
__in.setstate(__err);
} }
template<typename _CharT, typename _Traits> template<typename _CharT, typename _Traits>
...@@ -121,7 +121,8 @@ namespace std ...@@ -121,7 +121,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -151,7 +152,8 @@ namespace std ...@@ -151,7 +152,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -172,7 +174,8 @@ namespace std ...@@ -172,7 +174,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -202,7 +205,8 @@ namespace std ...@@ -202,7 +205,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -223,7 +227,8 @@ namespace std ...@@ -223,7 +227,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -244,7 +249,8 @@ namespace std ...@@ -244,7 +249,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -265,7 +271,8 @@ namespace std ...@@ -265,7 +271,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -287,7 +294,8 @@ namespace std ...@@ -287,7 +294,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -308,7 +316,8 @@ namespace std ...@@ -308,7 +316,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -330,7 +339,8 @@ namespace std ...@@ -330,7 +339,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -351,7 +361,8 @@ namespace std ...@@ -351,7 +361,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -372,7 +383,8 @@ namespace std ...@@ -372,7 +383,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -393,7 +405,8 @@ namespace std ...@@ -393,7 +405,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -417,7 +430,8 @@ namespace std ...@@ -417,7 +430,8 @@ namespace std
} }
else if (!__sbout) else if (!__sbout)
__err |= ios_base::failbit; __err |= ios_base::failbit;
this->setstate(__err); if (__err)
this->setstate(__err);
return *this; return *this;
} }
...@@ -447,7 +461,8 @@ namespace std ...@@ -447,7 +461,8 @@ namespace std
} }
if (!_M_gcount) if (!_M_gcount)
__err |= ios_base::failbit; __err |= ios_base::failbit;
this->setstate(__err); if (__err)
this->setstate(__err);
return __c; return __c;
} }
...@@ -478,7 +493,8 @@ namespace std ...@@ -478,7 +493,8 @@ namespace std
} }
if (!_M_gcount) if (!_M_gcount)
__err |= ios_base::failbit; __err |= ios_base::failbit;
this->setstate(__err); if (__err)
this->setstate(__err);
return *this; return *this;
} }
...@@ -516,7 +532,8 @@ namespace std ...@@ -516,7 +532,8 @@ namespace std
*__s = char_type(); *__s = char_type();
if (!_M_gcount) if (!_M_gcount)
__err |= ios_base::failbit; __err |= ios_base::failbit;
this->setstate(__err); if (__err)
this->setstate(__err);
return *this; return *this;
} }
...@@ -554,7 +571,8 @@ namespace std ...@@ -554,7 +571,8 @@ namespace std
} }
if (!_M_gcount) if (!_M_gcount)
__err |= ios_base::failbit; __err |= ios_base::failbit;
this->setstate(__err); if (__err)
this->setstate(__err);
return *this; return *this;
} }
...@@ -602,7 +620,8 @@ namespace std ...@@ -602,7 +620,8 @@ namespace std
*__s = char_type(); *__s = char_type();
if (!_M_gcount) if (!_M_gcount)
__err |= ios_base::failbit; __err |= ios_base::failbit;
this->setstate(__err); if (__err)
this->setstate(__err);
return *this; return *this;
} }
...@@ -635,7 +654,8 @@ namespace std ...@@ -635,7 +654,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -659,7 +679,8 @@ namespace std ...@@ -659,7 +679,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return __c; return __c;
} }
...@@ -682,7 +703,8 @@ namespace std ...@@ -682,7 +703,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -712,7 +734,8 @@ namespace std ...@@ -712,7 +734,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return _M_gcount; return _M_gcount;
} }
...@@ -739,7 +762,8 @@ namespace std ...@@ -739,7 +762,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -766,7 +790,8 @@ namespace std ...@@ -766,7 +790,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -796,7 +821,8 @@ namespace std ...@@ -796,7 +821,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return __ret; return __ret;
} }
...@@ -841,7 +867,8 @@ namespace std ...@@ -841,7 +867,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
return *this; return *this;
} }
...@@ -868,7 +895,8 @@ namespace std ...@@ -868,7 +895,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
return *this; return *this;
} }
...@@ -892,7 +920,8 @@ namespace std ...@@ -892,7 +920,8 @@ namespace std
} }
catch(...) catch(...)
{ __in._M_setstate(ios_base::badbit); } { __in._M_setstate(ios_base::badbit); }
__in.setstate(__err); if (__err)
__in.setstate(__err);
} }
return __in; return __in;
} }
...@@ -947,7 +976,8 @@ namespace std ...@@ -947,7 +976,8 @@ namespace std
} }
if (!__extracted) if (!__extracted)
__err |= ios_base::failbit; __err |= ios_base::failbit;
__in.setstate(__err); if (__err)
__in.setstate(__err);
return __in; return __in;
} }
...@@ -1028,7 +1058,8 @@ namespace std ...@@ -1028,7 +1058,8 @@ namespace std
// 211. operator>>(istream&, string&) doesn't set failbit // 211. operator>>(istream&, string&) doesn't set failbit
if (!__extracted) if (!__extracted)
__err |= ios_base::failbit; __err |= ios_base::failbit;
__in.setstate(__err); if (__err)
__in.setstate(__err);
return __in; return __in;
} }
...@@ -1081,7 +1112,8 @@ namespace std ...@@ -1081,7 +1112,8 @@ namespace std
} }
if ((!__extracted && !__testdelim) || __extracted == __n) if ((!__extracted && !__testdelim) || __extracted == __n)
__err |= ios_base::failbit; __err |= ios_base::failbit;
__in.setstate(__err); if (__err)
__in.setstate(__err);
return __in; return __in;
} }
......
...@@ -111,7 +111,8 @@ namespace std ...@@ -111,7 +111,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -143,7 +144,8 @@ namespace std ...@@ -143,7 +144,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -165,7 +167,8 @@ namespace std ...@@ -165,7 +167,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -199,7 +202,8 @@ namespace std ...@@ -199,7 +202,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -221,7 +225,8 @@ namespace std ...@@ -221,7 +225,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -244,7 +249,8 @@ namespace std ...@@ -244,7 +249,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -266,7 +272,8 @@ namespace std ...@@ -266,7 +272,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -288,7 +295,8 @@ namespace std ...@@ -288,7 +295,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -312,7 +320,8 @@ namespace std ...@@ -312,7 +320,8 @@ namespace std
} }
else if (!__sbin) else if (!__sbin)
__err |= ios_base::badbit; __err |= ios_base::badbit;
this->setstate(__err); if (__err)
this->setstate(__err);
return *this; return *this;
} }
...@@ -339,7 +348,8 @@ namespace std ...@@ -339,7 +348,8 @@ namespace std
} }
catch (...) catch (...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
} }
return *this; return *this;
} }
...@@ -383,7 +393,8 @@ namespace std ...@@ -383,7 +393,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
return *this; return *this;
} }
...@@ -424,7 +435,8 @@ namespace std ...@@ -424,7 +435,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
return *this; return *this;
} }
...@@ -450,7 +462,8 @@ namespace std ...@@ -450,7 +462,8 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
this->setstate(__err); if (__err)
this->setstate(__err);
return *this; return *this;
} }
......
// 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;
}
...@@ -104,10 +104,15 @@ namespace __gnu_test ...@@ -104,10 +104,15 @@ namespace __gnu_test
struct fail_streambuf : std::streambuf struct fail_streambuf : std::streambuf
{ {
private:
char p[2];
public:
fail_streambuf() fail_streambuf()
{ {
static char p[] = "s"; p[0] = 's';
setg(p, p, p + 1); p[1] = char();
setg(p, p, p + 1);
} }
virtual int_type underflow() virtual int_type underflow()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment