Blame SOURCES/gcc48-rh1469384.patch

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