]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR libstdc++/26211 + N3168
authorPaolo Carlini <paolo.carlini@oracle.com>
Thu, 18 Nov 2010 17:21:35 +0000 (17:21 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Thu, 18 Nov 2010 17:21:35 +0000 (17:21 +0000)
2010-11-18  Paolo Carlini  <paolo.carlini@oracle.com>

PR libstdc++/26211 + N3168
* include/bits/istream.tcc (basic_istream<>::tellg, seekg(pos_type),
seekg(off_type, ios_base::seekdir)): Construct a sentry.
(basic_istream<>::tellg, seekg(pos_type), seekg(off_type,
ios_base::seekdir, putback, unget)): Clear eofbit first, per N3168.
* testsuite/27_io/basic_istream/seekg/char/26211.cc: New.
* testsuite/27_io/basic_istream/seekg/wchar_t/26211.cc: Likewise.
* testsuite/27_io/basic_istream/tellg/char/26211.cc: Likewise.
* testsuite/27_io/basic_istream/tellg/wchar_t/26211.cc: Likewise.
* testsuite/27_io/basic_istream/tellg/char/8348.cc: Tweak.
* testsuite/27_io/basic_istream/tellg/wchar_t/8348.cc: Likewise.

From-SVN: r166911

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/istream.tcc
libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/26211.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/26211.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/26211.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/8348.cc
libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/26211.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/8348.cc

index 3d5dc45487669beb92605aa9c2b13c64f31f2113..49d7d4744175240c54273b15101e2a4407292318 100644 (file)
@@ -1,3 +1,17 @@
+2010-11-18  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR libstdc++/26211 + N3168
+       * include/bits/istream.tcc (basic_istream<>::tellg, seekg(pos_type),
+       seekg(off_type, ios_base::seekdir)): Construct a sentry.
+       (basic_istream<>::tellg, seekg(pos_type), seekg(off_type,
+       ios_base::seekdir, putback, unget)): Clear eofbit first, per N3168.
+       * testsuite/27_io/basic_istream/seekg/char/26211.cc: New.
+       * testsuite/27_io/basic_istream/seekg/wchar_t/26211.cc: Likewise.
+       * testsuite/27_io/basic_istream/tellg/char/26211.cc: Likewise.
+       * testsuite/27_io/basic_istream/tellg/wchar_t/26211.cc: Likewise.
+       * testsuite/27_io/basic_istream/tellg/char/8348.cc: Tweak.
+       * testsuite/27_io/basic_istream/tellg/wchar_t/8348.cc: Likewise.
+
 2010-11-18  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR other/42670
index d005f736f03d9b4e831bb2e2aa72684bf1f62258..e0a4cd3a0945d755cf6e89ac3ed73085dc1a3473 100644 (file)
@@ -1,7 +1,7 @@
 // istream classes -*- C++ -*-
 
 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-// 2006, 2007, 2008, 2009
+// 2006, 2007, 2008, 2009, 2010
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -713,6 +713,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
       // 60. What is a formatted input function?
       _M_gcount = 0;
+      // Clear eofbit per N3168.
+      this->clear(this->rdstate() & ~ios_base::eofbit);
       sentry __cerb(*this, true);
       if (__cerb)
        {
@@ -746,6 +748,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
       // 60. What is a formatted input function?
       _M_gcount = 0;
+      // Clear eofbit per N3168.
+      this->clear(this->rdstate() & ~ios_base::eofbit);
       sentry __cerb(*this, true);
       if (__cerb)
        {
@@ -815,19 +819,23 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
       // DR60.  Do not change _M_gcount.
       pos_type __ret = pos_type(-1);
-      __try
-       {
-         if (!this->fail())
-           __ret = this->rdbuf()->pubseekoff(0, ios_base::cur,
-                                             ios_base::in);
-       }
-      __catch(__cxxabiv1::__forced_unwind&)
+      sentry __cerb(*this, true);
+      if (__cerb)
        {
-         this->_M_setstate(ios_base::badbit);
-         __throw_exception_again;
+         __try
+           {
+             if (!this->fail())
+               __ret = this->rdbuf()->pubseekoff(0, ios_base::cur,
+                                                 ios_base::in);
+           }
+         __catch(__cxxabiv1::__forced_unwind&)
+           {
+             this->_M_setstate(ios_base::badbit);
+             __throw_exception_again;
+           }
+         __catch(...)
+           { this->_M_setstate(ios_base::badbit); }
        }
-      __catch(...)
-       { this->_M_setstate(ios_base::badbit); }
       return __ret;
     }
 
@@ -838,29 +846,35 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     {
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
       // DR60.  Do not change _M_gcount.
-      ios_base::iostate __err = ios_base::goodbit;
-      __try
+      // Clear eofbit per N3168.
+      this->clear(this->rdstate() & ~ios_base::eofbit);
+      sentry __cerb(*this, true);
+      if (__cerb)
        {
-         if (!this->fail())
+         ios_base::iostate __err = ios_base::goodbit;
+         __try
            {
-             // 136.  seekp, seekg setting wrong streams?
-             const pos_type __p = this->rdbuf()->pubseekpos(__pos,
-                                                            ios_base::in);
-             
-             // 129.  Need error indication from seekp() and seekg()
-             if (__p == pos_type(off_type(-1)))
-               __err |= ios_base::failbit;
+             if (!this->fail())
+               {
+                 // 136.  seekp, seekg setting wrong streams?
+                 const pos_type __p = this->rdbuf()->pubseekpos(__pos,
+                                                                ios_base::in);
+                 
+                 // 129.  Need error indication from seekp() and seekg()
+                 if (__p == pos_type(off_type(-1)))
+                   __err |= ios_base::failbit;
+               }
            }
+         __catch(__cxxabiv1::__forced_unwind&)
+           {
+             this->_M_setstate(ios_base::badbit);
+             __throw_exception_again;
+           }
+         __catch(...)
+           { this->_M_setstate(ios_base::badbit); }
+         if (__err)
+           this->setstate(__err);
        }
-      __catch(__cxxabiv1::__forced_unwind&)
-       {
-         this->_M_setstate(ios_base::badbit);
-         __throw_exception_again;
-       }
-      __catch(...)
-       { this->_M_setstate(ios_base::badbit); }
-      if (__err)
-       this->setstate(__err);
       return *this;
     }
 
@@ -871,29 +885,35 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     {
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
       // DR60.  Do not change _M_gcount.
-      ios_base::iostate __err = ios_base::goodbit;
-      __try
+      // Clear eofbit per N3168.
+      this->clear(this->rdstate() & ~ios_base::eofbit);
+      sentry __cerb(*this, true);
+      if (__cerb)
        {
-         if (!this->fail())
+         ios_base::iostate __err = ios_base::goodbit;
+         __try
            {
-             // 136.  seekp, seekg setting wrong streams?
-             const pos_type __p = this->rdbuf()->pubseekoff(__off, __dir,
-                                                            ios_base::in);
+             if (!this->fail())
+               {
+                 // 136.  seekp, seekg setting wrong streams?
+                 const pos_type __p = this->rdbuf()->pubseekoff(__off, __dir,
+                                                                ios_base::in);
              
-             // 129.  Need error indication from seekp() and seekg()
-             if (__p == pos_type(off_type(-1)))
-               __err |= ios_base::failbit;
+                 // 129.  Need error indication from seekp() and seekg()
+                 if (__p == pos_type(off_type(-1)))
+                   __err |= ios_base::failbit;
+               }
            }
+         __catch(__cxxabiv1::__forced_unwind&)
+           {
+             this->_M_setstate(ios_base::badbit);
+             __throw_exception_again;
+           }
+         __catch(...)
+           { this->_M_setstate(ios_base::badbit); }
+         if (__err)
+           this->setstate(__err);
        }
-      __catch(__cxxabiv1::__forced_unwind&)
-       {
-         this->_M_setstate(ios_base::badbit);
-         __throw_exception_again;
-       }
-      __catch(...)
-       { this->_M_setstate(ios_base::badbit); }
-      if (__err)
-       this->setstate(__err);
       return *this;
     }
 
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/26211.cc b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/26211.cc
new file mode 100644 (file)
index 0000000..be28650
--- /dev/null
@@ -0,0 +1,63 @@
+// 2010-11-18  Paolo Carlini  <paolo.carlini@oracle.com>
+
+// Copyright (C) 2010 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <istream>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/26211
+void test01()
+{
+  using namespace std;
+  bool test __attribute__((unused)) = true;
+
+  typedef istringstream::pos_type pos_type;
+
+  istringstream iss("Duos for Doris");
+  ostringstream oss;
+
+  const pos_type p0 = iss.tellg();
+  VERIFY( p0 == pos_type(0) );
+
+  iss >> oss.rdbuf();
+  VERIFY( iss.rdstate() == iss.eofbit );
+
+  iss.seekg(0, ios_base::beg);
+  VERIFY( iss.good() );
+
+  iss.seekg(0, ios_base::beg);
+  VERIFY( !iss.fail() );
+  VERIFY( iss.tellg() == p0 );
+
+  iss >> oss.rdbuf();
+  VERIFY( iss.rdstate() == iss.eofbit );
+
+  iss.seekg(p0);
+  VERIFY( iss.good() );
+
+  iss.seekg(p0);
+  VERIFY( !iss.fail() );
+  VERIFY( iss.tellg() == p0 );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/26211.cc b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/26211.cc
new file mode 100644 (file)
index 0000000..2a73e1e
--- /dev/null
@@ -0,0 +1,63 @@
+// 2010-11-18  Paolo Carlini  <paolo.carlini@oracle.com>
+
+// Copyright (C) 2010 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <istream>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/26211
+void test01()
+{
+  using namespace std;
+  bool test __attribute__((unused)) = true;
+
+  typedef wistringstream::pos_type pos_type;
+
+  wistringstream iss(L"Duos for Doris");
+  wostringstream oss;
+
+  const pos_type p0 = iss.tellg();
+  VERIFY( p0 == pos_type(0) );
+
+  iss >> oss.rdbuf();
+  VERIFY( iss.rdstate() == iss.eofbit );
+
+  iss.seekg(0, ios_base::beg);
+  VERIFY( iss.good() );
+
+  iss.seekg(0, ios_base::beg);
+  VERIFY( !iss.fail() );
+  VERIFY( iss.tellg() == p0 );
+
+  iss >> oss.rdbuf();
+  VERIFY( iss.rdstate() == iss.eofbit );
+
+  iss.seekg(p0);
+  VERIFY( iss.good() );
+
+  iss.seekg(p0);
+  VERIFY( !iss.fail() );
+  VERIFY( iss.tellg() == p0 );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/26211.cc b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/26211.cc
new file mode 100644 (file)
index 0000000..6677f94
--- /dev/null
@@ -0,0 +1,49 @@
+// 2010-11-18  Paolo Carlini  <paolo.carlini@oracle.com>
+
+// Copyright (C) 2010 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <istream>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/26211
+void test01()
+{
+  using namespace std;
+  bool test __attribute__((unused)) = true;
+
+  typedef istringstream::pos_type pos_type;
+
+  istringstream iss("Duos for Doris");
+  ostringstream oss;
+
+  VERIFY( iss.tellg() == pos_type(0) );
+
+  iss >> oss.rdbuf();
+  VERIFY( iss.rdstate() == iss.eofbit );
+  VERIFY( iss.tellg() == pos_type(-1) );
+
+  iss.clear();
+  VERIFY( iss.tellg() == pos_type(14) );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
index e4b4914ef48a47b62fc9d0c4e7299bf4f8b3cf53..62bdd502597afbd20c4cbcb9b97a94658c9b10c7 100644 (file)
@@ -40,6 +40,7 @@ void test06(void)
     iss >> asNum;
     VERIFY( test = iss.eof() );
     VERIFY( test = !iss.fail() );
+    iss.clear();
     iss.tellg();
     VERIFY( test = !iss.fail() );
   }
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/26211.cc b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/26211.cc
new file mode 100644 (file)
index 0000000..7d88d5c
--- /dev/null
@@ -0,0 +1,49 @@
+// 2010-11-18  Paolo Carlini  <paolo.carlini@oracle.com>
+
+// Copyright (C) 2010 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <istream>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/26211
+void test01()
+{
+  using namespace std;
+  bool test __attribute__((unused)) = true;
+
+  typedef wistringstream::pos_type pos_type;
+
+  wistringstream iss(L"Duos for Doris");
+  wostringstream oss;
+
+  VERIFY( iss.tellg() == pos_type(0) );
+
+  iss >> oss.rdbuf();
+  VERIFY( iss.rdstate() == iss.eofbit );
+  VERIFY( iss.tellg() == pos_type(-1) );
+
+  iss.clear();
+  VERIFY( iss.tellg() == pos_type(14) );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
index 61613817b4ddbf3e6e6694d2475cc5a1f5989d0c..6979b9c06f8bfefec9e467d4b2c56acc965e50a1 100644 (file)
@@ -37,6 +37,7 @@ void test06(void)
     iss >> asNum;
     VERIFY( test = iss.eof() );
     VERIFY( test = !iss.fail() );
+    iss.clear();
     iss.tellg();
     VERIFY( test = !iss.fail() );
   }