This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

libstdc++/9318: i/ostream::operator>>/<<(streambuf*) broken


>Number:         9318
>Category:       libstdc++
>Synopsis:       i/ostream::operator>>/<<(streambuf*) broken
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jan 15 02:06:00 PST 2003
>Closed-Date:
>Last-Modified:
>Originator:     peturr02@ru.is
>Release:        gcc-3.2.1
>Organization:
>Environment:
Red Hat Linux 8.0
>Description:
basic_istream<>::operator>>(basic_streambuf<>*) and basic_ostream<>::operator<<(basic_streambuf<>*) don't copy any characters if the target streambuf is a user-defined unbuffered streambuf.

Reason: __copy_streambufs only performs the copy if ios_base::out is set in the _M_mode member of the target streambuf, but the only basic_streambuf<> members that change _M_mode are setg and setp, and an unbuffered streambuf never calls those.
>How-To-Repeat:
See attachment.
>Fix:
Remove check for _M_mode & ios_base::out.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="streambufcopybug.cc"
Content-Disposition: inline; filename="streambufcopybug.cc"

#include <sstream>
#include <streambuf>
#include <string>
#include <iostream>

using namespace std;

class Outbuf : public std::streambuf
{
private:
	string 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));
		}

public:
	string result() const { return str; }
};

#undef NDEBUG
#include <cassert>

void test01()
{
	istringstream stream ("Bad Moon Rising");
	Outbuf buf;
	stream >> &buf;

	cout << buf.result() << endl;
	cout << stream.str() << endl;
	
	assert(buf.result() == stream.str());
}

void test02()
{
	stringbuf sbuf ("Bad Moon Rising", ios::in);
	Outbuf buf;
	ostream stream (&buf);
	stream << &sbuf;

	cout << buf.result() << endl;
	cout << sbuf.str() << endl;
	
	assert(buf.result() == sbuf.str());
}

int main()
{
	test01();
	test02();

	return 0;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]