aboutsummaryrefslogtreecommitdiffstats
path: root/include/istream
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-08-20 20:51:16 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-08-20 20:51:16 +0000
commit1147845301c03308e3419b89c28c77bb6917fe04 (patch)
tree225f45e462607f9595a5e5f418a9533ab50e83bb /include/istream
parentb7332b04df5d50c92640c74cfeb138ecb7e3f7ae (diff)
downloadsrc-1147845301c03308e3419b89c28c77bb6917fe04.tar.gz
src-1147845301c03308e3419b89c28c77bb6917fe04.zip
Vendor import of stripped libc++ trunk r366426 (just before the release_90 branchvendor/libc++/libc++-trunk-r366426
Notes
Notes: svn path=/vendor/libc++/dist/; revision=351284 svn path=/vendor/libc++/libc++-trunk-r366426/; revision=351285; tag=vendor/libc++/libc++-trunk-r366426
Diffstat (limited to 'include/istream')
-rw-r--r--include/istream895
1 files changed, 514 insertions, 381 deletions
diff --git a/include/istream b/include/istream
index 30ee4f4b8710..d6217bbb8009 100644
--- a/include/istream
+++ b/include/istream
@@ -1,10 +1,9 @@
// -*- C++ -*-
//===--------------------------- istream ----------------------------------===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
@@ -363,26 +362,31 @@ template <class _Tp, class _CharT, class _Traits>
_LIBCPP_INLINE_VISIBILITY
basic_istream<_CharT, _Traits>&
__input_arithmetic(basic_istream<_CharT, _Traits>& __is, _Tp& __n) {
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
+ ios_base::iostate __state = ios_base::goodbit;
+ typename basic_istream<_CharT, _Traits>::sentry __s(__is);
+ if (__s)
{
-#endif // _LIBCPP_NO_EXCEPTIONS
- typename basic_istream<_CharT, _Traits>::sentry __s(__is);
- if (__s)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
{
+#endif // _LIBCPP_NO_EXCEPTIONS
typedef istreambuf_iterator<_CharT, _Traits> _Ip;
typedef num_get<_CharT, _Ip> _Fp;
- ios_base::iostate __err = ios_base::goodbit;
- use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __err, __n);
- __is.setstate(__err);
- }
+ use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __state, __n);
#ifndef _LIBCPP_NO_EXCEPTIONS
+ }
+ catch (...)
+ {
+ __state |= ios_base::badbit;
+ __is.__setstate_nothrow(__state);
+ if (__is.exceptions() & ios_base::badbit)
+ {
+ throw;
+ }
+ }
+#endif
+ __is.setstate(__state);
}
- catch (...)
- {
- __is.__set_badbit_and_consider_rethrow();
- }
-#endif // _LIBCPP_NO_EXCEPTIONS
return __is;
}
@@ -467,39 +471,46 @@ template <class _Tp, class _CharT, class _Traits>
_LIBCPP_INLINE_VISIBILITY
basic_istream<_CharT, _Traits>&
__input_arithmetic_with_numeric_limits(basic_istream<_CharT, _Traits>& __is, _Tp& __n) {
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
+ ios_base::iostate __state = ios_base::goodbit;
+ typename basic_istream<_CharT, _Traits>::sentry __s(__is);
+ if (__s)
{
-#endif // _LIBCPP_NO_EXCEPTIONS
- typename basic_istream<_CharT, _Traits>::sentry __s(__is);
- if (__s)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
{
+#endif // _LIBCPP_NO_EXCEPTIONS
typedef istreambuf_iterator<_CharT, _Traits> _Ip;
typedef num_get<_CharT, _Ip> _Fp;
- ios_base::iostate __err = ios_base::goodbit;
long __temp;
- use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __err, __temp);
+ use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __state, __temp);
if (__temp < numeric_limits<_Tp>::min())
{
- __err |= ios_base::failbit;
+ __state |= ios_base::failbit;
__n = numeric_limits<_Tp>::min();
}
else if (__temp > numeric_limits<_Tp>::max())
{
- __err |= ios_base::failbit;
+ __state |= ios_base::failbit;
__n = numeric_limits<_Tp>::max();
}
else
+ {
__n = static_cast<_Tp>(__temp);
- __is.setstate(__err);
- }
+ }
#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- __is.__set_badbit_and_consider_rethrow();
- }
+ }
+ catch (...)
+ {
+ __state |= ios_base::badbit;
+ __is.__setstate_nothrow(__state);
+ if (__is.exceptions() & ios_base::badbit)
+ {
+ throw;
+ }
+ }
#endif // _LIBCPP_NO_EXCEPTIONS
+ __is.setstate(__state);
+ }
return __is;
}
@@ -522,22 +533,22 @@ _LIBCPP_INLINE_VISIBILITY
basic_istream<_CharT, _Traits>&
__input_c_string(basic_istream<_CharT, _Traits>& __is, _CharT* __p, size_t __n)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
+ ios_base::iostate __state = ios_base::goodbit;
+ typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
+ if (__sen)
{
-#endif // _LIBCPP_NO_EXCEPTIONS
- typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
- if (__sen)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
{
- auto __s = __p;
+#endif
+ _CharT* __s = __p;
const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
- ios_base::iostate __err = ios_base::goodbit;
while (__s != __p + (__n-1))
{
typename _Traits::int_type __i = __is.rdbuf()->sgetc();
if (_Traits::eq_int_type(__i, _Traits::eof()))
{
- __err |= ios_base::eofbit;
+ __state |= ios_base::eofbit;
break;
}
_CharT __ch = _Traits::to_char_type(__i);
@@ -549,16 +560,21 @@ __input_c_string(basic_istream<_CharT, _Traits>& __is, _CharT* __p, size_t __n)
*__s = _CharT();
__is.width(0);
if (__s == __p)
- __err |= ios_base::failbit;
- __is.setstate(__err);
- }
+ __state |= ios_base::failbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
+ }
+ catch (...)
+ {
+ __state |= ios_base::badbit;
+ __is.__setstate_nothrow(__state);
+ if (__is.exceptions() & ios_base::badbit)
+ {
+ throw;
+ }
+ }
+#endif
+ __is.setstate(__state);
}
- catch (...)
- {
- __is.__set_badbit_and_consider_rethrow();
- }
-#endif // _LIBCPP_NO_EXCEPTIONS
return __is;
}
@@ -569,7 +585,7 @@ inline _LIBCPP_INLINE_VISIBILITY
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, _CharT (&__buf)[_Np])
{
- auto __n = _Np;
+ size_t __n = _Np;
if (__is.width() > 0)
__n = _VSTD::min(size_t(__is.width()), _Np);
return _VSTD::__input_c_string(__is, __buf, __n);
@@ -626,26 +642,33 @@ template<class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
+ ios_base::iostate __state = ios_base::goodbit;
+ typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
+ if (__sen)
{
-#endif // _LIBCPP_NO_EXCEPTIONS
- typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
- if (__sen)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
{
+#endif
typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
if (_Traits::eq_int_type(__i, _Traits::eof()))
- __is.setstate(ios_base::eofbit | ios_base::failbit);
+ __state |= ios_base::eofbit | ios_base::failbit;
else
__c = _Traits::to_char_type(__i);
- }
#ifndef _LIBCPP_NO_EXCEPTIONS
+ }
+ catch (...)
+ {
+ __state |= ios_base::badbit;
+ __is.__setstate_nothrow(__state);
+ if (__is.exceptions() & ios_base::badbit)
+ {
+ throw;
+ }
+ }
+#endif
+ __is.setstate(__state);
}
- catch (...)
- {
- __is.__set_badbit_and_consider_rethrow();
- }
-#endif // _LIBCPP_NO_EXCEPTIONS
return __is;
}
@@ -669,58 +692,56 @@ template<class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_type>* __sb)
{
+ ios_base::iostate __state = ios_base::goodbit;
__gc_ = 0;
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
+ sentry __s(*this, true);
+ if (__s)
{
-#endif // _LIBCPP_NO_EXCEPTIONS
- sentry __s(*this, true);
- if (__s)
+ if (__sb)
{
- if (__sb)
- {
#ifndef _LIBCPP_NO_EXCEPTIONS
- try
+ try
+ {
+#endif // _LIBCPP_NO_EXCEPTIONS
+ while (true)
{
-#endif // _LIBCPP_NO_EXCEPTIONS
- ios_base::iostate __err = ios_base::goodbit;
- while (true)
+ typename traits_type::int_type __i = this->rdbuf()->sgetc();
+ if (traits_type::eq_int_type(__i, _Traits::eof()))
{
- typename traits_type::int_type __i = this->rdbuf()->sgetc();
- if (traits_type::eq_int_type(__i, _Traits::eof()))
- {
- __err |= ios_base::eofbit;
- break;
- }
- if (traits_type::eq_int_type(
- __sb->sputc(traits_type::to_char_type(__i)),
- traits_type::eof()))
- break;
- ++__gc_;
- this->rdbuf()->sbumpc();
+ __state |= ios_base::eofbit;
+ break;
}
- if (__gc_ == 0)
- __err |= ios_base::failbit;
- this->setstate(__err);
-#ifndef _LIBCPP_NO_EXCEPTIONS
+ if (traits_type::eq_int_type(
+ __sb->sputc(traits_type::to_char_type(__i)),
+ traits_type::eof()))
+ break;
+ ++__gc_;
+ this->rdbuf()->sbumpc();
}
- catch (...)
+ if (__gc_ == 0)
+ __state |= ios_base::failbit;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ }
+ catch (...)
+ {
+ __state |= ios_base::badbit;
+ if (__gc_ == 0)
+ __state |= ios_base::failbit;
+
+ this->__setstate_nothrow(__state);
+ if (this->exceptions() & ios_base::failbit || this->exceptions() & ios_base::badbit)
{
- if (__gc_ == 0)
- this->__set_failbit_and_consider_rethrow();
+ throw;
}
-#endif // _LIBCPP_NO_EXCEPTIONS
}
- else
- this->setstate(ios_base::failbit);
+#endif // _LIBCPP_NO_EXCEPTIONS
}
-#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
+ else
+ {
+ __state |= ios_base::failbit;
+ }
+ this->setstate(__state);
}
-#endif // _LIBCPP_NO_EXCEPTIONS
return *this;
}
@@ -728,28 +749,34 @@ template<class _CharT, class _Traits>
typename basic_istream<_CharT, _Traits>::int_type
basic_istream<_CharT, _Traits>::get()
{
+ ios_base::iostate __state = ios_base::goodbit;
__gc_ = 0;
int_type __r = traits_type::eof();
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
+ sentry __s(*this, true);
+ if (__s)
{
-#endif // _LIBCPP_NO_EXCEPTIONS
- sentry __s(*this, true);
- if (__s)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
{
+#endif
__r = this->rdbuf()->sbumpc();
if (traits_type::eq_int_type(__r, traits_type::eof()))
- this->setstate(ios_base::failbit | ios_base::eofbit);
+ __state |= ios_base::failbit | ios_base::eofbit;
else
__gc_ = 1;
- }
#ifndef _LIBCPP_NO_EXCEPTIONS
+ }
+ catch (...)
+ {
+ this->__setstate_nothrow(this->rdstate() | ios_base::badbit);
+ if (this->exceptions() & ios_base::badbit)
+ {
+ throw;
+ }
+ }
+#endif
+ this->setstate(__state);
}
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
-#endif // _LIBCPP_NO_EXCEPTIONS
return __r;
}
@@ -757,23 +784,23 @@ template<class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __dlm)
{
+ ios_base::iostate __state = ios_base::goodbit;
__gc_ = 0;
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
+ sentry __sen(*this, true);
+ if (__sen)
{
-#endif // _LIBCPP_NO_EXCEPTIONS
- sentry __sen(*this, true);
- if (__sen)
+ if (__n > 0)
{
- if (__n > 0)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
{
- ios_base::iostate __err = ios_base::goodbit;
+#endif
while (__gc_ < __n-1)
{
int_type __i = this->rdbuf()->sgetc();
if (traits_type::eq_int_type(__i, traits_type::eof()))
{
- __err |= ios_base::eofbit;
+ __state |= ios_base::eofbit;
break;
}
char_type __ch = traits_type::to_char_type(__i);
@@ -784,23 +811,33 @@ basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __
this->rdbuf()->sbumpc();
}
if (__gc_ == 0)
- __err |= ios_base::failbit;
- this->setstate(__err);
+ __state |= ios_base::failbit;
+#ifndef _LIBCPP_NO_EXCEPTIONS
}
- else
- this->setstate(ios_base::failbit);
+ catch (...)
+ {
+ __state |= ios_base::badbit;
+ this->__setstate_nothrow(__state);
+ if (this->exceptions() & ios_base::badbit)
+ {
+ if (__n > 0)
+ *__s = char_type();
+ throw;
+ }
+ }
+#endif
}
+ else
+ {
+ __state |= ios_base::failbit;
+ }
+
if (__n > 0)
*__s = char_type();
-#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- if (__n > 0)
- *__s = char_type();
- this->__set_badbit_and_consider_rethrow();
+ this->setstate(__state);
}
-#endif // _LIBCPP_NO_EXCEPTIONS
+ if (__n > 0)
+ *__s = char_type();
return *this;
}
@@ -809,52 +846,43 @@ basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb,
char_type __dlm)
{
+ ios_base::iostate __state = ios_base::goodbit;
__gc_ = 0;
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
+ sentry __sen(*this, true);
+ if (__sen)
{
-#endif // _LIBCPP_NO_EXCEPTIONS
- sentry __sen(*this, true);
- if (__sen)
- {
- ios_base::iostate __err = ios_base::goodbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
+ try
+ {
#endif // _LIBCPP_NO_EXCEPTIONS
- while (true)
+ while (true)
+ {
+ typename traits_type::int_type __i = this->rdbuf()->sgetc();
+ if (traits_type::eq_int_type(__i, traits_type::eof()))
{
- typename traits_type::int_type __i = this->rdbuf()->sgetc();
- if (traits_type::eq_int_type(__i, traits_type::eof()))
- {
- __err |= ios_base::eofbit;
- break;
- }
- char_type __ch = traits_type::to_char_type(__i);
- if (traits_type::eq(__ch, __dlm))
- break;
- if (traits_type::eq_int_type(__sb.sputc(__ch), traits_type::eof()))
- break;
- ++__gc_;
- this->rdbuf()->sbumpc();
+ __state |= ios_base::eofbit;
+ break;
}
-#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
+ char_type __ch = traits_type::to_char_type(__i);
+ if (traits_type::eq(__ch, __dlm))
+ break;
+ if (traits_type::eq_int_type(__sb.sputc(__ch), traits_type::eof()))
+ break;
+ ++__gc_;
+ this->rdbuf()->sbumpc();
}
-#endif // _LIBCPP_NO_EXCEPTIONS
- if (__gc_ == 0)
- __err |= ios_base::failbit;
- this->setstate(__err);
- }
#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
+ }
+ catch (...)
+ {
+ __state |= ios_base::badbit;
+ // according to the spec, exceptions here are caught but not rethrown
+ }
#endif // _LIBCPP_NO_EXCEPTIONS
+ if (__gc_ == 0)
+ __state |= ios_base::failbit;
+ this->setstate(__state);
+ }
return *this;
}
@@ -862,21 +890,21 @@ template<class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm)
{
+ ios_base::iostate __state = ios_base::goodbit;
__gc_ = 0;
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
+ sentry __sen(*this, true);
+ if (__sen)
{
-#endif // _LIBCPP_NO_EXCEPTIONS
- sentry __sen(*this, true);
- if (__sen)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
{
- ios_base::iostate __err = ios_base::goodbit;
+#endif // _LIBCPP_NO_EXCEPTIONS
while (true)
{
typename traits_type::int_type __i = this->rdbuf()->sgetc();
if (traits_type::eq_int_type(__i, traits_type::eof()))
{
- __err |= ios_base::eofbit;
+ __state |= ios_base::eofbit;
break;
}
char_type __ch = traits_type::to_char_type(__i);
@@ -888,28 +916,35 @@ basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_typ
}
if (__gc_ >= __n-1)
{
- __err |= ios_base::failbit;
+ __state |= ios_base::failbit;
break;
}
*__s++ = __ch;
this->rdbuf()->sbumpc();
++__gc_;
}
- if (__gc_ == 0)
- __err |= ios_base::failbit;
- this->setstate(__err);
- }
- if (__n > 0)
- *__s = char_type();
#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- if (__n > 0)
- *__s = char_type();
- this->__set_badbit_and_consider_rethrow();
- }
+ }
+ catch (...)
+ {
+ __state |= ios_base::badbit;
+ this->__setstate_nothrow(__state);
+ if (this->exceptions() & ios_base::badbit)
+ {
+ if (__n > 0)
+ *__s = char_type();
+ if (__gc_ == 0)
+ __state |= ios_base::failbit;
+ throw;
+ }
+ }
#endif // _LIBCPP_NO_EXCEPTIONS
+ }
+ if (__n > 0)
+ *__s = char_type();
+ if (__gc_ == 0)
+ __state |= ios_base::failbit;
+ this->setstate(__state);
return *this;
}
@@ -917,15 +952,15 @@ template<class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm)
{
+ ios_base::iostate __state = ios_base::goodbit;
__gc_ = 0;
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
+ sentry __sen(*this, true);
+ if (__sen)
{
-#endif // _LIBCPP_NO_EXCEPTIONS
- sentry __sen(*this, true);
- if (__sen)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
{
- ios_base::iostate __err = ios_base::goodbit;
+#endif // _LIBCPP_NO_EXCEPTIONS
if (__n == numeric_limits<streamsize>::max())
{
while (true)
@@ -933,7 +968,7 @@ basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm)
typename traits_type::int_type __i = this->rdbuf()->sbumpc();
if (traits_type::eq_int_type(__i, traits_type::eof()))
{
- __err |= ios_base::eofbit;
+ __state |= ios_base::eofbit;
break;
}
++__gc_;
@@ -948,7 +983,7 @@ basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm)
typename traits_type::int_type __i = this->rdbuf()->sbumpc();
if (traits_type::eq_int_type(__i, traits_type::eof()))
{
- __err |= ios_base::eofbit;
+ __state |= ios_base::eofbit;
break;
}
++__gc_;
@@ -956,15 +991,20 @@ basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm)
break;
}
}
- this->setstate(__err);
- }
#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
+ }
+ catch (...)
+ {
+ __state |= ios_base::badbit;
+ this->__setstate_nothrow(__state);
+ if (this->exceptions() & ios_base::badbit)
+ {
+ throw;
+ }
+ }
#endif // _LIBCPP_NO_EXCEPTIONS
+ this->setstate(__state);
+ }
return *this;
}
@@ -972,26 +1012,33 @@ template<class _CharT, class _Traits>
typename basic_istream<_CharT, _Traits>::int_type
basic_istream<_CharT, _Traits>::peek()
{
+ ios_base::iostate __state = ios_base::goodbit;
__gc_ = 0;
int_type __r = traits_type::eof();
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
+ sentry __sen(*this, true);
+ if (__sen)
{
-#endif // _LIBCPP_NO_EXCEPTIONS
- sentry __sen(*this, true);
- if (__sen)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
{
+#endif // _LIBCPP_NO_EXCEPTIONS
__r = this->rdbuf()->sgetc();
if (traits_type::eq_int_type(__r, traits_type::eof()))
- this->setstate(ios_base::eofbit);
- }
+ __state |= ios_base::eofbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
+ }
+ catch (...)
+ {
+ __state |= ios_base::badbit;
+ this->__setstate_nothrow(__state);
+ if (this->exceptions() & ios_base::badbit)
+ {
+ throw;
+ }
+ }
#endif // _LIBCPP_NO_EXCEPTIONS
+ this->setstate(__state);
+ }
return __r;
}
@@ -999,27 +1046,36 @@ template<class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n)
{
+ ios_base::iostate __state = ios_base::goodbit;
__gc_ = 0;
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
+ sentry __sen(*this, true);
+ if (__sen)
{
-#endif // _LIBCPP_NO_EXCEPTIONS
- sentry __sen(*this, true);
- if (__sen)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
{
+#endif // _LIBCPP_NO_EXCEPTIONS
__gc_ = this->rdbuf()->sgetn(__s, __n);
if (__gc_ != __n)
- this->setstate(ios_base::failbit | ios_base::eofbit);
- }
- else
- this->setstate(ios_base::failbit);
+ __state |= ios_base::failbit | ios_base::eofbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
+ }
+ catch (...)
+ {
+ __state |= ios_base::badbit;
+ this->__setstate_nothrow(__state);
+ if (this->exceptions() & ios_base::badbit)
+ {
+ throw;
+ }
+ }
+#endif // _LIBCPP_NO_EXCEPTIONS
}
- catch (...)
+ else
{
- this->__set_badbit_and_consider_rethrow();
+ __state |= ios_base::failbit;
}
-#endif // _LIBCPP_NO_EXCEPTIONS
+ this->setstate(__state);
return *this;
}
@@ -1027,36 +1083,48 @@ template<class _CharT, class _Traits>
streamsize
basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n)
{
+ ios_base::iostate __state = ios_base::goodbit;
__gc_ = 0;
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
+ sentry __sen(*this, true);
+ if (__sen)
{
-#endif // _LIBCPP_NO_EXCEPTIONS
- sentry __sen(*this, true);
- if (__sen)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
{
+#endif // _LIBCPP_NO_EXCEPTIONS
streamsize __c = this->rdbuf()->in_avail();
switch (__c)
{
case -1:
- this->setstate(ios_base::eofbit);
+ __state |= ios_base::eofbit;
break;
case 0:
break;
default:
- read(__s, _VSTD::min(__c, __n));
+ __n = _VSTD::min(__c, __n);
+ __gc_ = this->rdbuf()->sgetn(__s, __n);
+ if (__gc_ != __n)
+ __state |= ios_base::failbit | ios_base::eofbit;
break;
}
- }
- else
- this->setstate(ios_base::failbit);
#ifndef _LIBCPP_NO_EXCEPTIONS
+ }
+ catch (...)
+ {
+ __state |= ios_base::badbit;
+ this->__setstate_nothrow(__state);
+ if (this->exceptions() & ios_base::badbit)
+ {
+ throw;
+ }
+ }
+#endif // _LIBCPP_NO_EXCEPTIONS
}
- catch (...)
+ else
{
- this->__set_badbit_and_consider_rethrow();
+ __state |= ios_base::failbit;
}
-#endif // _LIBCPP_NO_EXCEPTIONS
+ this->setstate(__state);
return __gc_;
}
@@ -1064,27 +1132,36 @@ template<class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::putback(char_type __c)
{
+ ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit;
__gc_ = 0;
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
+ this->clear(__state);
+ sentry __sen(*this, true);
+ if (__sen)
{
-#endif // _LIBCPP_NO_EXCEPTIONS
- this->clear(this->rdstate() & ~ios_base::eofbit);
- sentry __sen(*this, true);
- if (__sen)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
{
+#endif // _LIBCPP_NO_EXCEPTIONS
if (this->rdbuf() == 0 || this->rdbuf()->sputbackc(__c) == traits_type::eof())
- this->setstate(ios_base::badbit);
- }
- else
- this->setstate(ios_base::failbit);
+ __state |= ios_base::badbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
+ }
+ catch (...)
+ {
+ __state |= ios_base::badbit;
+ this->__setstate_nothrow(__state);
+ if (this->exceptions() & ios_base::badbit)
+ {
+ throw;
+ }
+ }
+#endif // _LIBCPP_NO_EXCEPTIONS
}
- catch (...)
+ else
{
- this->__set_badbit_and_consider_rethrow();
+ __state |= ios_base::failbit;
}
-#endif // _LIBCPP_NO_EXCEPTIONS
+ this->setstate(__state);
return *this;
}
@@ -1092,27 +1169,36 @@ template<class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::unget()
{
+ ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit;
__gc_ = 0;
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
+ this->clear(__state);
+ sentry __sen(*this, true);
+ if (__sen)
{
-#endif // _LIBCPP_NO_EXCEPTIONS
- this->clear(this->rdstate() & ~ios_base::eofbit);
- sentry __sen(*this, true);
- if (__sen)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
{
+#endif // _LIBCPP_NO_EXCEPTIONS
if (this->rdbuf() == 0 || this->rdbuf()->sungetc() == traits_type::eof())
- this->setstate(ios_base::badbit);
- }
- else
- this->setstate(ios_base::failbit);
+ __state |= ios_base::badbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
+ }
+ catch (...)
+ {
+ __state |= ios_base::badbit;
+ this->__setstate_nothrow(__state);
+ if (this->exceptions() & ios_base::badbit)
+ {
+ throw;
+ }
+ }
+#endif // _LIBCPP_NO_EXCEPTIONS
}
- catch (...)
+ else
{
- this->__set_badbit_and_consider_rethrow();
+ __state |= ios_base::failbit;
}
-#endif // _LIBCPP_NO_EXCEPTIONS
+ this->setstate(__state);
return *this;
}
@@ -1120,29 +1206,36 @@ template<class _CharT, class _Traits>
int
basic_istream<_CharT, _Traits>::sync()
{
+ ios_base::iostate __state = ios_base::goodbit;
int __r = 0;
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
+ sentry __sen(*this, true);
+ if (__sen)
{
-#endif // _LIBCPP_NO_EXCEPTIONS
- sentry __sen(*this, true);
- if (__sen)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
{
+#endif // _LIBCPP_NO_EXCEPTIONS
if (this->rdbuf() == 0)
return -1;
if (this->rdbuf()->pubsync() == -1)
{
- this->setstate(ios_base::badbit);
+ __state |= ios_base::badbit;
return -1;
}
- }
#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
+ }
+ catch (...)
+ {
+ __state |= ios_base::badbit;
+ this->__setstate_nothrow(__state);
+ if (this->exceptions() & ios_base::badbit)
+ {
+ throw;
+ }
+ }
#endif // _LIBCPP_NO_EXCEPTIONS
+ this->setstate(__state);
+ }
return __r;
}
@@ -1150,21 +1243,30 @@ template<class _CharT, class _Traits>
typename basic_istream<_CharT, _Traits>::pos_type
basic_istream<_CharT, _Traits>::tellg()
{
+ ios_base::iostate __state = ios_base::goodbit;
pos_type __r(-1);
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
+ sentry __sen(*this, true);
+ if (__sen)
{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
+ {
#endif // _LIBCPP_NO_EXCEPTIONS
- sentry __sen(*this, true);
- if (__sen)
- __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
+ __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
+ }
+ catch (...)
+ {
+ __state |= ios_base::badbit;
+ this->__setstate_nothrow(__state);
+ if (this->exceptions() & ios_base::badbit)
+ {
+ throw;
+ }
+ }
#endif // _LIBCPP_NO_EXCEPTIONS
+ this->setstate(__state);
+ }
return __r;
}
@@ -1172,24 +1274,31 @@ template<class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::seekg(pos_type __pos)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
+ ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit;
+ this->clear(__state);
+ sentry __sen(*this, true);
+ if (__sen)
{
-#endif // _LIBCPP_NO_EXCEPTIONS
- this->clear(this->rdstate() & ~ios_base::eofbit);
- sentry __sen(*this, true);
- if (__sen)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
{
+#endif // _LIBCPP_NO_EXCEPTIONS
if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1))
- this->setstate(ios_base::failbit);
- }
+ __state |= ios_base::failbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
+ }
+ catch (...)
+ {
+ __state |= ios_base::badbit;
+ this->__setstate_nothrow(__state);
+ if (this->exceptions() & ios_base::badbit)
+ {
+ throw;
+ }
+ }
#endif // _LIBCPP_NO_EXCEPTIONS
+ this->setstate(__state);
+ }
return *this;
}
@@ -1197,24 +1306,31 @@ template<class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
+ ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit;
+ this->clear(__state);
+ sentry __sen(*this, true);
+ if (__sen)
{
-#endif // _LIBCPP_NO_EXCEPTIONS
- this->clear(this->rdstate() & ~ios_base::eofbit);
- sentry __sen(*this, true);
- if (__sen)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
{
+#endif // _LIBCPP_NO_EXCEPTIONS
if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::in) == pos_type(-1))
- this->setstate(ios_base::failbit);
- }
+ __state |= ios_base::failbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
+ }
+ catch (...)
+ {
+ __state |= ios_base::badbit;
+ this->__setstate_nothrow(__state);
+ if (this->exceptions() & ios_base::badbit)
+ {
+ throw;
+ }
+ }
#endif // _LIBCPP_NO_EXCEPTIONS
+ this->setstate(__state);
+ }
return *this;
}
@@ -1222,34 +1338,41 @@ template <class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
ws(basic_istream<_CharT, _Traits>& __is)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
+ ios_base::iostate __state = ios_base::goodbit;
+ typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
+ if (__sen)
{
-#endif // _LIBCPP_NO_EXCEPTIONS
- typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
- if (__sen)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
{
+#endif // _LIBCPP_NO_EXCEPTIONS
const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
while (true)
{
typename _Traits::int_type __i = __is.rdbuf()->sgetc();
if (_Traits::eq_int_type(__i, _Traits::eof()))
{
- __is.setstate(ios_base::eofbit);
+ __state |= ios_base::eofbit;
break;
}
if (!__ct.is(__ct.space, _Traits::to_char_type(__i)))
break;
__is.rdbuf()->sbumpc();
}
- }
#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- __is.__set_badbit_and_consider_rethrow();
- }
+ }
+ catch (...)
+ {
+ __state |= ios_base::badbit;
+ __is.__setstate_nothrow(__state);
+ if (__is.exceptions() & ios_base::badbit)
+ {
+ throw;
+ }
+ }
#endif // _LIBCPP_NO_EXCEPTIONS
+ __is.setstate(__state);
+ }
return __is;
}
@@ -1298,7 +1421,6 @@ protected:
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
void swap(basic_iostream& __rhs)
{ basic_istream<char_type, traits_type>::swap(__rhs); }
-public:
};
#ifndef _LIBCPP_CXX03_LANG
@@ -1329,13 +1451,14 @@ basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is,
basic_string<_CharT, _Traits, _Allocator>& __str)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
+ ios_base::iostate __state = ios_base::goodbit;
+ typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
+ if (__sen)
{
-#endif // _LIBCPP_NO_EXCEPTIONS
- typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
- if (__sen)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
{
+#endif
__str.clear();
streamsize __n = __is.width();
if (__n <= 0)
@@ -1344,13 +1467,12 @@ operator>>(basic_istream<_CharT, _Traits>& __is,
__n = numeric_limits<streamsize>::max();
streamsize __c = 0;
const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
- ios_base::iostate __err = ios_base::goodbit;
while (__c < __n)
{
typename _Traits::int_type __i = __is.rdbuf()->sgetc();
if (_Traits::eq_int_type(__i, _Traits::eof()))
{
- __err |= ios_base::eofbit;
+ __state |= ios_base::eofbit;
break;
}
_CharT __ch = _Traits::to_char_type(__i);
@@ -1362,18 +1484,21 @@ operator>>(basic_istream<_CharT, _Traits>& __is,
}
__is.width(0);
if (__c == 0)
- __err |= ios_base::failbit;
- __is.setstate(__err);
- }
- else
- __is.setstate(ios_base::failbit);
+ __state |= ios_base::failbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
+ }
+ catch (...)
+ {
+ __state |= ios_base::badbit;
+ __is.__setstate_nothrow(__state);
+ if (__is.exceptions() & ios_base::badbit)
+ {
+ throw;
+ }
+ }
+#endif
+ __is.setstate(__state);
}
- catch (...)
- {
- __is.__set_badbit_and_consider_rethrow();
- }
-#endif // _LIBCPP_NO_EXCEPTIONS
return __is;
}
@@ -1382,22 +1507,22 @@ basic_istream<_CharT, _Traits>&
getline(basic_istream<_CharT, _Traits>& __is,
basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
+ ios_base::iostate __state = ios_base::goodbit;
+ typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
+ if (__sen)
{
-#endif // _LIBCPP_NO_EXCEPTIONS
- typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
- if (__sen)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
{
+#endif
__str.clear();
- ios_base::iostate __err = ios_base::goodbit;
streamsize __extr = 0;
while (true)
{
typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
if (_Traits::eq_int_type(__i, _Traits::eof()))
{
- __err |= ios_base::eofbit;
+ __state |= ios_base::eofbit;
break;
}
++__extr;
@@ -1407,21 +1532,26 @@ getline(basic_istream<_CharT, _Traits>& __is,
__str.push_back(__ch);
if (__str.size() == __str.max_size())
{
- __err |= ios_base::failbit;
+ __state |= ios_base::failbit;
break;
}
}
if (__extr == 0)
- __err |= ios_base::failbit;
- __is.setstate(__err);
- }
+ __state |= ios_base::failbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
+ }
+ catch (...)
+ {
+ __state |= ios_base::badbit;
+ __is.__setstate_nothrow(__state);
+ if (__is.exceptions() & ios_base::badbit)
+ {
+ throw;
+ }
+ }
+#endif
+ __is.setstate(__state);
}
- catch (...)
- {
- __is.__set_badbit_and_consider_rethrow();
- }
-#endif // _LIBCPP_NO_EXCEPTIONS
return __is;
}
@@ -1460,17 +1590,17 @@ template <class _CharT, class _Traits, size_t _Size>
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
{
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
+ ios_base::iostate __state = ios_base::goodbit;
+ typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
+ if (__sen)
{
-#endif // _LIBCPP_NO_EXCEPTIONS
- typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
- if (__sen)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
{
+#endif
basic_string<_CharT, _Traits> __str;
const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
size_t __c = 0;
- ios_base::iostate __err = ios_base::goodbit;
_CharT __zero = __ct.widen('0');
_CharT __one = __ct.widen('1');
while (__c < _Size)
@@ -1478,7 +1608,7 @@ operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
typename _Traits::int_type __i = __is.rdbuf()->sgetc();
if (_Traits::eq_int_type(__i, _Traits::eof()))
{
- __err |= ios_base::eofbit;
+ __state |= ios_base::eofbit;
break;
}
_CharT __ch = _Traits::to_char_type(__i);
@@ -1490,18 +1620,21 @@ operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
}
__x = bitset<_Size>(__str);
if (__c == 0)
- __err |= ios_base::failbit;
- __is.setstate(__err);
- }
- else
- __is.setstate(ios_base::failbit);
+ __state |= ios_base::failbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
+ }
+ catch (...)
+ {
+ __state |= ios_base::badbit;
+ __is.__setstate_nothrow(__state);
+ if (__is.exceptions() & ios_base::badbit)
+ {
+ throw;
+ }
+ }
+#endif
+ __is.setstate(__state);
}
- catch (...)
- {
- __is.__set_badbit_and_consider_rethrow();
- }
-#endif // _LIBCPP_NO_EXCEPTIONS
return __is;
}