This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch] Fix libstdc++/9318
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>
- Cc: bkoz <bkoz at redhat dot com>
- Date: Sun, 09 Feb 2003 13:31:09 +0100
- Subject: [Patch] Fix libstdc++/9318
Hi!
This one seems needed for unbuffered custom streambufs
(using, f.i., std::string, as in testcase) to interact
with ostream::operator>>/<< : in fact a custom streambuf
has no _standard_ (*) way to change _M_mode (other than
callling setg/setp, unused for this kind of custom buffers).
Also double checked the testcase with a couple of other
implementations.
Tested x86-linux, ok trunk and 3_3?
Paolo.
(*) Of course, _for v3_ a:
Outbuf() { _M_mode = _M_mode | ios_base::out; }
could be added to the custom buffer of the testcase...
//////////
2003-02-09 Paolo Carlini <pcarlini@unitus.it>
Petur Runolfsson <peturr02@ru.is>
DR libstdc++/9318
* include/bits/streambuf.tcc (__copy_streambufs):
Don't conditionalize the copy to __testput.
* testsuite/27_io/streambuf_members.cc (test09, test10): Add.
diff -urN libstdc++-v3-orig/include/bits/streambuf.tcc libstdc++-v3/include/bits/streambuf.tcc
--- libstdc++-v3-orig/include/bits/streambuf.tcc 2003-02-04 19:08:44.000000000 +0100
+++ libstdc++-v3/include/bits/streambuf.tcc 2003-02-09 12:19:54.000000000 +0100
@@ -203,10 +203,9 @@
streamsize __ret = 0;
streamsize __bufsize = __sbin->in_avail();
streamsize __xtrct;
- bool __testput = __sbout->_M_mode & ios_base::out;
try
{
- while (__testput && __bufsize != -1)
+ while (__bufsize != -1)
{
if (__bufsize != 0 && __sbin->gptr() != NULL
&& __sbin->gptr() + __bufsize <= __sbin->egptr())
diff -urN libstdc++-v3-orig/testsuite/27_io/streambuf_members.cc libstdc++-v3/testsuite/27_io/streambuf_members.cc
--- libstdc++-v3-orig/testsuite/27_io/streambuf_members.cc 2003-01-23 23:53:35.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/streambuf_members.cc 2003-02-09 12:34:46.000000000 +0100
@@ -31,7 +31,7 @@
#include <cstring> // for memset, memcmp
#include <streambuf>
-#include <string>
+#include <sstream>
#include <ostream>
#include <testsuite_hooks.h>
@@ -386,6 +386,51 @@
VERIFY( ob.getloc() == loc_de );
}
+// libstdc++/9318
+class Outbuf : public std::streambuf
+{
+public:
+ typedef std::streambuf::traits_type traits_type;
+
+ std::string result() const { return str; }
+
+protected:
+ virtual int_type overflow(int_type c = traits_type::eof())
+ {
+ if (!traits_type::eq_int_type(c, traits_type::eof()))
+ str.push_back(traits_type::to_char_type(c));
+ return traits_type::not_eof(c);
+ }
+
+private:
+ std::string str;
+};
+
+// <1>
+void test09()
+{
+ bool test = true;
+
+ std::istringstream stream("Bad Moon Rising");
+ Outbuf buf;
+ stream >> &buf;
+
+ VERIFY( buf.result() == "Bad Moon Rising" );
+}
+
+// <2>
+void test10()
+{
+ bool test = true;
+
+ std::stringbuf sbuf("Bad Moon Rising", std::ios::in);
+ Outbuf buf;
+ std::ostream stream(&buf);
+ stream << &sbuf;
+
+ VERIFY( buf.result() == "Bad Moon Rising" );
+}
+
int main()
{
test01();
@@ -397,5 +442,8 @@
test07();
test08();
+
+ test09();
+ test10();
return 0;
}