This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch] Fix libstdc++/10975
- From: Paolo Carlini <pcarlini at suse dot de>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Thu, 30 Sep 2004 14:40:19 +0200
- Subject: [Patch] Fix libstdc++/10975
Hi,
the below fixes the PR implementing the resolution of DR 453: it looks like
we agree (at least Benjamin (privately), Nathan (see audit trail) and
myself)
that this is a real defect, with a trivial fix. In the meanwhile, the DR
also
includes the proposed wording. If someone objects, however, we can well
delay
the issue, no problem with me.
During the work, a small surprise: the original testcase for 2346-sstream
was largely broken (seekg/teelg in *write* mode).
Tested x86-linux, will wait until this evening in case of comments.
Paolo.
//////////////
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.
diff -urN libstdc++-v3-orig/docs/html/ext/howto.html libstdc++-v3/docs/html/ext/howto.html
--- libstdc++-v3-orig/docs/html/ext/howto.html 2004-08-13 18:47:43.000000000 +0200
+++ libstdc++-v3/docs/html/ext/howto.html 2004-09-30 11:31:01.000000000 +0200
@@ -496,6 +496,12 @@
</dt>
<dd>Replace "new" with "::new".
</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>
diff -urN libstdc++-v3-orig/include/bits/sstream.tcc libstdc++-v3/include/bits/sstream.tcc
--- libstdc++-v3-orig/include/bits/sstream.tcc 2004-09-29 22:56:03.000000000 +0200
+++ libstdc++-v3/include/bits/sstream.tcc 2004-09-30 11:27:33.000000000 +0200
@@ -142,8 +142,10 @@
__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 -urN libstdc++-v3-orig/testsuite/27_io/basic_istream/seekg/char/2346-fstream.cc libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/2346-fstream.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_istream/seekg/char/2346-fstream.cc 2004-01-06 13:20:42.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/2346-fstream.cc 1970-01-01 01:00:00.000000000 +0100
@@ -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 -urN libstdc++-v3-orig/testsuite/27_io/basic_istream/seekg/char/2346-sstream.cc libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/2346-sstream.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_istream/seekg/char/2346-sstream.cc 2004-01-06 13:20:42.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/2346-sstream.cc 1970-01-01 01:00:00.000000000 +0100
@@ -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;
-}
diff -urN libstdc++-v3-orig/testsuite/27_io/basic_istream/tellg/char/1.cc libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/1.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_istream/tellg/char/1.cc 2003-09-23 22:03:10.000000000 +0200
+++ libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/1.cc 2004-09-30 11:54:24.000000000 +0200
@@ -31,20 +31,23 @@
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 -urN libstdc++-v3-orig/testsuite/27_io/basic_ostream/seekp/char/2346-fstream.cc libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-fstream.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_ostream/seekp/char/2346-fstream.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-fstream.cc 2004-09-30 11:22:39.000000000 +0200
@@ -0,0 +1,88 @@
+// 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)
+{
+ for (int j = 0; j < times; j++)
+ {
+ bool test __attribute__((unused)) = true;
+ 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 -urN libstdc++-v3-orig/testsuite/27_io/basic_ostream/seekp/char/2346-sstream.cc libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-sstream.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_ostream/seekp/char/2346-sstream.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-sstream.cc 2004-09-30 11:23:56.000000000 +0200
@@ -0,0 +1,80 @@
+// 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)
+{
+ for (int j = 0; j < times; j++)
+ {
+ bool test __attribute__((unused)) = true;
+ 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;
+}
diff -urN libstdc++-v3-orig/testsuite/27_io/basic_ostream/tellp/char/1.cc libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/1.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_ostream/tellp/char/1.cc 2003-09-23 22:03:15.000000000 +0200
+++ libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/1.cc 2004-09-30 11:53:26.000000000 +0200
@@ -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
@@ -25,24 +25,26 @@
#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...
diff -urN libstdc++-v3-orig/testsuite/27_io/basic_ostream/tellp/char/2.cc libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/2.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_ostream/tellp/char/2.cc 2003-09-23 22:03:15.000000000 +0200
+++ libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/2.cc 2004-09-30 13:13:28.000000000 +0200
@@ -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 @@
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 -urN libstdc++-v3-orig/testsuite/27_io/basic_stringbuf/seekoff/char/10975.cc libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/10975.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_stringbuf/seekoff/char/10975.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/10975.cc 2004-09-30 13:11:46.000000000 +0200
@@ -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 -urN libstdc++-v3-orig/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/10975.cc libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/10975.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/10975.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/10975.cc 2004-09-30 13:11:27.000000000 +0200
@@ -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;
+}