|
|
001c85 |
2017-07-25 Jonathan Wakely <jwakely@redhat.com>
|
|
|
001c85 |
|
|
|
001c85 |
PR libstdc++/53984
|
|
|
001c85 |
* include/bits/basic_ios.h (basic_ios::_M_setstate): Adjust comment.
|
|
|
001c85 |
* include/bits/istream.tcc (basic_istream::sentry): Handle exceptions
|
|
|
001c85 |
during construction.
|
|
|
001c85 |
* include/std/istream: Adjust comments for formatted input functions
|
|
|
001c85 |
and unformatted input functions.
|
|
|
001c85 |
* testsuite/27_io/basic_fstream/53984.cc: New.
|
|
|
001c85 |
* testsuite/27_io/basic_istream/sentry/char/53984.cc: New.
|
|
|
001c85 |
|
|
|
001c85 |
--- libstdc++-v3/include/bits/basic_ios.h
|
|
|
001c85 |
+++ libstdc++-v3/include/bits/basic_ios.h
|
|
|
001c85 |
@@ -157,8 +157,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|
|
001c85 |
setstate(iostate __state)
|
|
|
001c85 |
{ this->clear(this->rdstate() | __state); }
|
|
|
001c85 |
|
|
|
001c85 |
- // Flip the internal state on for the proper state bits, then re
|
|
|
001c85 |
- // throws the propagated exception if bit also set in
|
|
|
001c85 |
+ // Flip the internal state on for the proper state bits, then
|
|
|
001c85 |
+ // rethrows the propagated exception if bit also set in
|
|
|
001c85 |
// exceptions().
|
|
|
001c85 |
void
|
|
|
001c85 |
_M_setstate(iostate __state)
|
|
|
001c85 |
--- libstdc++-v3/include/bits/istream.tcc
|
|
|
001c85 |
+++ libstdc++-v3/include/bits/istream.tcc
|
|
|
001c85 |
@@ -48,28 +48,36 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|
|
001c85 |
{
|
|
|
001c85 |
ios_base::iostate __err = ios_base::goodbit;
|
|
|
001c85 |
if (__in.good())
|
|
|
001c85 |
- {
|
|
|
001c85 |
- if (__in.tie())
|
|
|
001c85 |
- __in.tie()->flush();
|
|
|
001c85 |
- if (!__noskip && bool(__in.flags() & ios_base::skipws))
|
|
|
001c85 |
- {
|
|
|
001c85 |
- const __int_type __eof = traits_type::eof();
|
|
|
001c85 |
- __streambuf_type* __sb = __in.rdbuf();
|
|
|
001c85 |
- __int_type __c = __sb->sgetc();
|
|
|
001c85 |
-
|
|
|
001c85 |
- const __ctype_type& __ct = __check_facet(__in._M_ctype);
|
|
|
001c85 |
- while (!traits_type::eq_int_type(__c, __eof)
|
|
|
001c85 |
- && __ct.is(ctype_base::space,
|
|
|
001c85 |
- traits_type::to_char_type(__c)))
|
|
|
001c85 |
- __c = __sb->snextc();
|
|
|
001c85 |
+ __try
|
|
|
001c85 |
+ {
|
|
|
001c85 |
+ if (__in.tie())
|
|
|
001c85 |
+ __in.tie()->flush();
|
|
|
001c85 |
+ if (!__noskip && bool(__in.flags() & ios_base::skipws))
|
|
|
001c85 |
+ {
|
|
|
001c85 |
+ const __int_type __eof = traits_type::eof();
|
|
|
001c85 |
+ __streambuf_type* __sb = __in.rdbuf();
|
|
|
001c85 |
+ __int_type __c = __sb->sgetc();
|
|
|
001c85 |
+
|
|
|
001c85 |
+ const __ctype_type& __ct = __check_facet(__in._M_ctype);
|
|
|
001c85 |
+ while (!traits_type::eq_int_type(__c, __eof)
|
|
|
001c85 |
+ && __ct.is(ctype_base::space,
|
|
|
001c85 |
+ traits_type::to_char_type(__c)))
|
|
|
001c85 |
+ __c = __sb->snextc();
|
|
|
001c85 |
|
|
|
001c85 |
- // _GLIBCXX_RESOLVE_LIB_DEFECTS
|
|
|
001c85 |
- // 195. Should basic_istream::sentry's constructor ever
|
|
|
001c85 |
- // set eofbit?
|
|
|
001c85 |
- if (traits_type::eq_int_type(__c, __eof))
|
|
|
001c85 |
- __err |= ios_base::eofbit;
|
|
|
001c85 |
- }
|
|
|
001c85 |
- }
|
|
|
001c85 |
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
|
|
|
001c85 |
+ // 195. Should basic_istream::sentry's constructor ever
|
|
|
001c85 |
+ // set eofbit?
|
|
|
001c85 |
+ if (traits_type::eq_int_type(__c, __eof))
|
|
|
001c85 |
+ __err |= ios_base::eofbit;
|
|
|
001c85 |
+ }
|
|
|
001c85 |
+ }
|
|
|
001c85 |
+ __catch(__cxxabiv1::__forced_unwind&)
|
|
|
001c85 |
+ {
|
|
|
001c85 |
+ __in._M_setstate(ios_base::badbit);
|
|
|
001c85 |
+ __throw_exception_again;
|
|
|
001c85 |
+ }
|
|
|
001c85 |
+ __catch(...)
|
|
|
001c85 |
+ { __in._M_setstate(ios_base::badbit); }
|
|
|
001c85 |
|
|
|
001c85 |
if (__in.good() && __err == ios_base::goodbit)
|
|
|
001c85 |
_M_ok = true;
|
|
|
001c85 |
--- libstdc++-v3/include/std/istream
|
|
|
001c85 |
+++ libstdc++-v3/include/std/istream
|
|
|
001c85 |
@@ -150,9 +150,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|
|
001c85 |
* whatever data is appropriate for the type of the argument.
|
|
|
001c85 |
*
|
|
|
001c85 |
* If an exception is thrown during extraction, ios_base::badbit
|
|
|
001c85 |
- * will be turned on in the stream's error state without causing an
|
|
|
001c85 |
- * ios_base::failure to be thrown. The original exception will then
|
|
|
001c85 |
- * be rethrown.
|
|
|
001c85 |
+ * will be turned on in the stream's error state (without causing an
|
|
|
001c85 |
+ * ios_base::failure to be thrown) and the original exception will
|
|
|
001c85 |
+ * be rethrown if badbit is set in the exceptions mask.
|
|
|
001c85 |
*/
|
|
|
001c85 |
|
|
|
001c85 |
//@{
|
|
|
001c85 |
@@ -286,9 +286,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|
|
001c85 |
* by gcount().
|
|
|
001c85 |
*
|
|
|
001c85 |
* If an exception is thrown during extraction, ios_base::badbit
|
|
|
001c85 |
- * will be turned on in the stream's error state without causing an
|
|
|
001c85 |
- * ios_base::failure to be thrown. The original exception will then
|
|
|
001c85 |
- * be rethrown.
|
|
|
001c85 |
+ * will be turned on in the stream's error state (without causing an
|
|
|
001c85 |
+ * ios_base::failure to be thrown) and the original exception will
|
|
|
001c85 |
+ * be rethrown if badbit is set in the exceptions mask.
|
|
|
001c85 |
*/
|
|
|
001c85 |
|
|
|
001c85 |
/**
|
|
|
001c85 |
--- /dev/null
|
|
|
001c85 |
+++ libstdc++-v3/testsuite/27_io/basic_fstream/53984.cc
|
|
|
001c85 |
@@ -0,0 +1,64 @@
|
|
|
001c85 |
+// Copyright (C) 2017 Free Software Foundation, Inc.
|
|
|
001c85 |
+//
|
|
|
001c85 |
+// This file is part of the GNU ISO C++ Library. This library is free
|
|
|
001c85 |
+// software; you can redistribute it and/or modify it under the
|
|
|
001c85 |
+// terms of the GNU General Public License as published by the
|
|
|
001c85 |
+// Free Software Foundation; either version 3, or (at your option)
|
|
|
001c85 |
+// any later version.
|
|
|
001c85 |
+
|
|
|
001c85 |
+// This library is distributed in the hope that it will be useful,
|
|
|
001c85 |
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
001c85 |
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
001c85 |
+// GNU General Public License for more details.
|
|
|
001c85 |
+
|
|
|
001c85 |
+// You should have received a copy of the GNU General Public License along
|
|
|
001c85 |
+// with this library; see the file COPYING3. If not see
|
|
|
001c85 |
+// <http://www.gnu.org/licenses/>.
|
|
|
001c85 |
+
|
|
|
001c85 |
+// { dg-require-fileio "" }
|
|
|
001c85 |
+
|
|
|
001c85 |
+// PR libstdc++/53984
|
|
|
001c85 |
+
|
|
|
001c85 |
+#include <fstream>
|
|
|
001c85 |
+#include <testsuite_hooks.h>
|
|
|
001c85 |
+
|
|
|
001c85 |
+void
|
|
|
001c85 |
+test01()
|
|
|
001c85 |
+{
|
|
|
001c85 |
+ std::ifstream in(".");
|
|
|
001c85 |
+ if (in)
|
|
|
001c85 |
+ {
|
|
|
001c85 |
+ char c;
|
|
|
001c85 |
+ if (in.get(c))
|
|
|
001c85 |
+ {
|
|
|
001c85 |
+ // Reading a directory doesn't produce an error on this target
|
|
|
001c85 |
+ // so the formatted input functions below wouldn't fail anyway
|
|
|
001c85 |
+ // (see PR libstdc++/81808).
|
|
|
001c85 |
+ return;
|
|
|
001c85 |
+ }
|
|
|
001c85 |
+ int x;
|
|
|
001c85 |
+ in.clear();
|
|
|
001c85 |
+ // Formatted input function should set badbit, but not throw:
|
|
|
001c85 |
+ in >> x;
|
|
|
001c85 |
+ VERIFY( in.bad() );
|
|
|
001c85 |
+
|
|
|
001c85 |
+ in.clear();
|
|
|
001c85 |
+ in.exceptions(std::ios::badbit);
|
|
|
001c85 |
+ try
|
|
|
001c85 |
+ {
|
|
|
001c85 |
+ // Formatted input function should set badbit, and throw:
|
|
|
001c85 |
+ in >> x;
|
|
|
001c85 |
+ VERIFY( false );
|
|
|
001c85 |
+ }
|
|
|
001c85 |
+ catch (const std::exception&)
|
|
|
001c85 |
+ {
|
|
|
001c85 |
+ VERIFY( in.bad() );
|
|
|
001c85 |
+ }
|
|
|
001c85 |
+ }
|
|
|
001c85 |
+}
|
|
|
001c85 |
+
|
|
|
001c85 |
+int
|
|
|
001c85 |
+main()
|
|
|
001c85 |
+{
|
|
|
001c85 |
+ test01();
|
|
|
001c85 |
+}
|
|
|
001c85 |
--- /dev/null
|
|
|
001c85 |
+++ libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/53984.cc
|
|
|
001c85 |
@@ -0,0 +1,41 @@
|
|
|
001c85 |
+// Copyright (C) 2017 Free Software Foundation, Inc.
|
|
|
001c85 |
+//
|
|
|
001c85 |
+// This file is part of the GNU ISO C++ Library. This library is free
|
|
|
001c85 |
+// software; you can redistribute it and/or modify it under the
|
|
|
001c85 |
+// terms of the GNU General Public License as published by the
|
|
|
001c85 |
+// Free Software Foundation; either version 3, or (at your option)
|
|
|
001c85 |
+// any later version.
|
|
|
001c85 |
+
|
|
|
001c85 |
+// This library is distributed in the hope that it will be useful,
|
|
|
001c85 |
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
001c85 |
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
001c85 |
+// GNU General Public License for more details.
|
|
|
001c85 |
+
|
|
|
001c85 |
+// You should have received a copy of the GNU General Public License along
|
|
|
001c85 |
+// with this library; see the file COPYING3. If not see
|
|
|
001c85 |
+// <http://www.gnu.org/licenses/>.
|
|
|
001c85 |
+
|
|
|
001c85 |
+#include <streambuf>
|
|
|
001c85 |
+#include <istream>
|
|
|
001c85 |
+#include <testsuite_hooks.h>
|
|
|
001c85 |
+
|
|
|
001c85 |
+struct SB : std::streambuf
|
|
|
001c85 |
+{
|
|
|
001c85 |
+ virtual int_type underflow() { throw 1; }
|
|
|
001c85 |
+};
|
|
|
001c85 |
+
|
|
|
001c85 |
+void
|
|
|
001c85 |
+test01()
|
|
|
001c85 |
+{
|
|
|
001c85 |
+ SB sb;
|
|
|
001c85 |
+ std::istream is(&sb);
|
|
|
001c85 |
+ int i;
|
|
|
001c85 |
+ is >> i;
|
|
|
001c85 |
+ VERIFY( is.bad() );
|
|
|
001c85 |
+}
|
|
|
001c85 |
+
|
|
|
001c85 |
+int
|
|
|
001c85 |
+main()
|
|
|
001c85 |
+{
|
|
|
001c85 |
+ test01();
|
|
|
001c85 |
+}
|