libstdc++/3599 Patch for invalid ostream::put state check
Stephen M. Webb
stephen@bregmasoft.com
Wed Jul 18 09:04:00 GMT 2001
This patch is originally due to Roman Sulzhyk who reported the bug libstdc++/3599.
I cleaned it up and added the test case.
The problem boiled down to libstdc++-v3 violating the "returns" clause of
section 27.5.2.4.5 of the standard, albiet indirectly.
2001-07-18 Stephen M. Webb <stephen@bregmasoft..com>
Roman Sulzhyk <roman_sulzhyk@yahoo.com>
libstdc++/3599
* include/bits/ostream.tcc (ostream::put): Fixed error condition check.
* testsuite/27_io/streambuf.cc (test07): Added new regression test.
Index: include/bits/ostream.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/ostream.tcc,v
retrieving revision 1.12
diff -c -3 -p -r1.12 ostream.tcc
*** ostream.tcc 2001/06/11 19:20:19 1.12
--- ostream.tcc 2001/07/18 15:40:15
*************** namespace std
*** 358,364 ****
if (__cerb)
{
int_type __put = rdbuf()->sputc(__c);
! if (__put != traits_type::to_int_type(__c))
this->setstate(ios_base::badbit);
}
return *this;
--- 358,364 ----
if (__cerb)
{
int_type __put = rdbuf()->sputc(__c);
! if (traits_type::eq_int_type(__put, traits_type::eof()))
this->setstate(ios_base::badbit);
}
return *this;
Index: testsuite/27_io/streambuf.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/streambuf.cc,v
retrieving revision 1.7
diff -c -3 -p -r1.7 streambuf.cc
*** streambuf.cc 2001/05/12 16:51:42 1.7
--- streambuf.cc 2001/07/18 15:40:16
*************** namespace gnu
*** 337,342 ****
--- 337,366 ----
class gnu::something_derived : std::streambuf { };
#endif
+ // libstdc++/3599
+ class testbuf2 : public std::streambuf
+ {
+ public:
+ typedef std::streambuf::traits_type traits_type;
+
+ testbuf2() : std::streambuf() { }
+
+ protected:
+ int_type
+ overflow(int_type c = traits_type::eof())
+ { return traits_type::not_eof(0); }
+ };
+
+ void
+ test07()
+ {
+ testbuf2 ob;
+ std::ostream out(&ob);
+
+ VERIFY(out << "gasp");
+ VERIFY(out << std::endl);
+ }
+
int main()
{
test01();
*************** int main()
*** 345,349 ****
--- 369,375 ----
test04();
test05();
+
+ test07();
return 0;
}
_______
Stephen M. Webb
More information about the Gcc-patches
mailing list