diff options
28 files changed, 1948 insertions, 521 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 243dcbdf..fd4aaaf 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,58 @@ 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. + +2003-11-26 Benjamin Kosnik <bkoz@redhat.com> + PR libstdc++/12297 * include/bits/istream.tcc (basic_istream::sentry::sentry): Set failbit and eofbit when eof. 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; } diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/exceptions/char/9561.cc b/libstdc++-v3/testsuite/27_io/basic_istream/exceptions/char/9561.cc index 315b651..ace6cdd 100644 --- a/libstdc++-v3/testsuite/27_io/basic_istream/exceptions/char/9561.cc +++ b/libstdc++-v3/testsuite/27_io/basic_istream/exceptions/char/9561.cc @@ -21,44 +21,36 @@ #include <istream> #include <streambuf> #include <testsuite_hooks.h> +#include <testsuite_io.h> // libstdc++/9561 -struct foobar: std::exception { }; - -struct buf: std::streambuf -{ - virtual int_type underflow () { - throw foobar (); - return -1; - } - virtual int_type uflow () { - throw foobar (); - return -1; - } -}; - void test01() { using namespace std; bool test __attribute__((unused)) = true; - buf b; + __gnu_test::fail_streambuf b; std::istream strm (&b); strm.exceptions (std::ios::badbit); int i = 0; - try { - i = strm.get(); - } - catch (foobar) { - // strm should throw foobar and not do anything else - VERIFY(strm.bad()); - } - catch (...) { - VERIFY(false); - } + try + { + i = strm.get(); + i = strm.get(); + i = strm.get(); + } + catch (__gnu_test::underflow_error&) + { + // strm should throw facet_error and not do anything else + VERIFY(strm.bad()); + } + catch (...) + { + VERIFY(false); + } - VERIFY(i == 0); + VERIFY(i == 's'); } diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_badbit_throw.cc new file mode 100644 index 0000000..f7c43e2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_badbit_throw.cc @@ -0,0 +1,76 @@ +// 2003-03-08 Jerry Quinn <jlquinn@optonline.net> + +// 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. + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// libstdc++/9561 +template<typename T> +void test_badbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new __gnu_test::fail_num_get); + istringstream stream("jaylib - champion sound"); + stream.imbue(loc); + + stream.exceptions(ios_base::badbit); + VERIFY( stream.rdstate() == ios_base::goodbit ); + + try + { + T i; + stream >> i; + VERIFY( false ); + } + catch (const __gnu_test::facet_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + + +int main() +{ + test_badbit<bool>(); + test_badbit<short>(); + test_badbit<unsigned short>(); + test_badbit<int>(); + test_badbit<unsigned int>(); + test_badbit<long>(); + test_badbit<unsigned long>(); + + test_badbit<float>(); + test_badbit<double>(); + + test_badbit<void*>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit.cc new file mode 100644 index 0000000..e2ffe36 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit.cc @@ -0,0 +1,75 @@ +// 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. + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/10093 +template<typename T> +void test_failbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + istringstream stream("jaylib - champion sound"); + stream.exceptions(ios_base::failbit); + + try + { + T i; + stream >> i; + VERIFY( false ); + } + catch (const ios_base::failure&) + { + // stream should set failbit and throw ios_base::failure. + VERIFY( stream.fail() ); + VERIFY( !stream.bad() ); + VERIFY( !stream.eof() ); + } + catch(...) + { VERIFY( false ); } +} + +int main() +{ + test_failbit<bool>(); + test_failbit<short>(); + test_failbit<unsigned short>(); + test_failbit<int>(); + test_failbit<unsigned int>(); + test_failbit<long>(); + test_failbit<unsigned long>(); + + test_failbit<float>(); + test_failbit<double>(); + + test_failbit<void*>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit_throw.cc new file mode 100644 index 0000000..0b223bc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit_throw.cc @@ -0,0 +1,78 @@ +// 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. + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// libstdc++/10093 +template<typename T> +void test_failbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new __gnu_test::fail_num_get); + istringstream stream("jaylib - champion sound"); + stream.imbue(loc); + + stream.exceptions(ios_base::failbit); + + try + { + T i; + stream >> i; + } + catch (const ios_base::failure&) + { VERIFY( false ); } + catch(...) + { VERIFY( false ); } + + // stream should set badbit. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); +} + +int main() +{ + test_failbit<bool>(); + test_failbit<short>(); + test_failbit<unsigned short>(); + test_failbit<int>(); + test_failbit<unsigned int>(); + test_failbit<long>(); + test_failbit<unsigned long>(); + + test_failbit<float>(); + test_failbit<double>(); + + test_failbit<void*>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/error_failbit.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/error_failbit.cc new file mode 100644 index 0000000..2079b45 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/error_failbit.cc @@ -0,0 +1,67 @@ +// 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. + +#include <istream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test6() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bib; + istream stream(&bib); + stringbuf sbuf("", ios_base::out); + + stream >> &sbuf; + + VERIFY(stream.rdstate() & ios_base::failbit); + VERIFY((stream.rdstate() & ios_base::badbit) == 0); +} + +void test8() +{ + bool test __attribute__((unused)) = true; + istringstream stream("foo, bar, qux"); + __gnu_test::fail_streambuf bob; + + stream >> &bob; + + VERIFY(stream.rdstate() & ios_base::failbit); + VERIFY((stream.rdstate() & ios_base::badbit) == 0); +} + +// libstdc++/9371 +int main() +{ + test6(); + test8(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_badbit_throw.cc new file mode 100644 index 0000000..86c0a8a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_badbit_throw.cc @@ -0,0 +1,79 @@ +// 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. + +#include <istream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test14() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bib; + istream stream(&bib); + stream.exceptions(ios_base::badbit); + stringbuf sbuf("", ios_base::out); + + try + { + stream >> &sbuf; + } + catch (...) + { VERIFY(false); } + + VERIFY(stream.rdstate() & ios_base::failbit); + VERIFY((stream.rdstate() & ios_base::badbit) == 0); +} + +void test16() +{ + bool test __attribute__((unused)) = true; + istringstream stream("foo, bar, qux"); + stream.exceptions(ios_base::badbit); + __gnu_test::fail_streambuf bob; + + try + { + stream >> &bob; + } + catch (...) + { VERIFY(false); } + + VERIFY(stream.rdstate() & ios_base::failbit); + VERIFY((stream.rdstate() & ios_base::badbit) == 0); +} + +// libstdc++/9371 +int main() +{ + test14(); + test16(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_failbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_failbit_throw.cc new file mode 100644 index 0000000..199750a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_failbit_throw.cc @@ -0,0 +1,89 @@ +// 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. + +#include <istream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test10() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bib; + istream stream(&bib); + stream.exceptions(ios_base::failbit); + stringbuf sbuf("", ios_base::out); + + try + { + stream >> &sbuf; + VERIFY(false); + } + catch (ios_base::failure&) + { VERIFY(false); } + catch (__gnu_test::underflow_error&) + { } + catch (...) + { VERIFY(false); } + + VERIFY(stream.rdstate() & ios_base::failbit); + VERIFY((stream.rdstate() & ios_base::badbit) == 0); +} + +void test12() +{ + bool test __attribute__((unused)) = true; + istringstream stream("foo, bar, qux"); + stream.exceptions(ios_base::failbit); + __gnu_test::fail_streambuf bob; + + try + { + stream >> &bob; + VERIFY(false); + } + catch (ios_base::failure&) + { VERIFY(false); } + catch (__gnu_test::overflow_error&) + { } + catch (...) + { VERIFY(false); } + + VERIFY(stream.rdstate() & ios_base::failbit); + VERIFY((stream.rdstate() & ios_base::badbit) == 0); +} + +// libstdc++/9371 +int main() +{ + test10(); + test12(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_null.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_null.cc new file mode 100644 index 0000000..8e012d1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_null.cc @@ -0,0 +1,68 @@ +// 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. + +#include <istream> +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> + +using namespace std; + +void test2() +{ + bool test __attribute__((unused)) = true; + istringstream stream; + stream >> static_cast<streambuf*>(NULL); + VERIFY(stream.rdstate() & ios_base::failbit); +} + +void test4() +{ + bool test __attribute__((unused)) = true; + istringstream stream; + stream.exceptions(ios_base::failbit); + + try + { + stream >> static_cast<streambuf*>(NULL); + VERIFY(false); + } + catch (ios_base::failure&) + { + } + + VERIFY(stream.rdstate() & ios_base::failbit); +} + +// libstdc++/9371 +int main() +{ + test2(); + test4(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/exceptions_badbit_throw.cc new file mode 100644 index 0000000..bf89340 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/exceptions_badbit_throw.cc @@ -0,0 +1,96 @@ +// 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. + +#include <istream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test01() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bib; + istream stream(&bib); + stream.exceptions(ios_base::badbit); + + istream::pos_type pos; + + try + { + stream.seekg(pos); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + +void test02() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bib; + istream stream(&bib); + stream.exceptions(ios_base::badbit); + + istream::off_type off; + + try + { + stream.seekg(off, ios_base::cur); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + +// libstdc++/9546 +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/exceptions_badbit_throw.cc new file mode 100644 index 0000000..bd90ab2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/exceptions_badbit_throw.cc @@ -0,0 +1,66 @@ +// 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. + +#include <istream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test01() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bib; + istream stream(&bib); + stream.exceptions(ios_base::badbit); + + try + { + stream.tellg(); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + +// libstdc++/9546 +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/exceptions_badbit_throw.cc new file mode 100644 index 0000000..e8c5653 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/exceptions_badbit_throw.cc @@ -0,0 +1,66 @@ +// 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. + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test01() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bib; + ostream stream(&bib); + stream.exceptions(ios_base::badbit); + + try + { + stream.flush(); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + +// libstdc++/9546 +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_badbit_throw.cc new file mode 100644 index 0000000..a084dbd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_badbit_throw.cc @@ -0,0 +1,74 @@ +// 2003-03-08 Jerry Quinn <jlquinn@optonline.net> + +// 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. + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// libstdc++/9561 +template<typename T> +void test_badbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new __gnu_test::fail_num_put); + ostringstream stream("jaylib - champion sound"); + stream.imbue(loc); + + stream.exceptions(ios_base::badbit); + VERIFY( stream.rdstate() == ios_base::goodbit ); + + try + { + T i; + stream << i; + VERIFY( false ); + } + catch (const __gnu_test::facet_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + + +int main() +{ + test_badbit<bool>(); + test_badbit<short>(); + test_badbit<unsigned short>(); + test_badbit<int>(); + test_badbit<unsigned int>(); + test_badbit<long>(); + test_badbit<unsigned long>(); + + test_badbit<float>(); + test_badbit<double>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_failbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_failbit_throw.cc new file mode 100644 index 0000000..a1fbe21 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_failbit_throw.cc @@ -0,0 +1,76 @@ +// 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. + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// libstdc++/10093 +template<typename T> +void test_failbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new __gnu_test::fail_num_put); + ostringstream stream("jaylib - champion sound"); + stream.imbue(loc); + + stream.exceptions(ios_base::failbit); + + try + { + T i; + stream << i; + } + catch (const ios_base::failure&) + { VERIFY( false ); } + catch(...) + { VERIFY( false ); } + + // stream should set badbit. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); +} + +int main() +{ + test_failbit<bool>(); + test_failbit<short>(); + test_failbit<unsigned short>(); + test_failbit<int>(); + test_failbit<unsigned int>(); + test_failbit<long>(); + test_failbit<unsigned long>(); + + test_failbit<float>(); + test_failbit<double>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_failbit.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_failbit.cc new file mode 100644 index 0000000..ce47b6f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_failbit.cc @@ -0,0 +1,67 @@ +// 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. + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test5() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bob; + ostream stream(&bob); + stringbuf sbuf("Foo, bar, qux", ios_base::in); + + stream << &sbuf; + + VERIFY(stream.rdstate() & ios_base::failbit); + VERIFY((stream.rdstate() & ios_base::badbit) == 0); +} + +void test7() +{ + bool test __attribute__((unused)) = true; + ostringstream stream; + __gnu_test::fail_streambuf bib; + + stream << &bib; + + VERIFY(stream.rdstate() & ios_base::failbit); + VERIFY((stream.rdstate() & ios_base::badbit) == 0); +} + +// libstdc++/9371 +int main() +{ + test5(); + test7(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_badbit_throw.cc new file mode 100644 index 0000000..13ff248 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_badbit_throw.cc @@ -0,0 +1,79 @@ +// 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. + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test13() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bob; + ostream stream(&bob); + stream.exceptions(ios_base::badbit); + stringbuf sbuf("Foo, bar, qux", ios_base::in); + + try + { + stream << &sbuf; + } + catch (...) + { VERIFY(false); } + + VERIFY(stream.rdstate() & ios_base::failbit); + VERIFY((stream.rdstate() & ios_base::badbit) == 0); +} + +void test15() +{ + bool test __attribute__((unused)) = true; + ostringstream stream; + stream.exceptions(ios_base::badbit); + __gnu_test::fail_streambuf bib; + + try + { + stream << &bib; + } + catch (...) + { VERIFY(false); } + + VERIFY(stream.rdstate() & ios_base::failbit); + VERIFY((stream.rdstate() & ios_base::badbit) == 0); +} + +// libstdc++/9371 +int main() +{ + test13(); + test15(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_failbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_failbit_throw.cc new file mode 100644 index 0000000..5abaf92 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_failbit_throw.cc @@ -0,0 +1,89 @@ +// 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. + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test9() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bob; + ostream stream(&bob); + stream.exceptions(ios_base::failbit); + stringbuf sbuf("Foo, bar, qux", ios_base::in); + + try + { + stream << &sbuf; + VERIFY(false); + } + catch (ios_base::failure&) + { VERIFY(false); } + catch (__gnu_test::overflow_error&) + { } + catch (...) + { VERIFY(false); } + + VERIFY(stream.rdstate() & ios_base::failbit); + VERIFY((stream.rdstate() & ios_base::badbit) == 0); +} + +void test11() +{ + bool test __attribute__((unused)) = true; + ostringstream stream; + stream.exceptions(ios_base::failbit); + __gnu_test::fail_streambuf bib; + + try + { + stream << &bib; + VERIFY(false); + } + catch (ios_base::failure&) + { VERIFY(false); } + catch (__gnu_test::underflow_error&) + { } + catch (...) + { VERIFY(false); } + + VERIFY(stream.rdstate() & ios_base::failbit); + VERIFY((stream.rdstate() & ios_base::badbit) == 0); +} + +// libstdc++/9371 +int main() +{ + test9(); + test11(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_null.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_null.cc new file mode 100644 index 0000000..3f2de4d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_null.cc @@ -0,0 +1,68 @@ +// 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. + +#include <istream> +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> + +using namespace std; + +void test1() +{ + bool test __attribute__((unused)) = true; + ostringstream stream; + stream << static_cast<streambuf*>(NULL); + VERIFY(stream.rdstate() & ios_base::badbit); +} + +void test3() +{ + bool test __attribute__((unused)) = true; + ostringstream stream; + stream.exceptions(ios_base::badbit); + + try + { + stream << static_cast<streambuf*>(NULL); + VERIFY(false); + } + catch (ios_base::failure&) + { + } + + VERIFY(stream.rdstate() & ios_base::badbit); +} + +// libstdc++/9371 +int main() +{ + test1(); + test3(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/exceptions_badbit_throw.cc new file mode 100644 index 0000000..b0b3051 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/exceptions_badbit_throw.cc @@ -0,0 +1,96 @@ +// 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. + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test01() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bib; + ostream stream(&bib); + stream.exceptions(ios_base::badbit); + + ostream::pos_type pos; + + try + { + stream.seekp(pos); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + +void test02() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bib; + ostream stream(&bib); + stream.exceptions(ios_base::badbit); + + ostream::off_type off; + + try + { + stream.seekp(off, ios_base::cur); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + +// libstdc++/9546 +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/exceptions_badbit_throw.cc new file mode 100644 index 0000000..01d346a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/exceptions_badbit_throw.cc @@ -0,0 +1,66 @@ +// 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. + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test01() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bib; + ostream stream(&bib); + stream.exceptions(ios_base::badbit); + + try + { + stream.tellp(); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + +// libstdc++/9546 +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/testsuite_io.h b/libstdc++-v3/testsuite/testsuite_io.h index 86e1696..294f427 100644 --- a/libstdc++-v3/testsuite/testsuite_io.h +++ b/libstdc++-v3/testsuite/testsuite_io.h @@ -70,8 +70,7 @@ namespace __gnu_test bool one = this->pbase() == NULL; bool two = this->pptr() == NULL; return one && two; - } - + } }; // Used to check if basic_streambuf::pubsync() has been called. @@ -97,6 +96,164 @@ namespace __gnu_test return 0; } }; + + // Throws on all overflow and underflow calls. + struct underflow_error: std::exception { }; + struct overflow_error: std::exception { }; + struct positioning_error: std::exception { }; + + struct fail_streambuf : std::streambuf + { + fail_streambuf() + { + static char p[] = "s"; + setg(p, p, p + 1); + } + + virtual int_type underflow() + { + throw underflow_error(); + return -1; + } + + virtual int_type uflow() + { + throw underflow_error(); + return -1; + } + + virtual int_type + overflow(int_type) + { + throw overflow_error(); + return -1; + } + + virtual pos_type + seekoff(off_type, std::ios_base::seekdir, std::ios_base::openmode) + { + throw positioning_error(); + return pos_type(off_type(-1)); + } + + virtual pos_type + seekpos(pos_type, std::ios_base::openmode) + { + throw positioning_error(); + return pos_type(off_type(-1)); + } + + virtual int + sync() + { + throw positioning_error(); + return 0; + } + }; + + // Facets that throw an exception for every virtual function. + struct facet_error: std::exception { }; + + class fail_num_get : public std::num_get<char> + { + typedef std::ios_base ios_base; + + protected: + iter_type + do_get(iter_type a, iter_type, ios_base&, ios_base::iostate&, bool&) const + { throw facet_error(); return iter_type(); } + + virtual iter_type + do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, long&) const + { throw facet_error(); return iter_type(); } + + virtual iter_type + do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, + unsigned short&) const + { throw facet_error(); return iter_type(); } + + virtual iter_type + do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, + unsigned int&) const + { throw facet_error(); return iter_type(); } + + virtual iter_type + do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, + unsigned long&) const + { throw facet_error(); return iter_type(); } + +#ifdef _GLIBCXX_USE_LONG_LONG + virtual iter_type + do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, + long long&) const + { throw facet_error(); return iter_type(); } + + virtual iter_type + do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, + unsigned long long&) const + { throw facet_error(); return iter_type(); } +#endif + + virtual iter_type + do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, + float&) const + { throw facet_error(); return iter_type(); } + + virtual iter_type + do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, + double&) const + { throw facet_error(); return iter_type(); } + + virtual iter_type + do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, + long double&) const + { throw facet_error(); return iter_type(); } + + virtual iter_type + do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, + void*&) const + { throw facet_error(); return iter_type(); } + }; + + class fail_num_put : public std::num_put<char> + { + typedef std::ios_base ios_base; + + protected: + iter_type + do_put(iter_type, ios_base&, char_type __fill, bool __v) const + { throw facet_error(); return iter_type(NULL); } + + virtual iter_type + do_put(iter_type, ios_base&, char_type __fill, long __v) const + { throw facet_error(); return iter_type(NULL); } + + virtual iter_type + do_put(iter_type, ios_base&, char_type __fill, unsigned long) const + { throw facet_error(); return iter_type(NULL); } + +#ifdef _GLIBCXX_USE_LONG_LONG + virtual iter_type + do_put(iter_type, ios_base&, char_type __fill, long long __v) const + { throw facet_error(); return iter_type(NULL); } + + virtual iter_type + do_put(iter_type, ios_base&, char_type __fill, unsigned long long) const + { throw facet_error(); return iter_type(NULL); } +#endif + + virtual iter_type + do_put(iter_type, ios_base&, char_type __fill, double __v) const + { throw facet_error(); return iter_type(NULL); } + + virtual iter_type + do_put(iter_type, ios_base&, char_type __fill, long double __v) const + { throw facet_error(); return iter_type(NULL); } + + virtual iter_type + do_put(iter_type, ios_base&, char_type __fill, const void* __v) const + { throw facet_error(); return iter_type(NULL); } + }; }; // namespace __gnu_test #endif // _GLIBCXX_TESTSUITE_IO_H |