PR libstdc++/10975 (DR 453)
authorPaolo Carlini <pcarlini@suse.de>
Thu, 30 Sep 2004 17:23:10 +0000 (17:23 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Thu, 30 Sep 2004 17:23:10 +0000 (17:23 +0000)
2004-09-30  Paolo Carlini  <pcarlini@suse.de>

PR libstdc++/10975 (DR 453)
* include/bits/sstream.tcc (seekoff): Don't fail if __beg == 0
and __off == 0.
* docs/html/ext/howto.html: Add an entry for DR 453.
* testsuite/27_io/basic_stringbuf/seekoff/char/10975.cc: New.
* testsuite/27_io/basic_stringbuf/seekoff/wchar_t/10975.cc: Likewise.
* testsuite/27_io/basic_istream/tellg/char/1.cc: Tweak consistently.
* testsuite/27_io/basic_ostream/tellp/char/1.cc: Likewise.
* testsuite/27_io/basic_ostream/tellp/char/2.cc: Likewise.
* testsuite/27_io/basic_istream/seekg/char/2346-fstream.cc: Fix and
move to...
* testsuite/27_io/basic_istream/seekp/char/2346-fstream.cc: ... here.
* testsuite/27_io/basic_istream/seekg/char/2346-sstream.cc: Fix and
move to...
* testsuite/27_io/basic_istream/seekp/char/2346-sstream.cc: ... here.

From-SVN: r88341

12 files changed:
libstdc++-v3/ChangeLog
libstdc++-v3/docs/html/ext/howto.html
libstdc++-v3/include/bits/sstream.tcc
libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/2346-fstream.cc [deleted file]
libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/2346-sstream.cc [deleted file]
libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/1.cc
libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-fstream.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-sstream.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/1.cc
libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/2.cc
libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/10975.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/10975.cc [new file with mode: 0644]

index d7feffc7b3ddb24a5e9aede5e5b0fcb4341e15b1..2e928168b2872e2075ed8ac9307abb112dee0a42 100644 (file)
@@ -1,3 +1,21 @@
+2004-09-30  Paolo Carlini  <pcarlini@suse.de>
+
+       PR libstdc++/10975 (DR 453)
+       * include/bits/sstream.tcc (seekoff): Don't fail if __beg == 0
+       and __off == 0.
+       * docs/html/ext/howto.html: Add an entry for DR 453.
+       * testsuite/27_io/basic_stringbuf/seekoff/char/10975.cc: New.
+       * testsuite/27_io/basic_stringbuf/seekoff/wchar_t/10975.cc: Likewise.
+       * testsuite/27_io/basic_istream/tellg/char/1.cc: Tweak consistently.
+       * testsuite/27_io/basic_ostream/tellp/char/1.cc: Likewise.
+       * testsuite/27_io/basic_ostream/tellp/char/2.cc: Likewise.
+       * testsuite/27_io/basic_istream/seekg/char/2346-fstream.cc: Fix and
+       move to...
+       * testsuite/27_io/basic_istream/seekp/char/2346-fstream.cc: ... here.
+       * testsuite/27_io/basic_istream/seekg/char/2346-sstream.cc: Fix and
+       move to...
+       * testsuite/27_io/basic_istream/seekp/char/2346-sstream.cc: ... here.
+
 2004-09-29  Paolo Carlini  <pcarlini@suse.de>
 
        * include/std/std_sstream.h (basic_stringbuf(ios_base::openmode)):
index 5670c46976846966890f9d343fd4a68233af2420..5b4a69fb1f76c5739d7e7924c8454538932024e3 100644 (file)
     </dt>
     <dd>Replace &quot;new&quot; with &quot;::new&quot;.
     </dd>
+
+    <dt><a href="lwg-active.html#453">453</a>:
+        <em>basic_stringbuf::seekoff need not always fail for an empty stream</em>
+    </dt>
+    <dd>Don't fail if the next pointer is null and newoff is zero.
+    </dd>
 <!--
     <dt><a href="lwg-defects.html#"></a>:
         <em></em>
index bd05cc2eb43ca4e04303ccc7363667f44ba93111..1b1232e9175515807d96f898b1c6770c7938331b 100644 (file)
@@ -142,8 +142,10 @@ namespace std
       __testin &= !(__mode & ios_base::out);
       __testout &= !(__mode & ios_base::in);
 
+      // _GLIBCXX_RESOLVE_LIB_DEFECTS
+      // 453. basic_stringbuf::seekoff need not always fail for an empty stream.
       const char_type* __beg = __testin ? this->eback() : this->pbase();
-      if (__beg && (__testin || __testout || __testboth))
+      if ((__beg || !__off) && (__testin || __testout || __testboth))
        {
          _M_update_egptr();
 
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/2346-fstream.cc b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/2346-fstream.cc
deleted file mode 100644 (file)
index 72686f1..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-// 2000-06-29 bkoz
-
-// Copyright (C) 2000, 2001, 2002, 2003 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
-// USA.
-
-// 27.6.1.3 unformatted input functions
-// NB: ostream has a particular "seeks" category. Adopt this for istreams too.
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %-*.txt
-
-#include <istream>
-#include <fstream>
-#include <testsuite_hooks.h>
-
-const char* s = " lootpack, peanut butter wolf, rob swift, madlib, quasimoto";
-const int times = 10;
-
-void write_rewind(std::iostream& stream)
-{
-  for (int j = 0; j < times; j++) 
-    {
-      bool test __attribute__((unused)) = true;
-      std::streampos begin = stream.tellg();
-      
-      for (int i = 0; i < times; ++i)
-       stream << j << '-' << i << s << '\n';
-      
-      stream.seekg(begin);
-      std::streampos end = stream.tellg(); 
-      std::streampos badpos = std::streampos(std::streambuf::off_type(-1));
-    }
-}
-
-void check_contents(std::iostream& stream)
-{
-  bool test __attribute__((unused)) = true;
-
-  stream.clear();
-  stream.seekg(0, std::ios::beg);
-  int i = 0;
-  int loop = times * times + 2;
-  while (i < loop)
-    {
-      stream.ignore(80, '\n');
-      if (stream.good())
-       ++i;
-      else
-       break;
-    }
-  VERIFY( i == times );
-}
-
-// fstream
-// libstdc++/2346
-void test02()
-{       
-  std::fstream ofstrm;
-  ofstrm.open("istream_seeks-3.txt", std::ios::out);
-  if (!ofstrm)
-    std::abort();
-  write_rewind(ofstrm);
-  ofstrm.close();
-
-  std::fstream ifstrm;
-  ifstrm.open("istream_seeks-3.txt", std::ios::in);
-  check_contents(ifstrm);
-  ifstrm.close();
-}
-
-int main()
-{
-  test02();
-  return 0;
-}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/2346-sstream.cc b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/2346-sstream.cc
deleted file mode 100644 (file)
index 60e43c9..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-// 2000-06-29 bkoz
-
-// Copyright (C) 2000, 2001, 2002, 2003 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
-// USA.
-
-// 27.6.1.3 unformatted input functions
-// NB: ostream has a particular "seeks" category. Adopt this for istreams too.
-
-#include <istream>
-#include <sstream>
-#include <testsuite_hooks.h>
-
-const char* s = " lootpack, peanut butter wolf, rob swift, madlib, quasimoto";
-const int times = 10;
-
-void write_rewind(std::iostream& stream)
-{
-  for (int j = 0; j < times; j++) 
-    {
-      bool test __attribute__((unused)) = true;
-      std::streampos begin = stream.tellg();
-      
-      for (int i = 0; i < times; ++i)
-       stream << j << '-' << i << s << '\n';
-      
-      stream.seekg(begin);
-      std::streampos end = stream.tellg(); 
-      std::streampos badpos = std::streampos(std::streambuf::off_type(-1));
-    }
-}
-
-void check_contents(std::iostream& stream)
-{
-  bool test __attribute__((unused)) = true;
-
-  stream.clear();
-  stream.seekg(0, std::ios::beg);
-  int i = 0;
-  int loop = times * times + 2;
-  while (i < loop)
-    {
-      stream.ignore(80, '\n');
-      if (stream.good())
-       ++i;
-      else
-       break;
-    }
-  VERIFY( i == times );
-}
-
-// stringstream
-// libstdc++/2346
-void test03()
-{       
-  std::stringstream sstrm;
-
-  write_rewind(sstrm);
-  check_contents(sstrm);
-}
-
-int main()
-{
-  test03();
-  return 0;
-}
index d213d040a11ed55a41841e6cbb29b59d24d42f0d..4bbe40be919bfd13a88230a59e7a6b3199e554a8 100644 (file)
 void test01()
 {
   using namespace std;
+  typedef ios::off_type off_type;
   typedef ios::pos_type pos_type;
 
   bool test __attribute__((unused)) = true;
   const char str_lit01[] = "istream_seeks-1.tst";
 
   // in
-  // test default ctors leave things in the same positions...
   istringstream ist1;
   pos_type p3 = ist1.tellg();
 
   ifstream ifs1;
   pos_type p4 = ifs1.tellg();
 
-  VERIFY( p3 == p4 );
+  // N.B. We implement the resolution of DR 453 and
+  // istringstream::tellg() doesn't fail.
+  VERIFY( p3 == pos_type(off_type(0)) );
+  VERIFY( p4 == pos_type(off_type(-1)) );
 
   // in
   // test ctors leave things in the same positions...
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-fstream.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-fstream.cc
new file mode 100644 (file)
index 0000000..29d52f1
--- /dev/null
@@ -0,0 +1,89 @@
+// 2000-06-29 bkoz
+
+// Copyright (C) 2000, 2001, 2002, 2003, 2004 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 27.6.2.4  basic_ostream seek members  [lib.ostream.seeks]
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %-*.txt
+
+#include <ostream>
+#include <istream>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+const char* s = " lootpack, peanut butter wolf, rob swift, madlib, quasimoto";
+const int times = 10;
+
+void write_rewind(std::iostream& stream)
+{
+  bool test __attribute__((unused)) = true;
+
+  for (int j = 0; j < times; j++) 
+    {
+      std::streampos begin = stream.tellp();
+      
+      for (int i = 0; i < times; ++i)
+       stream << j << '-' << i << s << '\n';
+      
+      stream.seekp(begin);
+    }
+  VERIFY( stream.good() );
+}
+
+void check_contents(std::iostream& stream)
+{
+  bool test __attribute__((unused)) = true;
+
+  stream.clear();
+  stream.seekg(0, std::ios::beg);
+  int i = 0;
+  int loop = times * times + 2;
+  while (i < loop)
+    {
+      stream.ignore(80, '\n');
+      if (stream.good())
+       ++i;
+      else
+       break;
+    }
+  VERIFY( i == times );
+}
+
+// fstream
+// libstdc++/2346
+void test02()
+{       
+  std::fstream ofstrm;
+  ofstrm.open("istream_seeks-3.txt", std::ios::out);
+  if (!ofstrm)
+    std::abort();
+  write_rewind(ofstrm);
+  ofstrm.close();
+
+  std::fstream ifstrm;
+  ifstrm.open("istream_seeks-3.txt", std::ios::in);
+  check_contents(ifstrm);
+  ifstrm.close();
+}
+
+int main()
+{
+  test02();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-sstream.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-sstream.cc
new file mode 100644 (file)
index 0000000..e0a7071
--- /dev/null
@@ -0,0 +1,81 @@
+// 2000-06-29 bkoz
+
+// Copyright (C) 2000, 2001, 2002, 2003, 2004 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 27.6.2.4  basic_ostream seek members  [lib.ostream.seeks]
+
+#include <ostream>
+#include <istream>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+const char* s = " lootpack, peanut butter wolf, rob swift, madlib, quasimoto";
+const int times = 10;
+
+void write_rewind(std::iostream& stream)
+{
+  bool test __attribute__((unused)) = true;
+
+  for (int j = 0; j < times; j++) 
+    {
+      std::streampos begin = stream.tellp();
+      
+      for (int i = 0; i < times; ++i)
+       stream << j << '-' << i << s << '\n';
+      
+      stream.seekp(begin);
+    }
+  VERIFY( stream.good() );
+}
+
+void check_contents(std::iostream& stream)
+{
+  bool test __attribute__((unused)) = true;
+
+  stream.clear();
+  stream.seekg(0, std::ios::beg);
+  int i = 0;
+  int loop = times * times + 2;
+  while (i < loop)
+    {
+      stream.ignore(80, '\n');
+      if (stream.good())
+       ++i;
+      else
+       break;
+    }
+  VERIFY( i == times );
+}
+
+// stringstream
+// libstdc++/2346
+// N.B. The original testcase was broken, using tellg/seekg in write_rewind.
+void test03()
+{       
+  std::stringstream sstrm;
+
+  write_rewind(sstrm);
+  check_contents(sstrm);
+}
+
+int main()
+{
+  test03();
+  return 0;
+}
index 5c8caced6f3e44122ed0acb26b9a0c085f4ff932..27506636b03cf8e9654cba997b8df092c8d24a4e 100644 (file)
@@ -1,6 +1,6 @@
 // 2000-06-29 bkoz
 
-// Copyright (C) 2000, 2003 Free Software Foundation
+// Copyright (C) 2000, 2003, 2004 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
 #include <fstream>
 #include <testsuite_hooks.h>
 
-
 void test01()
 {
   using namespace std;
+  typedef ios::off_type off_type;
   typedef ios::pos_type pos_type;
 
   bool test __attribute__((unused)) = true;
   const char str_lit01[] = "ostream_seeks-1.txt";
 
   // out
-  // test default ctors leave things in the same positions...
   ostringstream ost1;
   pos_type p1 = ost1.tellp();
 
   ofstream ofs1;
   pos_type p2 = ofs1.tellp();
 
-  VERIFY( p1 == p2 );
+  // N.B. We implement the resolution of DR 453 and
+  // ostringstream::tellp() doesn't fail.
+  VERIFY( p1 == pos_type(off_type(0)) );
+  VERIFY( p2 == pos_type(off_type(-1)) );
 
   // out
   // test ctors leave things in the same positions...
index f82df5d4bb03a614c02c33ad232d06da4a9555ac..acdc3b4cc75b7c5c25e7151596726f6d427af966 100644 (file)
@@ -1,6 +1,6 @@
 // 2000-03-23 bkoz
 
-// Copyright (C) 2000, 2003 Free Software Foundation
+// Copyright (C) 2000, 2003, 2004 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
@@ -33,13 +33,13 @@ void test01()
   ostringstream ost;
   pos_type pos1;
   pos1 = ost.tellp();
-  VERIFY( pos1 == pos_type(-1) );
+  VERIFY( pos1 == pos_type(off_type(0)) );
   ost << "RZA ";
   pos1 = ost.tellp();
-  VERIFY( pos1 == pos_type(4) );
+  VERIFY( pos1 == pos_type(off_type(4)) );
   ost << "ghost dog: way of the samurai";
   pos1 = ost.tellp();
-  VERIFY( pos1 == pos_type(33) );
+  VERIFY( pos1 == pos_type(off_type(33)) );
 }                                    
 
 int main()
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/10975.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/10975.cc
new file mode 100644 (file)
index 0000000..d97ecc9
--- /dev/null
@@ -0,0 +1,57 @@
+// 2004-09-30  Paolo Carlini  <pcarlini@suse.de>
+
+// Copyright (C) 2004 Free Software Foundation, Inc.
+//
+// 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 27.7.1.3 Overridden virtual functions
+
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/10975
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  using namespace std;
+  typedef streambuf::pos_type pos_type;
+  typedef streambuf::off_type off_type;
+
+  const pos_type good = pos_type(off_type(0));
+  const pos_type bad = pos_type(off_type(-1));
+  pos_type p;
+
+  stringbuf sbuf;
+  
+  p = sbuf.pubseekoff(0, ios_base::cur, ios_base::in);
+  VERIFY( p == good );
+
+  p = sbuf.pubseekoff(0, ios_base::beg, ios_base::out);
+  VERIFY( p == good );
+
+  p = sbuf.pubseekoff(0, ios_base::end);
+  VERIFY( p == good );
+
+  p = sbuf.pubseekoff(0, ios_base::cur);
+  VERIFY( p == bad );
+}
+
+int main() 
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/10975.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/10975.cc
new file mode 100644 (file)
index 0000000..1fef627
--- /dev/null
@@ -0,0 +1,57 @@
+// 2004-09-30  Paolo Carlini  <pcarlini@suse.de>
+
+// Copyright (C) 2004 Free Software Foundation, Inc.
+//
+// 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 27.7.1.3 Overridden virtual functions
+
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/10975
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  using namespace std;
+  typedef wstreambuf::pos_type pos_type;
+  typedef wstreambuf::off_type off_type;
+
+  const pos_type good = pos_type(off_type(0));
+  const pos_type bad = pos_type(off_type(-1));
+  pos_type p;
+
+  wstringbuf sbuf;
+  
+  p = sbuf.pubseekoff(0, ios_base::cur, ios_base::in);
+  VERIFY( p == good );
+
+  p = sbuf.pubseekoff(0, ios_base::beg, ios_base::out);
+  VERIFY( p == good );
+
+  p = sbuf.pubseekoff(0, ios_base::end);
+  VERIFY( p == good );
+
+  p = sbuf.pubseekoff(0, ios_base::cur);
+  VERIFY( p == bad );
+}
+
+int main() 
+{
+  test01();
+  return 0;
+}