This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch] Fix libstdc++/9563
- 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: Wed, 12 Feb 2003 20:06:16 +0100
- Subject: [Patch] Fix libstdc++/9563
Hi!
This one too seems pretty straightforward: basically, we failed
to implement the exact requirements of 27.6.2.3, p2-3.
(interestingly we did for the more complex istream::sentry)
Tested x86-linux, ok trunk and 3_3?
Paolo.
//////////
2003-02-12 Paolo Carlini <pcarlini@unitus.it>
PR libstdc++/9563
* include/bits/ostream.tcc (sentry::sentry): Check
the state of the stream after the preparation.
* testsuite/27_io/ostream_sentry.cc (test02): Add.
diff -urN libstdc++-v3-orig/include/bits/ostream.tcc libstdc++-v3/include/bits/ostream.tcc
--- libstdc++-v3-orig/include/bits/ostream.tcc 2003-02-04 21:56:49.000000000 +0100
+++ libstdc++-v3/include/bits/ostream.tcc 2003-02-12 14:33:40.000000000 +0100
@@ -41,11 +41,19 @@
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>::sentry::
sentry(basic_ostream<_CharT,_Traits>& __os)
- : _M_ok(__os.good()), _M_os(__os)
+ : _M_os(__os)
{
- // XXX MT
- if (_M_ok && __os.tie())
- __os.tie()->flush();
+ // XXX MT
+ if (__os.good() && __os.tie())
+ __os.tie()->flush();
+
+ if (__os.good())
+ _M_ok = true;
+ else
+ {
+ _M_ok = false;
+ __os.setstate(ios_base::failbit);
+ }
}
template<typename _CharT, typename _Traits>
diff -urN libstdc++-v3-orig/testsuite/27_io/ostream_sentry.cc libstdc++-v3/testsuite/27_io/ostream_sentry.cc
--- libstdc++-v3-orig/testsuite/27_io/ostream_sentry.cc 2003-02-07 01:26:44.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/ostream_sentry.cc 2003-02-12 19:32:53.000000000 +0100
@@ -46,8 +46,38 @@
VERIFY( bool(sentry1) == true );
}
+// libstdc++/9563
+struct buf: std::streambuf
+{
+ std::ios *io_;
+
+ buf (std::ios *io): io_ (io) { }
+
+ virtual int sync ()
+ {
+ io_->setstate (std::ios::failbit);
+ return 0;
+ }
+};
+
+void
+test02()
+{
+ buf b(0);
+ std::ostream strm(&b);
+
+ buf tb(&strm);
+ std::ostream tied(&tb);
+
+ strm.tie(&tied);
+ std::ostream::sentry s(strm);
+
+ VERIFY( !s );
+}
+
int main()
{
test01();
+ test02();
return 0;
}