aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <pcarlini@suse.de>2004-09-29 21:14:43 +0000
committerPaolo Carlini <pcarlini@suse.de>2004-09-29 21:14:43 +0000
commit02c252e2c9286220df8939188cc52eb02f52e4df (patch)
tree7ddbfb3d8fde45554eca1fb9fedb2a481d11dd26
parent52fa231c68b21358df0f36083efd30d588f864f4 (diff)
2004-09-29 Paolo Carlini <pcarlini@suse.de>
* include/std/std_sstream.h (basic_stringbuf(ios_base::openmode)): Don't use _M_stringbuf_init, keep the pointers null, per 27.7.1.1. (str()): Slightly tweak, protect from pptr() == 0. (_M_update_egptr()): Likewise. * include/bits/sstream.tcc (ssekoff, seekpos): In order to check for an empty buffer use __beg instead of _M_string.capacity(). * testsuite/27_io/basic_stringbuf/cons/char/1.cc: New. * testsuite/27_io/basic_stringbuf/cons/wchar_t/1.cc: Likewise. * testsuite/27_io/basic_filebuf/cons/char/1.cc: New. * testsuite/27_io/basic_filebuf/cons/wchar_t/1.cc: Likewise. * testsuite/27_io/basic_streambuf/cons/char/1.cc: Update. * testsuite/27_io/basic_streambuf/cons/wchar_t/1.cc: Likewise. 2004-09-29 Paolo Carlini <pcarlini@suse.de> Benjamin Kosnik <bkoz@redhat.com> * testsuite/testsuite_io.h (class constraint_buf): New, extended and templatized version of constraint_filebuf; add typedefs for streambuf/stringbuf/filebuf and wchar_t counterparts. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@88307 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libstdc++-v3/ChangeLog23
-rw-r--r--libstdc++-v3/include/bits/sstream.tcc18
-rw-r--r--libstdc++-v3/include/std/std_sstream.h12
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/cons/char/1.cc40
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/cons/wchar_t/1.cc40
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_streambuf/cons/char/1.cc61
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_streambuf/cons/wchar_t/1.cc61
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/1.cc40
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/1.cc40
-rw-r--r--libstdc++-v3/testsuite/testsuite_io.h87
10 files changed, 258 insertions, 164 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index e5dee830e8f..d7feffc7b3d 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,26 @@
+2004-09-29 Paolo Carlini <pcarlini@suse.de>
+
+ * include/std/std_sstream.h (basic_stringbuf(ios_base::openmode)):
+ Don't use _M_stringbuf_init, keep the pointers null, per 27.7.1.1.
+ (str()): Slightly tweak, protect from pptr() == 0.
+ (_M_update_egptr()): Likewise.
+ * include/bits/sstream.tcc (ssekoff, seekpos): In order to check
+ for an empty buffer use __beg instead of _M_string.capacity().
+ * testsuite/27_io/basic_stringbuf/cons/char/1.cc: New.
+ * testsuite/27_io/basic_stringbuf/cons/wchar_t/1.cc: Likewise.
+
+ * testsuite/27_io/basic_filebuf/cons/char/1.cc: New.
+ * testsuite/27_io/basic_filebuf/cons/wchar_t/1.cc: Likewise.
+ * testsuite/27_io/basic_streambuf/cons/char/1.cc: Update.
+ * testsuite/27_io/basic_streambuf/cons/wchar_t/1.cc: Likewise.
+
+2004-09-29 Paolo Carlini <pcarlini@suse.de>
+ Benjamin Kosnik <bkoz@redhat.com>
+
+ * testsuite/testsuite_io.h (class constraint_buf): New, extended
+ and templatized version of constraint_filebuf; add typedefs for
+ streambuf/stringbuf/filebuf and wchar_t counterparts.
+
2004-09-28 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/16612
diff --git a/libstdc++-v3/include/bits/sstream.tcc b/libstdc++-v3/include/bits/sstream.tcc
index 137d6b3fff7..bd05cc2eb43 100644
--- a/libstdc++-v3/include/bits/sstream.tcc
+++ b/libstdc++-v3/include/bits/sstream.tcc
@@ -123,6 +123,7 @@ namespace std
{
// Update egptr() to match the actual string end.
_M_update_egptr();
+
if (this->gptr() < this->egptr())
__ret = traits_type::to_int_type(*this->gptr());
}
@@ -141,10 +142,9 @@ namespace std
__testin &= !(__mode & ios_base::out);
__testout &= !(__mode & ios_base::in);
- if (_M_string.capacity() && (__testin || __testout || __testboth))
+ const char_type* __beg = __testin ? this->eback() : this->pbase();
+ if (__beg && (__testin || __testout || __testboth))
{
- char_type* __beg = __testin ? this->eback() : this->pbase();
-
_M_update_egptr();
off_type __newoffi = __off;
@@ -181,15 +181,15 @@ namespace std
seekpos(pos_type __sp, ios_base::openmode __mode)
{
pos_type __ret = pos_type(off_type(-1));
- if (_M_string.capacity())
- {
- off_type __pos (__sp);
- const bool __testin = (ios_base::in & this->_M_mode & __mode) != 0;
- const bool __testout = (ios_base::out & this->_M_mode & __mode) != 0;
- char_type* __beg = __testin ? this->eback() : this->pbase();
+ const bool __testin = (ios_base::in & this->_M_mode & __mode) != 0;
+ const bool __testout = (ios_base::out & this->_M_mode & __mode) != 0;
+ const char_type* __beg = __testin ? this->eback() : this->pbase();
+ if (__beg)
+ {
_M_update_egptr();
+ off_type __pos(__sp);
const bool __testpos = 0 <= __pos
&& __pos <= this->egptr() - __beg;
if ((__testin || __testout) && __testpos)
diff --git a/libstdc++-v3/include/std/std_sstream.h b/libstdc++-v3/include/std/std_sstream.h
index 6b5728b94ce..0a6738adf8a 100644
--- a/libstdc++-v3/include/std/std_sstream.h
+++ b/libstdc++-v3/include/std/std_sstream.h
@@ -111,8 +111,8 @@ namespace std
*/
explicit
basic_stringbuf(ios_base::openmode __mode = ios_base::in | ios_base::out)
- : __streambuf_type(), _M_mode(), _M_string()
- { _M_stringbuf_init(__mode); }
+ : __streambuf_type(), _M_mode(__mode), _M_string()
+ { }
/**
* @brief Starts with an existing string buffer.
@@ -140,8 +140,7 @@ namespace std
__string_type
str() const
{
- const bool __testout = this->_M_mode & ios_base::out;
- if (__testout)
+ if (this->pptr())
{
// The current egptr() may not be the actual string end.
if (this->pptr() > this->egptr())
@@ -169,7 +168,7 @@ namespace std
}
protected:
- // Common initialization code for both ctors goes here.
+ // Common initialization code goes here.
/**
* @if maint
* @doctodo
@@ -277,9 +276,8 @@ namespace std
_M_update_egptr()
{
const bool __testin = this->_M_mode & ios_base::in;
- const bool __testout = this->_M_mode & ios_base::out;
- if (__testout && this->pptr() > this->egptr())
+ if (this->pptr() && this->pptr() > this->egptr())
if (__testin)
this->setg(this->eback(), this->gptr(), this->pptr());
else
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/char/1.cc
new file mode 100644
index 00000000000..599309845cd
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/char/1.cc
@@ -0,0 +1,40 @@
+// 2004-09-29 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.8.1.2 basic_filebuf constructors [lib.filebuf.cons]
+
+#include <fstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+// http://gcc.gnu.org/ml/libstdc++/2004-09/msg00243.html
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ __gnu_test::constraint_filebuf fbuf;
+ VERIFY( fbuf.check_pointers() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/wchar_t/1.cc
new file mode 100644
index 00000000000..083a81c0deb
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/wchar_t/1.cc
@@ -0,0 +1,40 @@
+// 2004-09-29 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.8.1.2 basic_filebuf constructors [lib.filebuf.cons]
+
+#include <fstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+// http://gcc.gnu.org/ml/libstdc++/2004-09/msg00243.html
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ __gnu_test::constraint_wfilebuf fbuf;
+ VERIFY( fbuf.check_pointers() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/cons/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/cons/char/1.cc
index 9400a599bfc..76a344cfe23 100644
--- a/libstdc++-v3/testsuite/27_io/basic_streambuf/cons/char/1.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/cons/char/1.cc
@@ -31,69 +31,12 @@
#include <streambuf>
#include <testsuite_hooks.h>
-
-class testbuf : public std::streambuf
-{
-public:
-
- // Typedefs:
- typedef std::streambuf::traits_type traits_type;
- typedef std::streambuf::char_type char_type;
-
- testbuf(): std::streambuf()
- { }
-
- bool
- check_pointers()
- {
- bool test __attribute__((unused)) = true;
- VERIFY( this->eback() == NULL );
- VERIFY( this->gptr() == NULL );
- VERIFY( this->egptr() == NULL );
- VERIFY( this->pbase() == NULL );
- VERIFY( this->pptr() == NULL );
- VERIFY( this->epptr() == NULL );
- return test;
- }
-
- int_type
- pub_uflow()
- { return (this->uflow()); }
-
- int_type
- pub_overflow(int_type __c = traits_type::eof())
- { return (this->overflow(__c)); }
-
- int_type
- pub_pbackfail(int_type __c)
- { return (this->pbackfail(__c)); }
-
- void
- pub_setg(char* beg, char* cur, char *end)
- { this->setg(beg, cur, end); }
-
- void
- pub_setp(char* beg, char* end)
- { this->setp(beg, end); }
-
-protected:
- int_type
- underflow()
- {
- int_type __retval = traits_type::eof();
- if (this->gptr() < this->egptr())
- __retval = traits_type::not_eof(0);
- return __retval;
- }
-};
+#include <testsuite_io.h>
void test01()
{
- typedef testbuf::traits_type traits_type;
- typedef testbuf::int_type int_type;
-
bool test __attribute__((unused)) = true;
- testbuf buf01;
+ __gnu_test::constraint_streambuf buf01;
// 27.5.2.1 basic_streambuf ctors
// default ctor initializes
diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/cons/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/cons/wchar_t/1.cc
index a97b35f4d11..1721e4a820a 100644
--- a/libstdc++-v3/testsuite/27_io/basic_streambuf/cons/wchar_t/1.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/cons/wchar_t/1.cc
@@ -32,69 +32,12 @@
#include <streambuf>
#include <testsuite_hooks.h>
-
-class testbuf : public std::wstreambuf
-{
-public:
-
- // Typedefs:
- typedef std::wstreambuf::traits_type traits_type;
- typedef std::wstreambuf::char_type char_type;
-
- testbuf(): std::wstreambuf()
- { }
-
- bool
- check_pointers()
- {
- bool test __attribute__((unused)) = true;
- VERIFY( this->eback() == NULL );
- VERIFY( this->gptr() == NULL );
- VERIFY( this->egptr() == NULL );
- VERIFY( this->pbase() == NULL );
- VERIFY( this->pptr() == NULL );
- VERIFY( this->epptr() == NULL );
- return test;
- }
-
- int_type
- pub_uflow()
- { return (this->uflow()); }
-
- int_type
- pub_overflow(int_type __c = traits_type::eof())
- { return (this->overflow(__c)); }
-
- int_type
- pub_pbackfail(int_type __c)
- { return (this->pbackfail(__c)); }
-
- void
- pub_setg(wchar_t* beg, wchar_t* cur, wchar_t* end)
- { this->setg(beg, cur, end); }
-
- void
- pub_setp(wchar_t* beg, wchar_t* end)
- { this->setp(beg, end); }
-
-protected:
- int_type
- underflow()
- {
- int_type __retval = traits_type::eof();
- if (this->gptr() < this->egptr())
- __retval = traits_type::not_eof(0);
- return __retval;
- }
-};
+#include <testsuite_io.h>
void test01()
{
- typedef testbuf::traits_type traits_type;
- typedef testbuf::int_type int_type;
-
bool test __attribute__((unused)) = true;
- testbuf buf01;
+ __gnu_test::constraint_wstreambuf buf01;
// 27.5.2.1 basic_streambuf ctors
// default ctor initializes
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/1.cc
new file mode 100644
index 00000000000..cf82e029d61
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/1.cc
@@ -0,0 +1,40 @@
+// 2004-09-29 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.1 basic_stringbuf constructors [lib.stringbuf.cons]
+
+#include <sstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+// http://gcc.gnu.org/ml/libstdc++/2004-09/msg00243.html
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ __gnu_test::constraint_stringbuf sbuf;
+ VERIFY( sbuf.check_pointers() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/1.cc
new file mode 100644
index 00000000000..10abc588786
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/1.cc
@@ -0,0 +1,40 @@
+// 2004-09-29 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.1 basic_stringbuf constructors [lib.stringbuf.cons]
+
+#include <sstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+// http://gcc.gnu.org/ml/libstdc++/2004-09/msg00243.html
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ __gnu_test::constraint_wstringbuf sbuf;
+ VERIFY( sbuf.check_pointers() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/testsuite_io.h b/libstdc++-v3/testsuite/testsuite_io.h
index e5e342eed14..809d0801c6d 100644
--- a/libstdc++-v3/testsuite/testsuite_io.h
+++ b/libstdc++-v3/testsuite/testsuite_io.h
@@ -1,7 +1,7 @@
// -*- C++ -*-
-// Testing filebuf for the C++ library testsuite.
+// Testing streambuf/filebuf/stringbuf for the C++ library testsuite.
//
-// Copyright (C) 2003 Free Software Foundation, Inc.
+// Copyright (C) 2003, 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
@@ -32,6 +32,7 @@
#define _GLIBCXX_TESTSUITE_IO_H
#include <fstream>
+#include <sstream>
namespace __gnu_test
{
@@ -44,34 +45,60 @@ namespace __gnu_test
// Joint file position
// 27.8.1.4 - Overridden virtual functions p9
// If unbuffered, pbase == pptr == NULL
- class constraint_filebuf: public std::filebuf
- {
- public:
- bool
- write_position()
- {
- bool two = this->pptr() != NULL;
- bool one = this->pptr() < this->epptr();
- return one && two;
- }
-
- bool
- read_position()
- {
- bool one = this->gptr() != NULL;
- bool two = this->gptr() < this->egptr();
-
- return one && two;
- }
-
- bool
- unbuffered()
- {
- bool one = this->pbase() == NULL;
- bool two = this->pptr() == NULL;
- return one && two;
- }
- };
+ // 27.7.1.1 - Basic_stringbuf constructors p 1
+ // 27.8.1.2 - Basic_filebuf constructors p 1
+ // ... , initializing the base class with basic_streambuf() 27.5.2.1
+ template<typename T>
+ class constraint_buf
+ : public T
+ {
+ public:
+ bool
+ write_position()
+ {
+ bool one = this->pptr() != NULL;
+ bool two = this->pptr() < this->epptr();
+ return one && two;
+ }
+
+ bool
+ read_position()
+ {
+ bool one = this->gptr() != NULL;
+ bool two = this->gptr() < this->egptr();
+ return one && two;
+ }
+
+ bool
+ unbuffered()
+ {
+ bool one = this->pbase() == NULL;
+ bool two = this->pptr() == NULL;
+ return one && two;
+ }
+
+ bool
+ check_pointers()
+ {
+ bool one = this->eback() == NULL;
+ bool two = this->gptr() == NULL;
+ bool three = this->egptr() == NULL;
+
+ bool four = this->pbase() == NULL;
+ bool five = this->pptr() == NULL;
+ bool six = this->epptr() == NULL;
+ return one && two && three && four && five && six;
+ }
+ };
+
+ typedef constraint_buf<std::streambuf> constraint_streambuf;
+ typedef constraint_buf<std::filebuf> constraint_filebuf;
+ typedef constraint_buf<std::stringbuf> constraint_stringbuf;
+#ifdef _GLIBCXX_USE_WCHAR_T
+ typedef constraint_buf<std::wstreambuf> constraint_wstreambuf;
+ typedef constraint_buf<std::wfilebuf> constraint_wfilebuf;
+ typedef constraint_buf<std::wstringbuf> constraint_wstringbuf;
+#endif
// Used to check if basic_streambuf::pubsync() has been called.
// This is useful for checking if a function creates [io]stream::sentry