]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libstdc++/26211 ([DR 419, US 137 / US 139] basic_istream::tellg, seekg are...
authorPaolo Carlini <pcarlini@suse.de>
Sun, 12 Feb 2006 16:09:41 +0000 (16:09 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Sun, 12 Feb 2006 16:09:41 +0000 (16:09 +0000)
2006-02-12  Paolo Carlini  <pcarlini@suse.de>

PR libstdc++/26211
* include/bits/istream.tcc (basic_istream<>::tellg, seekg(pos_type),
seekg(off_type, ios_base::seekdir)): Construct a sentry, as per
27.6.1.3/1.
* 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/seekg/char/8348-1.cc: Adjust.
* testsuite/27_io/basic_istream/seekg/wchar_t/8348-1.cc: Likewise.
* testsuite/27_io/basic_istream/seekg/char/8348-2.cc: Likewise.
* testsuite/27_io/basic_istream/seekg/wchar_t/8348-1.cc: Likewise.
* testsuite/27_io/basic_istream/tellg/char/8348.cc: Likewise.
* testsuite/27_io/basic_istream/tellg/wchar_t/8348.cc: Likewise.

From-SVN: r110891

12 files changed:
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/char/8348-1.cc
libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/8348-2.cc
libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/26211.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/8348-1.cc
libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/8348-2.cc
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 85fe6bbc679a11ae93143171a32d556dcaf9b6e7..3d2ef2ec08893412dc5e3b581957457c193464e9 100644 (file)
@@ -1,4 +1,21 @@
-2006-10-02  Paolo Carlini  <pcarlini@suse.de>
+2006-02-12  Paolo Carlini  <pcarlini@suse.de>
+
+       PR libstdc++/26211
+       * include/bits/istream.tcc (basic_istream<>::tellg, seekg(pos_type),
+       seekg(off_type, ios_base::seekdir)): Construct a sentry, as per
+       27.6.1.3/1.
+       * 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/seekg/char/8348-1.cc: Adjust.
+       * testsuite/27_io/basic_istream/seekg/wchar_t/8348-1.cc: Likewise.
+       * testsuite/27_io/basic_istream/seekg/char/8348-2.cc: Likewise.
+       * testsuite/27_io/basic_istream/seekg/wchar_t/8348-1.cc: Likewise.
+       * testsuite/27_io/basic_istream/tellg/char/8348.cc: Likewise.
+       * testsuite/27_io/basic_istream/tellg/wchar_t/8348.cc: Likewise.
+
+2006-02-10  Paolo Carlini  <pcarlini@suse.de>
 
        PR libstdc++/26181
        * include/bits/streambuf.tcc (__copy_streambufs_eof): New, like
index ef773bc7080bbbe855dc2d0ae155726191ec5211..db3e96e00e11043c9f9ca60c4a51961df9615a7c 100644 (file)
@@ -711,13 +711,18 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
       // DR60.  Do not change _M_gcount.
       pos_type __ret = pos_type(-1);
-      try
+      sentry __cerb(*this, true);
+      if (__cerb)
        {
-         if (!this->fail())
-           __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
+         try
+           {
+             if (!this->fail())
+               __ret = this->rdbuf()->pubseekoff(0, ios_base::cur,
+                                                 ios_base::in);
+           }
+         catch(...)
+           { this->_M_setstate(ios_base::badbit); }
        }
-      catch(...)
-       { this->_M_setstate(ios_base::badbit); }
       return __ret;
     }
 
@@ -728,24 +733,28 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     {
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
       // DR60.  Do not change _M_gcount.
-      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
-      try
+      sentry __cerb(*this, true);
+      if (__cerb)
        {
-         if (!this->fail())
+         ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
+         try
            {
-             // 136.  seekp, seekg setting wrong streams?
-             const pos_type __p = this->rdbuf()->pubseekpos(__pos,
-                                                            ios_base::in);
+             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;
+                 // 129. Need error indication from seekp() and seekg()
+                 if (__p == pos_type(off_type(-1)))
+                   __err |= ios_base::failbit;
+               }
            }
+         catch(...)
+           { this->_M_setstate(ios_base::badbit); }
+         if (__err)
+           this->setstate(__err);
        }
-      catch(...)
-       { this->_M_setstate(ios_base::badbit); }
-      if (__err)
-       this->setstate(__err);
       return *this;
     }
 
@@ -756,24 +765,28 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     {
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
       // DR60.  Do not change _M_gcount.
-      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
-      try
+      sentry __cerb(*this, true);
+      if (__cerb)
        {
-         if (!this->fail())
+         ios_base::iostate __err = ios_base::iostate(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(...)
+           { this->_M_setstate(ios_base::badbit); }
+         if (__err)
+           this->setstate(__err);
        }
-      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..4c333d3
--- /dev/null
@@ -0,0 +1,64 @@
+// Copyright (C) 2006 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+#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.fail() );
+
+  iss.clear();
+  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.fail() );
+
+  iss.clear();
+  iss.seekg(p0);
+  VERIFY( !iss.fail() );
+  VERIFY( iss.tellg() == p0 );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
index ec01b61c2ab85c6934e5e795875b15029c81a70c..8e2515767713c59366f9cdd6f91ed28e5a7a7eb5 100644 (file)
@@ -1,6 +1,7 @@
 // 2000-06-29 bkoz
 
-// Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation
+// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006
+// 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
@@ -40,6 +41,7 @@ void test06(void)
     iss >> asNum;
     VERIFY( test = iss.eof() );
     VERIFY( test = !iss.fail() );
+    iss.clear();
     iss.seekg(pos1);
     VERIFY( test = !iss.fail() );
   }
index 163e8050b3ddf152adf693e848015301d12da5ab..25f528919958fc441dd3068fe5a6be3bd78f99a1 100644 (file)
@@ -1,6 +1,7 @@
 // 2000-06-29 bkoz
 
-// Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation
+// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006
+// 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
@@ -40,6 +41,7 @@ void test06(void)
     iss >> asNum;
     VERIFY( test = iss.eof() );
     VERIFY( test = !iss.fail() );
+    iss.clear();
     iss.seekg(0, ios_base::beg);
     VERIFY( test = !iss.fail() );
   }
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..3397238
--- /dev/null
@@ -0,0 +1,64 @@
+// Copyright (C) 2006 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+#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.fail() );
+
+  iss.clear();
+  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.fail() );
+
+  iss.clear();
+  iss.seekg(p0);
+  VERIFY( !iss.fail() );
+  VERIFY( iss.tellg() == p0 );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
index dfc6034767d874dabd9f4255b872af389955871d..86cf286fcaa2c55dc0d042af330d1eccfbe96479 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2004 Free Software Foundation
+// Copyright (C) 2004, 2005, 2006 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
@@ -39,6 +39,7 @@ void test06(void)
     VERIFY( test = iss.eof() );
     VERIFY( test = !iss.fail() );
     iss.seekg(pos1);
+    iss.clear();
     VERIFY( test = !iss.fail() );
   }
 }
index 151871dfa99da7631451a6e86facb2732ea938a1..fc9bf9c7d7a550748401c9e762cb75aaae144dc9 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2004 Free Software Foundation
+// Copyright (C) 2004, 2005, 2006 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
@@ -38,6 +38,7 @@ void test06(void)
     iss >> asNum;
     VERIFY( test = iss.eof() );
     VERIFY( test = !iss.fail() );
+    iss.clear();
     iss.seekg(0, ios_base::beg);
     VERIFY( test = !iss.fail() );
   }
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..f7b6b90
--- /dev/null
@@ -0,0 +1,48 @@
+// Copyright (C) 2006 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+#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 fb121f72d712c4b8dffeee78c5fbc241dea382da..ba219fcb5dd548be75a6e8d56bf392168570b134 100644 (file)
@@ -1,6 +1,7 @@
 // 2000-06-29 bkoz
 
-// Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation
+// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006
+// 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
@@ -40,6 +41,7 @@ void test06(void)
     iss >> asNum;
     VERIFY( test = iss.eof() );
     VERIFY( test = !iss.fail() );
+    iss.clear();
     iss.tellg();
     VERIFY( test = !iss.fail() );
   }
@@ -52,6 +54,7 @@ void test06(void)
     iss >> asNum;
     VERIFY( test = iss.eof() );
     VERIFY( test = !iss.fail() );
+    iss.clear();
     iss.seekg(0, ios_base::beg);
     VERIFY( test = !iss.fail() );
   }
@@ -64,6 +67,7 @@ void test06(void)
     iss >> asNum;
     VERIFY( test = iss.eof() );
     VERIFY( test = !iss.fail() );
+    iss.clear();
     iss.seekg(pos1);
     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..c61e83e
--- /dev/null
@@ -0,0 +1,48 @@
+// Copyright (C) 2006 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+#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 467c73fdef0c475ae3c2ab0ca682e88345edfba4..36ed2346b7857a70e2ad672628215fbc4b1cb4b1 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2004 Free Software Foundation
+// Copyright (C) 2004, 2005, 2006 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
@@ -38,6 +38,7 @@ void test06(void)
     iss >> asNum;
     VERIFY( test = iss.eof() );
     VERIFY( test = !iss.fail() );
+    iss.clear();
     iss.tellg();
     VERIFY( test = !iss.fail() );
   }
@@ -50,6 +51,7 @@ void test06(void)
     iss >> asNum;
     VERIFY( test = iss.eof() );
     VERIFY( test = !iss.fail() );
+    iss.clear();
     iss.seekg(0, ios_base::beg);
     VERIFY( test = !iss.fail() );
   }
@@ -62,6 +64,7 @@ void test06(void)
     iss >> asNum;
     VERIFY( test = iss.eof() );
     VERIFY( test = !iss.fail() );
+    iss.clear();
     iss.seekg(pos1);
     VERIFY( test = !iss.fail() );
   }