diff options
Diffstat (limited to 'libstdc++-v3/include/bits/istream.tcc')
-rw-r--r-- | libstdc++-v3/include/bits/istream.tcc | 128 |
1 files changed, 89 insertions, 39 deletions
diff --git a/libstdc++-v3/include/bits/istream.tcc b/libstdc++-v3/include/bits/istream.tcc index 5d60791ec98..d005f736f03 100644 --- a/libstdc++-v3/include/bits/istream.tcc +++ b/libstdc++-v3/include/bits/istream.tcc @@ -46,7 +46,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) basic_istream<_CharT, _Traits>::sentry:: sentry(basic_istream<_CharT, _Traits>& __in, bool __noskip) : _M_ok(false) { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); + ios_base::iostate __err = ios_base::goodbit; if (__in.good()) { if (__in.tie()) @@ -89,7 +89,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) sentry __cerb(*this, false); if (__cerb) { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); + ios_base::iostate __err = ios_base::goodbit; __try { const __num_get_type& __ng = __check_facet(this->_M_num_get); @@ -97,7 +97,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) } __catch(__cxxabiv1::__forced_unwind&) { - this->_M_setstate(ios_base::badbit); + this->_M_setstate(ios_base::badbit); __throw_exception_again; } __catch(...) @@ -115,19 +115,44 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { // _GLIBCXX_RESOLVE_LIB_DEFECTS // 118. basic_istream uses nonexistent num_get member functions. - long __l; - _M_extract(__l); - if (!this->fail()) + sentry __cerb(*this, false); + if (__cerb) { - if (__gnu_cxx::__numeric_traits<short>::__min <= __l - && __l <= __gnu_cxx::__numeric_traits<short>::__max) - __n = short(__l); - else - this->setstate(ios_base::failbit); + ios_base::iostate __err = ios_base::goodbit; + __try + { + long __l; + const __num_get_type& __ng = __check_facet(this->_M_num_get); + __ng.get(*this, 0, *this, __err, __l); + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 696. istream::operator>>(int&) broken. + if (__l < __gnu_cxx::__numeric_traits<short>::__min) + { + __err |= ios_base::failbit; + __n = __gnu_cxx::__numeric_traits<short>::__min; + } + else if (__l > __gnu_cxx::__numeric_traits<short>::__max) + { + __err |= ios_base::failbit; + __n = __gnu_cxx::__numeric_traits<short>::__max; + } + else + __n = short(__l); + } + __catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } + __catch(...) + { this->_M_setstate(ios_base::badbit); } + if (__err) + this->setstate(__err); } return *this; } - + template<typename _CharT, typename _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>:: @@ -135,15 +160,40 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { // _GLIBCXX_RESOLVE_LIB_DEFECTS // 118. basic_istream uses nonexistent num_get member functions. - long __l; - _M_extract(__l); - if (!this->fail()) + sentry __cerb(*this, false); + if (__cerb) { - if (__gnu_cxx::__numeric_traits<int>::__min <= __l - && __l <= __gnu_cxx::__numeric_traits<int>::__max) - __n = int(__l); - else - this->setstate(ios_base::failbit); + ios_base::iostate __err = ios_base::goodbit; + __try + { + long __l; + const __num_get_type& __ng = __check_facet(this->_M_num_get); + __ng.get(*this, 0, *this, __err, __l); + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 696. istream::operator>>(int&) broken. + if (__l < __gnu_cxx::__numeric_traits<int>::__min) + { + __err |= ios_base::failbit; + __n = __gnu_cxx::__numeric_traits<int>::__min; + } + else if (__l > __gnu_cxx::__numeric_traits<int>::__max) + { + __err |= ios_base::failbit; + __n = __gnu_cxx::__numeric_traits<int>::__max; + } + else + __n = int(__l); + } + __catch(__cxxabiv1::__forced_unwind&) + { + this->_M_setstate(ios_base::badbit); + __throw_exception_again; + } + __catch(...) + { this->_M_setstate(ios_base::badbit); } + if (__err) + this->setstate(__err); } return *this; } @@ -153,7 +203,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) basic_istream<_CharT, _Traits>:: operator>>(__streambuf_type* __sbout) { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); + ios_base::iostate __err = ios_base::goodbit; sentry __cerb(*this, false); if (__cerb && __sbout) { @@ -188,7 +238,7 @@ _GLIBCXX_BEGIN_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); + ios_base::iostate __err = ios_base::goodbit; sentry __cerb(*this, true); if (__cerb) { @@ -222,7 +272,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) get(char_type& __c) { _M_gcount = 0; - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); + ios_base::iostate __err = ios_base::goodbit; sentry __cerb(*this, true); if (__cerb) { @@ -259,7 +309,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) get(char_type* __s, streamsize __n, char_type __delim) { _M_gcount = 0; - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); + ios_base::iostate __err = ios_base::goodbit; sentry __cerb(*this, true); if (__cerb) { @@ -306,7 +356,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) get(__streambuf_type& __sb, char_type __delim) { _M_gcount = 0; - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); + ios_base::iostate __err = ios_base::goodbit; sentry __cerb(*this, true); if (__cerb) { @@ -350,7 +400,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) getline(char_type* __s, streamsize __n, char_type __delim) { _M_gcount = 0; - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); + ios_base::iostate __err = ios_base::goodbit; sentry __cerb(*this, true); if (__cerb) { @@ -413,7 +463,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) sentry __cerb(*this, true); if (__cerb) { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); + ios_base::iostate __err = ios_base::goodbit; __try { const int_type __eof = traits_type::eof(); @@ -446,7 +496,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) sentry __cerb(*this, true); if (__cerb && __n > 0) { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); + ios_base::iostate __err = ios_base::goodbit; __try { const int_type __eof = traits_type::eof(); @@ -508,7 +558,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) sentry __cerb(*this, true); if (__cerb && __n > 0) { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); + ios_base::iostate __err = ios_base::goodbit; __try { const int_type __eof = traits_type::eof(); @@ -574,7 +624,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) sentry __cerb(*this, true); if (__cerb) { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); + ios_base::iostate __err = ios_base::goodbit; __try { __c = this->rdbuf()->sgetc(); @@ -603,7 +653,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) sentry __cerb(*this, true); if (__cerb) { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); + ios_base::iostate __err = ios_base::goodbit; __try { _M_gcount = this->rdbuf()->sgetn(__s, __n); @@ -632,7 +682,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) sentry __cerb(*this, true); if (__cerb) { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); + ios_base::iostate __err = ios_base::goodbit; __try { // Cannot compare int_type with streamsize generically. @@ -666,7 +716,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) sentry __cerb(*this, true); if (__cerb) { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); + ios_base::iostate __err = ios_base::goodbit; __try { const int_type __eof = traits_type::eof(); @@ -699,7 +749,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) sentry __cerb(*this, true); if (__cerb) { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); + ios_base::iostate __err = ios_base::goodbit; __try { const int_type __eof = traits_type::eof(); @@ -732,7 +782,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) sentry __cerb(*this, true); if (__cerb) { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); + ios_base::iostate __err = ios_base::goodbit; __try { __streambuf_type* __sb = this->rdbuf(); @@ -788,7 +838,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { // _GLIBCXX_RESOLVE_LIB_DEFECTS // DR60. Do not change _M_gcount. - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); + ios_base::iostate __err = ios_base::goodbit; __try { if (!this->fail()) @@ -821,7 +871,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { // _GLIBCXX_RESOLVE_LIB_DEFECTS // DR60. Do not change _M_gcount. - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); + ios_base::iostate __err = ios_base::goodbit; __try { if (!this->fail()) @@ -858,7 +908,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) typename __istream_type::sentry __cerb(__in, false); if (__cerb) { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); + ios_base::iostate __err = ios_base::goodbit; __try { const __int_type __cb = __in.rdbuf()->sbumpc(); @@ -891,7 +941,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) typedef ctype<_CharT> __ctype_type; streamsize __extracted = 0; - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); + ios_base::iostate __err = ios_base::goodbit; typename __istream_type::sentry __cerb(__in, false); if (__cerb) { |