Blame SOURCES/gcc48-rh1469384.patch

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