OSDN Git Service

2004-09-30 Paolo Carlini <pcarlini@suse.de>
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 30 Sep 2004 17:23:10 +0000 (17:23 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 30 Sep 2004 17:23:10 +0000 (17:23 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@88341 138bc75d-0d04-0410-961f-82ee72b054a4

libstdc++-v3/ChangeLog
libstdc++-v3/docs/html/ext/howto.html
libstdc++-v3/include/bits/sstream.tcc
libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/1.cc
libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-fstream.cc [moved from libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/2346-fstream.cc with 81% similarity]
libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-sstream.cc [moved from libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/2346-sstream.cc with 79% similarity]
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 d7feffc..2e92816 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 5670c46..5b4a69f 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 bd05cc2..1b1232e 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();
 
index d213d04..4bbe40b 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...
@@ -1,6 +1,6 @@
 // 2000-06-29 bkoz
 
-// Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation
+// 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
 // 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.
+// 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>
@@ -32,18 +32,18 @@ const int times = 10;
 
 void write_rewind(std::iostream& stream)
 {
+  bool test __attribute__((unused)) = true;
+
   for (int j = 0; j < times; j++) 
     {
-      bool test __attribute__((unused)) = true;
-      std::streampos begin = stream.tellg();
+      std::streampos begin = stream.tellp();
       
       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));
+      stream.seekp(begin);
     }
+  VERIFY( stream.good() );
 }
 
 void check_contents(std::iostream& stream)
@@ -1,6 +1,6 @@
 // 2000-06-29 bkoz
 
-// Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation
+// 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
@@ -18,9 +18,9 @@
 // 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.
+// 27.6.2.4  basic_ostream seek members  [lib.ostream.seeks]
 
+#include <ostream>
 #include <istream>
 #include <sstream>
 #include <testsuite_hooks.h>
@@ -30,18 +30,18 @@ const int times = 10;
 
 void write_rewind(std::iostream& stream)
 {
+  bool test __attribute__((unused)) = true;
+
   for (int j = 0; j < times; j++) 
     {
-      bool test __attribute__((unused)) = true;
-      std::streampos begin = stream.tellg();
+      std::streampos begin = stream.tellp();
       
       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));
+      stream.seekp(begin);
     }
+  VERIFY( stream.good() );
 }
 
 void check_contents(std::iostream& stream)
@@ -65,6 +65,7 @@ void check_contents(std::iostream& stream)
 
 // stringstream
 // libstdc++/2346
+// N.B. The original testcase was broken, using tellg/seekg in write_rewind.
 void test03()
 {       
   std::stringstream sstrm;
index 5c8cace..2750663 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 f82df5d..acdc3b4 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;
+}