Blame SOURCES/gcc48-rh1469384.patch

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