PR libstdc++/10975 (DR 453)

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
This commit is contained in:
Paolo Carlini 2004-09-30 17:23:10 +00:00 committed by Paolo Carlini
parent 84eeda0c97
commit 9c9e97bdb4
10 changed files with 173 additions and 27 deletions

View 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)):

View File

@ -496,6 +496,12 @@
</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>

View 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();

View File

@ -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...

View File

@ -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,11 +18,11 @@
// 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)

View File

@ -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;

View 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
@ -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...

View 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()

View File

@ -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;
}

View File

@ -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;
}