Blame SOURCES/gcc48-rh1469384.patch

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