aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include
diff options
context:
space:
mode:
authorBenjamin Kosnik <bkoz@redhat.com>2003-11-27 08:14:25 +0000
committerBenjamin Kosnik <bkoz@gcc.gnu.org>2003-11-27 08:14:25 +0000
commit12841eb3d032e926775f49834b8941f57a047baf (patch)
tree27f6d0d3d427d9db5da892e2b7f7f741d945f41a /libstdc++-v3/include
parentb483cfb7a714d1d4ca0868241f69b31d44c51e55 (diff)
downloadgcc-12841eb3d032e926775f49834b8941f57a047baf.zip
gcc-12841eb3d032e926775f49834b8941f57a047baf.tar.gz
gcc-12841eb3d032e926775f49834b8941f57a047baf.tar.bz2
re PR libstdc++/9371 (Bad exception handling in i/ostream::operator>>/<<(streambuf*))
2003-11-26 Benjamin Kosnik <bkoz@redhat.com> PR libstdc++/9371 PR libstdc++/9546 PR libstdc++/10093 PR libstdc++/10095 * include/bits/basic_ios.h (basic_ios::setstate): Elide if goodbit. (basic_ios::_M_setstate): Consolidate common error handling code. * include/bits/basic_ios.tcc: Tweak. * include/bits/fstream.tcc: Tweak. * include/bits/istream.tcc: Use _M_setstate for common exception handling. Move setstate calls after catch. (basic_istream::tellg): Check for exceptions thrown by streambuf virtual functions. (basic_istream::seekg): Same. * include/bits/ostream.tcc: Same, but for ostream. (basic_ostream::flush): Check for exceptions thrown by streambuf virtual functions. (basic_istream::tellp): Same. (basic_istream::seekp): Same. * include/bits/locale_facets.tcc: Tweak. * include/bits/streambuf.tcc: Tweak. (__copy_streambufs): Propagate exceptions. * testsuite/testsuite_io.h (fail_streambuf): New. (fail_num_get): New. (fail_num_put): New. (facet_error): New. (underflow_error): New. (overflow_error): New. (positioning_error): New. * testsuite/27_io/basic_istream/exceptions/char/9561.cc: Tweak. * testsuite/27_io/basic_istream/extractors_arithmetic/char/ exceptions_badbit_throw.cc, exceptions_failbit.cc, exceptions_failbit_throw.cc: New. * testsuite/27_io/basic_istream/extractors_other/char/ error_failbit.cc, exceptions_badbit_throw.cc, exceptions_failbit_throw.cc, exceptions_null.cc: New. * testsuite/27_io/basic_istream/seekg/char/exceptions_badbit_throw.cc: New. * testsuite/27_io/basic_istream/tellg/char/exceptions_badbit_throw.cc: New. * testsuite/27_io/basic_ostream/flush/char/exceptions_badbit_throw.cc: New. * testsuite/27_io/basic_ostream/inserters_arithmetic/char/ exceptions_badbit_throw.cc, exceptions_failbit_throw.cc: New. * testsuite/27_io/basic_ostream/inserters_other/char/ error_failbit.cc, exceptions_badbit_throw.cc, exceptions_failbit_throw.cc, exceptions_null.cc: New. * testsuite/27_io/basic_ostream/seekp/char/exceptions_badbit_throw.cc: New. * testsuite/27_io/basic_ostream/tellp/char/exceptions_badbit_throw.cc: New. From-SVN: r73979
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r--libstdc++-v3/include/bits/basic_ios.h23
-rw-r--r--libstdc++-v3/include/bits/basic_ios.tcc2
-rw-r--r--libstdc++-v3/include/bits/fstream.tcc4
-rw-r--r--libstdc++-v3/include/bits/istream.tcc484
-rw-r--r--libstdc++-v3/include/bits/locale_facets.tcc2
-rw-r--r--libstdc++-v3/include/bits/ostream.tcc310
-rw-r--r--libstdc++-v3/include/bits/streambuf.tcc11
7 files changed, 343 insertions, 493 deletions
diff --git a/libstdc++-v3/include/bits/basic_ios.h b/libstdc++-v3/include/bits/basic_ios.h
index 7e5b605..5ada6da 100644
--- a/libstdc++-v3/include/bits/basic_ios.h
+++ b/libstdc++-v3/include/bits/basic_ios.h
@@ -141,7 +141,23 @@ namespace std
*/
void
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
+ // throws the propagated exception if bit also set in
+ // exceptions().
+ void
+ _M_setstate(iostate __state)
+ {
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ _M_streambuf_state |= __state;
+ if (this->exceptions() & __state)
+ __throw_exception_again;
+ }
/**
* @brief Fast error checking.
@@ -441,11 +457,6 @@ namespace std
void
_M_cache_locale(const locale& __loc);
-
- // 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 --git a/libstdc++-v3/include/bits/basic_ios.tcc b/libstdc++-v3/include/bits/basic_ios.tcc
index 45cc894..6f690e0 100644
--- a/libstdc++-v3/include/bits/basic_ios.tcc
+++ b/libstdc++-v3/include/bits/basic_ios.tcc
@@ -42,7 +42,7 @@ namespace std
_M_streambuf_state = __state;
else
_M_streambuf_state = __state | badbit;
- if ((this->rdstate() & this->exceptions()))
+ if (this->exceptions() & this->rdstate())
__throw_ios_failure("basic_ios::clear");
}
diff --git a/libstdc++-v3/include/bits/fstream.tcc b/libstdc++-v3/include/bits/fstream.tcc
index aee725e..b15ad7d 100644
--- a/libstdc++-v3/include/bits/fstream.tcc
+++ b/libstdc++-v3/include/bits/fstream.tcc
@@ -134,9 +134,7 @@ namespace std
__testfail = true;
}
catch(...)
- {
- __testfail = true;
- }
+ { __testfail = true; }
// NB: Do this here so that re-opened filebufs will be cool...
this->_M_mode = ios_base::openmode(0);
diff --git a/libstdc++-v3/include/bits/istream.tcc b/libstdc++-v3/include/bits/istream.tcc
index d710f0c..4055ca7 100644
--- a/libstdc++-v3/include/bits/istream.tcc
+++ b/libstdc++-v3/include/bits/istream.tcc
@@ -61,7 +61,7 @@ namespace std
while (!traits_type::eq_int_type(__c, __eof)
&& __ct.is(ctype_base::space,
traits_type::to_char_type(__c)))
- __c = __sb->snextc();
+ __c = __sb->snextc();
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 195. Should basic_istream::sentry's constructor ever
@@ -85,10 +85,7 @@ namespace std
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::
operator>>(__istream_type& (*__pf)(__istream_type&))
- {
- __pf(*this);
- return *this;
- }
+ { return __pf(*this); }
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
@@ -116,21 +113,15 @@ namespace std
sentry __cerb(*this, false);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
const __num_get_type& __ng = __check_facet(this->_M_num_get);
__ng.get(*this, 0, *this, __err, __n);
- this->setstate(__err);
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
@@ -143,10 +134,10 @@ namespace std
sentry __cerb(*this, false);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
long __l;
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
const __num_get_type& __ng = __check_facet(this->_M_num_get);
__ng.get(*this, 0, *this, __err, __l);
// _GLIBCXX_RESOLVE_LIB_DEFECTS
@@ -157,16 +148,10 @@ namespace std
__n = __l;
else
__err |= ios_base::failbit;
- this->setstate(__err);
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
@@ -179,21 +164,15 @@ namespace std
sentry __cerb(*this, false);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
const __num_get_type& __ng = __check_facet(this->_M_num_get);
__ng.get(*this, 0, *this, __err, __n);
- this->setstate(__err);
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
@@ -206,10 +185,10 @@ namespace std
sentry __cerb(*this, false);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
long __l;
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
const __num_get_type& __ng = __check_facet(this->_M_num_get);
__ng.get(*this, 0, *this, __err, __l);
// _GLIBCXX_RESOLVE_LIB_DEFECTS
@@ -220,16 +199,10 @@ namespace std
__n = __l;
else
__err |= ios_base::failbit;
- this->setstate(__err);
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
@@ -242,21 +215,15 @@ namespace std
sentry __cerb(*this, false);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
const __num_get_type& __ng = __check_facet(this->_M_num_get);
__ng.get(*this, 0, *this, __err, __n);
- this->setstate(__err);
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
@@ -269,21 +236,15 @@ namespace std
sentry __cerb(*this, false);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
const __num_get_type& __ng = __check_facet(this->_M_num_get);
__ng.get(*this, 0, *this, __err, __n);
- this->setstate(__err);
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
@@ -296,21 +257,15 @@ namespace std
sentry __cerb(*this, false);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
const __num_get_type& __ng = __check_facet(this->_M_num_get);
__ng.get(*this, 0, *this, __err, __n);
- this->setstate(__err);
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
@@ -324,21 +279,15 @@ namespace std
sentry __cerb(*this, false);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
const __num_get_type& __ng = __check_facet(this->_M_num_get);
__ng.get(*this, 0, *this, __err, __n);
- this->setstate(__err);
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
@@ -351,21 +300,15 @@ namespace std
sentry __cerb(*this, false);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
const __num_get_type& __ng = __check_facet(this->_M_num_get);
__ng.get(*this, 0, *this, __err, __n);
- this->setstate(__err);
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
@@ -379,21 +322,15 @@ namespace std
sentry __cerb(*this, false);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
const __num_get_type& __ng = __check_facet(this->_M_num_get);
__ng.get(*this, 0, *this, __err, __n);
- this->setstate(__err);
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
@@ -406,21 +343,15 @@ namespace std
sentry __cerb(*this, false);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
const __num_get_type& __ng = __check_facet(this->_M_num_get);
__ng.get(*this, 0, *this, __err, __n);
- this->setstate(__err);
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
@@ -433,21 +364,15 @@ namespace std
sentry __cerb(*this, false);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
const __num_get_type& __ng = __check_facet(this->_M_num_get);
__ng.get(*this, 0, *this, __err, __n);
- this->setstate(__err);
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
@@ -460,21 +385,15 @@ namespace std
sentry __cerb(*this, false);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
- ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
const __num_get_type& __ng = __check_facet(this->_M_num_get);
__ng.get(*this, 0, *this, __err, __n);
- this->setstate(__err);
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
@@ -484,30 +403,22 @@ namespace std
basic_istream<_CharT, _Traits>::
operator>>(__streambuf_type* __sbout)
{
- sentry __cerb(*this, false);
- if (__cerb)
- {
- try
- {
- streamsize __xtrct = 0;
- if (__sbout)
- {
- __streambuf_type* __sbin = this->rdbuf();
- __xtrct = __copy_streambufs(*this, __sbin, __sbout);
- }
- if (!__sbout || !__xtrct)
- this->setstate(ios_base::failbit);
- }
- catch(...)
- {
- // 27.6.2.5.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
- }
- return *this;
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ sentry __cerb(*this, false);
+ if (__cerb && __sbout)
+ {
+ try
+ {
+ if (!__copy_streambufs(*this, this->rdbuf(), __sbout))
+ __err |= ios_base::failbit;
+ }
+ catch(...)
+ { this->_M_setstate(ios_base::failbit); }
+ }
+ else if (!__sbout)
+ __err |= ios_base::failbit;
+ this->setstate(__err);
+ return *this;
}
template<typename _CharT, typename _Traits>
@@ -518,6 +429,7 @@ namespace std
const int_type __eof = traits_type::eof();
int_type __c = __eof;
_M_gcount = 0;
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
sentry __cerb(*this, true);
if (__cerb)
{
@@ -528,17 +440,14 @@ namespace std
if (!traits_type::eq_int_type(__c, __eof))
_M_gcount = 1;
else
- this->setstate(ios_base::eofbit | ios_base::failbit);
+ __err |= ios_base::eofbit;
}
catch(...)
- {
- // 27.6.1.3 paragraph 1
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
}
+ if (!_M_gcount)
+ __err |= ios_base::failbit;
+ this->setstate(__err);
return __c;
}
@@ -548,31 +457,28 @@ namespace std
get(char_type& __c)
{
_M_gcount = 0;
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
sentry __cerb(*this, true);
if (__cerb)
{
try
{
- const int_type __eof = traits_type::eof();
- int_type __bufval = this->rdbuf()->sbumpc();
+ int_type __cb = this->rdbuf()->sbumpc();
// 27.6.1.1 paragraph 3
- if (!traits_type::eq_int_type(__bufval, __eof))
+ if (!traits_type::eq_int_type(__cb, traits_type::eof()))
{
_M_gcount = 1;
- __c = traits_type::to_char_type(__bufval);
+ __c = traits_type::to_char_type(__cb);
}
else
- this->setstate(ios_base::eofbit | ios_base::failbit);
+ __err |= ios_base::eofbit;
}
catch(...)
- {
- // 27.6.1.3 paragraph 1
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
}
+ if (!_M_gcount)
+ __err |= ios_base::failbit;
+ this->setstate(__err);
return *this;
}
@@ -582,6 +488,7 @@ namespace std
get(char_type* __s, streamsize __n, char_type __delim)
{
_M_gcount = 0;
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
sentry __cerb(*this, true);
if (__cerb)
{
@@ -601,20 +508,15 @@ namespace std
++_M_gcount;
}
if (traits_type::eq_int_type(__c, __eof))
- this->setstate(ios_base::eofbit);
+ __err |= ios_base::eofbit;
}
catch(...)
- {
- // 27.6.1.3 paragraph 1
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
}
*__s = char_type();
if (!_M_gcount)
- this->setstate(ios_base::failbit);
+ __err |= ios_base::failbit;
+ this->setstate(__err);
return *this;
}
@@ -624,6 +526,7 @@ namespace std
get(__streambuf_type& __sb, char_type __delim)
{
_M_gcount = 0;
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
sentry __cerb(*this, true);
if (__cerb)
{
@@ -644,19 +547,14 @@ namespace std
__c2 = traits_type::to_char_type(__c);
}
if (traits_type::eq_int_type(__c, __eof))
- this->setstate(ios_base::eofbit);
+ __err |= ios_base::eofbit;
}
catch(...)
- {
- // 27.6.1.3 paragraph 1
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
}
if (!_M_gcount)
- this->setstate(ios_base::failbit);
+ __err |= ios_base::failbit;
+ this->setstate(__err);
return *this;
}
@@ -666,6 +564,7 @@ namespace std
getline(char_type* __s, streamsize __n, char_type __delim)
{
_M_gcount = 0;
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
sentry __cerb(*this, true);
if (__cerb)
{
@@ -685,7 +584,7 @@ namespace std
++_M_gcount;
}
if (traits_type::eq_int_type(__c, __eof))
- this->setstate(ios_base::eofbit);
+ __err |= ios_base::eofbit;
else
{
if (traits_type::eq_int_type(__c, __idelim))
@@ -694,21 +593,16 @@ namespace std
++_M_gcount;
}
else
- this->setstate(ios_base::failbit);
+ __err |= ios_base::failbit;
}
}
catch(...)
- {
- // 27.6.1.3 paragraph 1
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
}
*__s = char_type();
if (!_M_gcount)
- this->setstate(ios_base::failbit);
+ __err |= ios_base::failbit;
+ this->setstate(__err);
return *this;
}
@@ -721,6 +615,7 @@ namespace std
sentry __cerb(*this, true);
if (__cerb && __n > 0)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
const int_type __eof = traits_type::eof();
@@ -736,16 +631,11 @@ namespace std
break;
}
if (traits_type::eq_int_type(__c, __eof))
- this->setstate(ios_base::eofbit);
+ __err |= ios_base::eofbit;
}
catch(...)
- {
- // 27.6.1.3 paragraph 1
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
@@ -760,20 +650,16 @@ namespace std
sentry __cerb(*this, true);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
__c = this->rdbuf()->sgetc();
if (traits_type::eq_int_type(__c, traits_type::eof()))
- this->setstate(ios_base::eofbit);
+ __err |= ios_base::eofbit;
}
catch(...)
- {
- // 27.6.1.3 paragraph 1
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return __c;
}
@@ -787,20 +673,16 @@ namespace std
sentry __cerb(*this, true);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
_M_gcount = this->rdbuf()->sgetn(__s, __n);
if (_M_gcount != __n)
- this->setstate(ios_base::eofbit | ios_base::failbit);
+ __err |= (ios_base::eofbit | ios_base::failbit);
}
catch(...)
- {
- // 27.6.1.3 paragraph 1
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
@@ -814,6 +696,7 @@ namespace std
sentry __cerb(*this, true);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
// Cannot compare int_type with streamsize generically.
@@ -825,16 +708,11 @@ namespace std
_M_gcount = this->rdbuf()->sgetn(__s, __num);
}
else
- this->setstate(ios_base::eofbit);
+ __err |= ios_base::eofbit;
}
catch(...)
- {
- // 27.6.1.3 paragraph 1
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return _M_gcount;
}
@@ -850,22 +728,18 @@ namespace std
sentry __cerb(*this, true);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
const int_type __eof = traits_type::eof();
__streambuf_type* __sb = this->rdbuf();
if (!__sb
|| traits_type::eq_int_type(__sb->sputbackc(__c), __eof))
- this->setstate(ios_base::badbit);
+ __err |= ios_base::badbit;
}
catch(...)
- {
- // 27.6.1.3 paragraph 1
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
@@ -881,22 +755,18 @@ namespace std
sentry __cerb(*this, true);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
const int_type __eof = traits_type::eof();
__streambuf_type* __sb = this->rdbuf();
if (!__sb
|| traits_type::eq_int_type(__sb->sungetc(), __eof))
- this->setstate(ios_base::badbit);
+ __err |= ios_base::badbit;
}
catch(...)
- {
- // 27.6.1.3 paragraph 1
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
@@ -906,30 +776,27 @@ namespace std
basic_istream<_CharT, _Traits>::
sync(void)
{
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR60. Do not change _M_gcount.
int __ret = -1;
sentry __cerb(*this, true);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
__streambuf_type* __sb = this->rdbuf();
if (__sb)
{
if (__sb->pubsync() == -1)
- this->setstate(ios_base::badbit);
+ __err |= ios_base::badbit;
else
__ret = 0;
}
}
catch(...)
- {
- // 27.6.1.3 paragraph 1
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return __ret;
}
@@ -939,30 +806,42 @@ namespace std
basic_istream<_CharT, _Traits>::
tellg(void)
{
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR60. Do not change _M_gcount.
pos_type __ret = pos_type(-1);
- if (!this->fail())
- __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
+ try
+ {
+ if (!this->fail())
+ __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
+ }
+ catch(...)
+ { this->_M_setstate(ios_base::badbit); }
return __ret;
}
-
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::
seekg(pos_type __pos)
{
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR60. Do not change _M_gcount.
- if (!this->fail())
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ try
{
- // _GLIBCXX_RESOLVE_LIB_DEFECTS
- // 136. seekp, seekg setting wrong streams?
- pos_type __err = this->rdbuf()->pubseekpos(__pos, ios_base::in);
+ if (!this->fail())
+ {
+ // 136. seekp, seekg setting wrong streams?
+ pos_type __p = this->rdbuf()->pubseekpos(__pos, ios_base::in);
- // 129. Need error indication from seekp() and seekg()
- if (__err == pos_type(off_type(-1)))
- this->setstate(ios_base::failbit);
+ // 129. Need error indication from seekp() and seekg()
+ if (__p == pos_type(off_type(-1)))
+ __err |= ios_base::failbit;
+ }
}
+ catch(...)
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
return *this;
}
@@ -971,18 +850,25 @@ namespace std
basic_istream<_CharT, _Traits>::
seekg(off_type __off, ios_base::seekdir __dir)
{
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR60. Do not change _M_gcount.
- if (!this->fail())
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ try
{
- // _GLIBCXX_RESOLVE_LIB_DEFECTS
- // 136. seekp, seekg setting wrong streams?
- pos_type __err = this->rdbuf()->pubseekoff(__off, __dir,
- ios_base::in);
-
- // 129. Need error indication from seekp() and seekg()
- if (__err == pos_type(off_type(-1)))
- this->setstate(ios_base::failbit);
+ if (!this->fail())
+ {
+ // 136. seekp, seekg setting wrong streams?
+ pos_type __p = this->rdbuf()->pubseekoff(__off, __dir,
+ ios_base::in);
+
+ // 129. Need error indication from seekp() and seekg()
+ if (__p == pos_type(off_type(-1)))
+ __err |= ios_base::failbit;
+ }
}
+ catch(...)
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
return *this;
}
@@ -995,16 +881,18 @@ namespace std
typename __istream_type::sentry __cerb(__in, false);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
- { __in.get(__c); }
- catch(...)
{
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- __in._M_setstate(ios_base::badbit);
- if ((__in.exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
+ typename __istream_type::int_type __cb = __in.rdbuf()->sbumpc();
+ if (!_Traits::eq_int_type(__cb, _Traits::eof()))
+ __c = _Traits::to_char_type(__cb);
+ else
+ __err |= (ios_base::eofbit | ios_base::failbit);
}
+ catch(...)
+ { __in._M_setstate(ios_base::badbit); }
+ __in.setstate(__err);
}
return __in;
}
@@ -1018,8 +906,9 @@ namespace std
typedef typename _Traits::int_type int_type;
typedef _CharT char_type;
typedef ctype<_CharT> __ctype_type;
- streamsize __extracted = 0;
+ streamsize __extracted = 0;
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
typename __istream_type::sentry __cerb(__in, false);
if (__cerb)
{
@@ -1046,7 +935,7 @@ namespace std
__c = __sb->snextc();
}
if (_Traits::eq_int_type(__c, __eof))
- __in.setstate(ios_base::eofbit);
+ __err |= ios_base::eofbit;
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 68. Extractors for char* should store null at end
@@ -1054,16 +943,11 @@ namespace std
__in.width(0);
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- __in._M_setstate(ios_base::badbit);
- if ((__in.exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { __in._M_setstate(ios_base::badbit); }
}
if (!__extracted)
- __in.setstate(ios_base::failbit);
+ __err |= ios_base::failbit;
+ __in.setstate(__err);
return __in;
}
@@ -1087,8 +971,7 @@ namespace std
__c = __sb->snextc();
if (_Traits::eq_int_type(__c, __eof))
- __in.setstate(ios_base::eofbit);
-
+ __in.setstate(ios_base::eofbit);
return __in;
}
@@ -1106,6 +989,7 @@ namespace std
typedef typename __string_type::size_type __size_type;
__size_type __extracted = 0;
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
typename __istream_type::sentry __cerb(__in, false);
if (__cerb)
{
@@ -1130,7 +1014,7 @@ namespace std
__c = __sb->snextc();
}
if (_Traits::eq_int_type(__c, __eof))
- __in.setstate(ios_base::eofbit);
+ __err |= ios_base::eofbit;
__in.width(0);
}
catch(...)
@@ -1138,17 +1022,13 @@ namespace std
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 91. Description of operator>> and getline() for string<>
// might cause endless loop
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- __in.setstate(ios_base::badbit);
- if ((__in.exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
+ __in._M_setstate(ios_base::badbit);
}
}
- // _GLIBCXX_RESOLVE_LIB_DEFECTS
// 211. operator>>(istream&, string&) doesn't set failbit
if (!__extracted)
- __in.setstate (ios_base::failbit);
+ __err |= ios_base::failbit;
+ __in.setstate(__err);
return __in;
}
@@ -1167,6 +1047,7 @@ namespace std
__size_type __extracted = 0;
const __size_type __n = __str.max_size();
bool __testdelim = false;
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
typename __istream_type::sentry __cerb(__in, true);
if (__cerb)
{
@@ -1188,22 +1069,19 @@ namespace std
__testdelim = _Traits::eq_int_type(__c, __idelim);
}
if (_Traits::eq_int_type(__c, __eof))
- __in.setstate(ios_base::eofbit);
+ __err |= ios_base::eofbit;
}
catch(...)
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 91. Description of operator>> and getline() for string<>
// might cause endless loop
- // 27.6.1.3 paragraph 1.
- // Turn this on without causing an ios::failure to be thrown.
- __in.setstate(ios_base::badbit);
- if ((__in.exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
+ __in._M_setstate(ios_base::badbit);
}
}
if ((!__extracted && !__testdelim) || __extracted == __n)
- __in.setstate(ios_base::failbit);
+ __err |= ios_base::failbit;
+ __in.setstate(__err);
return __in;
}
diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc
index 5f09924..c2097e3 100644
--- a/libstdc++-v3/include/bits/locale_facets.tcc
+++ b/libstdc++-v3/include/bits/locale_facets.tcc
@@ -627,7 +627,7 @@ namespace std
__io.flags(__fmt);
unsigned long __ul;
- std::__convert_to_v(__xtrc.c_str(), __ul, __err,
+ std::__convert_to_v(__xtrc.c_str(), __ul, __err,
_S_get_c_locale(), __base);
if (!(__err & ios_base::failbit))
__v = reinterpret_cast<void*>(__ul);
diff --git a/libstdc++-v3/include/bits/ostream.tcc b/libstdc++-v3/include/bits/ostream.tcc
index 3235754..fecaa93 100644
--- a/libstdc++-v3/include/bits/ostream.tcc
+++ b/libstdc++-v3/include/bits/ostream.tcc
@@ -43,7 +43,7 @@ namespace std
{
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>::sentry::
- sentry(basic_ostream<_CharT,_Traits>& __os)
+ sentry(basic_ostream<_CharT, _Traits>& __os)
: _M_os(__os)
{
// XXX MT
@@ -96,62 +96,35 @@ namespace std
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(__streambuf_type* __sbin)
- {
- sentry __cerb(*this);
- if (__cerb && __sbin)
- {
- try
- {
- if (!__copy_streambufs(*this, __sbin, this->rdbuf()))
- this->setstate(ios_base::failbit);
- }
- catch(...)
- {
- // 27.6.2.5.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
- }
- else if (!__sbin)
- this->setstate(ios_base::badbit);
- return *this;
- }
-
- template<typename _CharT, typename _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(bool __n)
+ basic_ostream<_CharT, _Traits>::
+ operator<<(bool __n)
{
sentry __cerb(*this);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
const __num_put_type& __np = __check_facet(this->_M_num_put);
if (__np.put(*this, *this, this->fill(), __n).failed())
- this->setstate(ios_base::badbit);
+ __err |= ios_base::badbit;
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(long __n)
+ basic_ostream<_CharT, _Traits>::
+ operator<<(long __n)
{
sentry __cerb(*this);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
bool __b = false;
@@ -166,41 +139,33 @@ namespace std
else
__b = __np.put(*this, *this, __c, __n).failed();
if (__b)
- this->setstate(ios_base::badbit);
+ __err |= ios_base::badbit;
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
+ basic_ostream<_CharT, _Traits>::
+ operator<<(unsigned long __n)
{
sentry __cerb(*this);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
const __num_put_type& __np = __check_facet(this->_M_num_put);
if (__np.put(*this, *this, this->fill(), __n).failed())
- this->setstate(ios_base::badbit);
+ __err |= ios_base::badbit;
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
@@ -208,11 +173,13 @@ namespace std
#ifdef _GLIBCXX_USE_LONG_LONG
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(long long __n)
+ basic_ostream<_CharT, _Traits>::
+ operator<<(long long __n)
{
sentry __cerb(*this);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
bool __b = false;
@@ -228,41 +195,33 @@ namespace std
else
__b = __np.put(*this, *this, __c, __n).failed();
if (__b)
- this->setstate(ios_base::badbit);
+ __err |= ios_base::badbit;
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
+ basic_ostream<_CharT, _Traits>::
+ operator<<(unsigned long long __n)
{
sentry __cerb(*this);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
const __num_put_type& __np = __check_facet(this->_M_num_put);
if (__np.put(*this, *this, this->fill(), __n).failed())
- this->setstate(ios_base::badbit);
+ __err |= ios_base::badbit;
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
@@ -270,82 +229,97 @@ namespace std
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(double __n)
+ basic_ostream<_CharT, _Traits>::
+ operator<<(double __n)
{
sentry __cerb(*this);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
const __num_put_type& __np = __check_facet(this->_M_num_put);
if (__np.put(*this, *this, this->fill(), __n).failed())
- this->setstate(ios_base::badbit);
+ __err |= ios_base::badbit;
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(long double __n)
+ basic_ostream<_CharT, _Traits>::
+ operator<<(long double __n)
{
sentry __cerb(*this);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
const __num_put_type& __np = __check_facet(this->_M_num_put);
if (__np.put(*this, *this, this->fill(), __n).failed())
- this->setstate(ios_base::badbit);
+ __err |= ios_base::badbit;
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
+ basic_ostream<_CharT, _Traits>::
+ operator<<(const void* __n)
{
sentry __cerb(*this);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
const __num_put_type& __np = __check_facet(this->_M_num_put);
if (__np.put(*this, *this, this->fill(), __n).failed())
- this->setstate(ios_base::badbit);
+ __err |= ios_base::badbit;
}
catch(...)
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ basic_ostream<_CharT, _Traits>::
+ operator<<(__streambuf_type* __sbin)
+ {
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ sentry __cerb(*this);
+ if (__cerb && __sbin)
+ {
+ try
{
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
+ if (!__copy_streambufs(*this, __sbin, this->rdbuf()))
+ __err |= ios_base::failbit;
}
+ catch(...)
+ { this->_M_setstate(ios_base::failbit); }
}
+ else if (!__sbin)
+ __err |= ios_base::badbit;
+ this->setstate(__err);
return *this;
}
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::put(char_type __c)
+ basic_ostream<_CharT, _Traits>::
+ put(char_type __c)
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR 60. What is a formatted input function?
@@ -356,25 +330,24 @@ namespace std
sentry __cerb(*this);
if (__cerb)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
try
{
int_type __put = this->rdbuf()->sputc(__c);
if (traits_type::eq_int_type(__put, traits_type::eof()))
- this->setstate(ios_base::badbit);
+ __err |= ios_base::badbit;
}
catch (...)
- {
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
}
return *this;
}
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::write(const _CharT* __s, streamsize __n)
+ basic_ostream<_CharT, _Traits>::
+ write(const _CharT* __s, streamsize __n)
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR 60. What is a formatted input function?
@@ -389,71 +362,95 @@ namespace std
try
{ _M_write(__s, __n); }
catch (...)
- {
- this->_M_setstate(ios_base::badbit);
- if ((this->exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { this->_M_setstate(ios_base::badbit); }
}
return *this;
}
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::flush()
+ basic_ostream<_CharT, _Traits>::
+ flush()
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR 60. What is a formatted input function?
// basic_ostream::flush() is *not* an unformatted output function.
- if (this->rdbuf() && this->rdbuf()->pubsync() == -1)
- this->setstate(ios_base::badbit);
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ try
+ {
+ if (this->rdbuf() && this->rdbuf()->pubsync() == -1)
+ __err |= ios_base::badbit;
+ }
+ catch(...)
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
return *this;
}
template<typename _CharT, typename _Traits>
typename basic_ostream<_CharT, _Traits>::pos_type
- basic_ostream<_CharT, _Traits>::tellp()
+ basic_ostream<_CharT, _Traits>::
+ tellp()
{
pos_type __ret = pos_type(-1);
- if (!this->fail())
- __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
+ try
+ {
+ if (!this->fail())
+ __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
+ }
+ catch(...)
+ { this->_M_setstate(ios_base::badbit); }
return __ret;
}
-
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
+ basic_ostream<_CharT, _Traits>::
+ seekp(pos_type __pos)
{
- if (!this->fail())
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ try
{
- // _GLIBCXX_RESOLVE_LIB_DEFECTS
- // 136. seekp, seekg setting wrong streams?
- pos_type __err = this->rdbuf()->pubseekpos(__pos, ios_base::out);
-
- // 129. Need error indication from seekp() and seekg()
- if (__err == pos_type(off_type(-1)))
- this->setstate(ios_base::failbit);
+ if (!this->fail())
+ {
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 136. seekp, seekg setting wrong streams?
+ pos_type __p = this->rdbuf()->pubseekpos(__pos, ios_base::out);
+
+ // 129. Need error indication from seekp() and seekg()
+ if (__p == pos_type(off_type(-1)))
+ __err |= ios_base::failbit;
+ }
}
+ catch(...)
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
return *this;
}
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::
- seekp(off_type __off, ios_base::seekdir __d)
+ seekp(off_type __off, ios_base::seekdir __dir)
{
- if (!this->fail())
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+ try
{
- // _GLIBCXX_RESOLVE_LIB_DEFECTS
- // 136. seekp, seekg setting wrong streams?
- pos_type __err = this->rdbuf()->pubseekoff(__off, __d,
- ios_base::out);
-
- // 129. Need error indication from seekp() and seekg()
- if (__err == pos_type(off_type(-1)))
- this->setstate(ios_base::failbit);
+ if (!this->fail())
+ {
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 136. seekp, seekg setting wrong streams?
+ pos_type __p = this->rdbuf()->pubseekoff(__off, __dir,
+ ios_base::out);
+
+ // 129. Need error indication from seekp() and seekg()
+ if (__p == pos_type(off_type(-1)))
+ __err |= ios_base::failbit;
+ }
}
+ catch(...)
+ { this->_M_setstate(ios_base::badbit); }
+ this->setstate(__err);
return *this;
}
@@ -483,13 +480,7 @@ namespace std
__out.width(0);
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- __out._M_setstate(ios_base::badbit);
- if ((__out.exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { __out._M_setstate(ios_base::badbit); }
}
return __out;
}
@@ -519,13 +510,7 @@ namespace std
__out.width(0);
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- __out._M_setstate(ios_base::badbit);
- if ((__out.exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { __out._M_setstate(ios_base::badbit); }
}
return __out;
}
@@ -555,13 +540,7 @@ namespace std
__out.width(0);
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- __out._M_setstate(ios_base::badbit);
- if ((__out.exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { __out._M_setstate(ios_base::badbit); }
}
else if (!__s)
__out.setstate(ios_base::badbit);
@@ -604,13 +583,7 @@ namespace std
__out.width(0);
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- __out._M_setstate(ios_base::badbit);
- if ((__out.exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { __out._M_setstate(ios_base::badbit); }
}
else if (!__s)
__out.setstate(ios_base::badbit);
@@ -642,13 +615,7 @@ namespace std
__out.width(0);
}
catch(...)
- {
- // 27.6.1.2.1 Common requirements.
- // Turn this on without causing an ios::failure to be thrown.
- __out._M_setstate(ios_base::badbit);
- if ((__out.exceptions() & ios_base::badbit) != 0)
- __throw_exception_again;
- }
+ { __out._M_setstate(ios_base::badbit); }
}
else if (!__s)
__out.setstate(ios_base::badbit);
@@ -668,6 +635,7 @@ namespace std
const streamsize __w = __out.width();
streamsize __len = static_cast<streamsize>(__str.size());
const _CharT* __s = __str.data();
+
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 25. String operator<< uses width() value wrong
if (__w > __len)
diff --git a/libstdc++-v3/include/bits/streambuf.tcc b/libstdc++-v3/include/bits/streambuf.tcc
index 2fac350..559c5b9 100644
--- a/libstdc++-v3/include/bits/streambuf.tcc
+++ b/libstdc++-v3/include/bits/streambuf.tcc
@@ -126,8 +126,7 @@ namespace std
const size_t __n = __sbin->egptr() - __sbin->gptr();
if (__n > 1)
{
- const size_t __wrote = __sbout->sputn(__sbin->gptr(),
- __n);
+ const size_t __wrote = __sbout->sputn(__sbin->gptr(), __n);
__sbin->gbump(__wrote);
__ret += __wrote;
if (__wrote < __n)
@@ -144,12 +143,8 @@ namespace std
}
}
}
- catch(exception& __fail)
- {
- __ios.setstate(ios_base::failbit);
- if ((__ios.exceptions() & ios_base::failbit) != 0)
- __throw_exception_again;
- }
+ catch(...)
+ { __throw_exception_again; }
return __ret;
}