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,9 +77,9 @@ namespace std ...@@ -77,9 +77,9 @@ 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>
basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>&
...@@ -121,6 +121,7 @@ namespace std ...@@ -121,6 +121,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -151,6 +152,7 @@ namespace std ...@@ -151,6 +152,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -172,6 +174,7 @@ namespace std ...@@ -172,6 +174,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -202,6 +205,7 @@ namespace std ...@@ -202,6 +205,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -223,6 +227,7 @@ namespace std ...@@ -223,6 +227,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -244,6 +249,7 @@ namespace std ...@@ -244,6 +249,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -265,6 +271,7 @@ namespace std ...@@ -265,6 +271,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -287,6 +294,7 @@ namespace std ...@@ -287,6 +294,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -308,6 +316,7 @@ namespace std ...@@ -308,6 +316,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -330,6 +339,7 @@ namespace std ...@@ -330,6 +339,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -351,6 +361,7 @@ namespace std ...@@ -351,6 +361,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -372,6 +383,7 @@ namespace std ...@@ -372,6 +383,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -393,6 +405,7 @@ namespace std ...@@ -393,6 +405,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -417,6 +430,7 @@ namespace std ...@@ -417,6 +430,7 @@ namespace std
} }
else if (!__sbout) else if (!__sbout)
__err |= ios_base::failbit; __err |= ios_base::failbit;
if (__err)
this->setstate(__err); this->setstate(__err);
return *this; return *this;
} }
...@@ -447,6 +461,7 @@ namespace std ...@@ -447,6 +461,7 @@ namespace std
} }
if (!_M_gcount) if (!_M_gcount)
__err |= ios_base::failbit; __err |= ios_base::failbit;
if (__err)
this->setstate(__err); this->setstate(__err);
return __c; return __c;
} }
...@@ -478,6 +493,7 @@ namespace std ...@@ -478,6 +493,7 @@ namespace std
} }
if (!_M_gcount) if (!_M_gcount)
__err |= ios_base::failbit; __err |= ios_base::failbit;
if (__err)
this->setstate(__err); this->setstate(__err);
return *this; return *this;
} }
...@@ -516,6 +532,7 @@ namespace std ...@@ -516,6 +532,7 @@ namespace std
*__s = char_type(); *__s = char_type();
if (!_M_gcount) if (!_M_gcount)
__err |= ios_base::failbit; __err |= ios_base::failbit;
if (__err)
this->setstate(__err); this->setstate(__err);
return *this; return *this;
} }
...@@ -554,6 +571,7 @@ namespace std ...@@ -554,6 +571,7 @@ namespace std
} }
if (!_M_gcount) if (!_M_gcount)
__err |= ios_base::failbit; __err |= ios_base::failbit;
if (__err)
this->setstate(__err); this->setstate(__err);
return *this; return *this;
} }
...@@ -602,6 +620,7 @@ namespace std ...@@ -602,6 +620,7 @@ namespace std
*__s = char_type(); *__s = char_type();
if (!_M_gcount) if (!_M_gcount)
__err |= ios_base::failbit; __err |= ios_base::failbit;
if (__err)
this->setstate(__err); this->setstate(__err);
return *this; return *this;
} }
...@@ -635,6 +654,7 @@ namespace std ...@@ -635,6 +654,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -659,6 +679,7 @@ namespace std ...@@ -659,6 +679,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return __c; return __c;
...@@ -682,6 +703,7 @@ namespace std ...@@ -682,6 +703,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -712,6 +734,7 @@ namespace std ...@@ -712,6 +734,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return _M_gcount; return _M_gcount;
...@@ -739,6 +762,7 @@ namespace std ...@@ -739,6 +762,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -766,6 +790,7 @@ namespace std ...@@ -766,6 +790,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -796,6 +821,7 @@ namespace std ...@@ -796,6 +821,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return __ret; return __ret;
...@@ -841,6 +867,7 @@ namespace std ...@@ -841,6 +867,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
return *this; return *this;
} }
...@@ -868,6 +895,7 @@ namespace std ...@@ -868,6 +895,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
return *this; return *this;
} }
...@@ -892,6 +920,7 @@ namespace std ...@@ -892,6 +920,7 @@ namespace std
} }
catch(...) catch(...)
{ __in._M_setstate(ios_base::badbit); } { __in._M_setstate(ios_base::badbit); }
if (__err)
__in.setstate(__err); __in.setstate(__err);
} }
return __in; return __in;
...@@ -947,6 +976,7 @@ namespace std ...@@ -947,6 +976,7 @@ namespace std
} }
if (!__extracted) if (!__extracted)
__err |= ios_base::failbit; __err |= ios_base::failbit;
if (__err)
__in.setstate(__err); __in.setstate(__err);
return __in; return __in;
} }
...@@ -1028,6 +1058,7 @@ namespace std ...@@ -1028,6 +1058,7 @@ 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;
if (__err)
__in.setstate(__err); __in.setstate(__err);
return __in; return __in;
} }
...@@ -1081,6 +1112,7 @@ namespace std ...@@ -1081,6 +1112,7 @@ namespace std
} }
if ((!__extracted && !__testdelim) || __extracted == __n) if ((!__extracted && !__testdelim) || __extracted == __n)
__err |= ios_base::failbit; __err |= ios_base::failbit;
if (__err)
__in.setstate(__err); __in.setstate(__err);
return __in; return __in;
} }
......
...@@ -111,6 +111,7 @@ namespace std ...@@ -111,6 +111,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -143,6 +144,7 @@ namespace std ...@@ -143,6 +144,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -165,6 +167,7 @@ namespace std ...@@ -165,6 +167,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -199,6 +202,7 @@ namespace std ...@@ -199,6 +202,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -221,6 +225,7 @@ namespace std ...@@ -221,6 +225,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -244,6 +249,7 @@ namespace std ...@@ -244,6 +249,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -266,6 +272,7 @@ namespace std ...@@ -266,6 +272,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -288,6 +295,7 @@ namespace std ...@@ -288,6 +295,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -312,6 +320,7 @@ namespace std ...@@ -312,6 +320,7 @@ namespace std
} }
else if (!__sbin) else if (!__sbin)
__err |= ios_base::badbit; __err |= ios_base::badbit;
if (__err)
this->setstate(__err); this->setstate(__err);
return *this; return *this;
} }
...@@ -339,6 +348,7 @@ namespace std ...@@ -339,6 +348,7 @@ namespace std
} }
catch (...) catch (...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
} }
return *this; return *this;
...@@ -383,6 +393,7 @@ namespace std ...@@ -383,6 +393,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
return *this; return *this;
} }
...@@ -424,6 +435,7 @@ namespace std ...@@ -424,6 +435,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err); this->setstate(__err);
return *this; return *this;
} }
...@@ -450,6 +462,7 @@ namespace std ...@@ -450,6 +462,7 @@ namespace std
} }
catch(...) catch(...)
{ this->_M_setstate(ios_base::badbit); } { this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__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,9 +104,14 @@ namespace __gnu_test ...@@ -104,9 +104,14 @@ 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';
p[1] = char();
setg(p, p, p + 1); setg(p, p, p + 1);
} }
......
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