From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carlo Wood To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org Subject: Re: libstdc++/4686: Output disappearing after operator<<( streambuf* ) Date: Thu, 25 Oct 2001 21:06:00 -0000 Message-id: <20011026040602.4363.qmail@sourceware.cygnus.com> X-SW-Source: 2001-10/msg00539.html List-Id: The following reply was made to PR libstdc++/4686; it has been noted by GNATS. From: Carlo Wood To: kanze@gabi-soft.de Cc: gcc-gnats@gcc.gnu.org Subject: Re: libstdc++/4686: Output disappearing after operator<<( streambuf* ) Date: Fri, 26 Oct 2001 06:00:57 +0200 On Thu, Oct 25, 2001 at 05:49:35PM -0000, kanze@gabi-soft.de wrote: > #include > #include > #include > > int > main() > { > std::istringstream i1( "3\n" ) ; > std::cout << i1.rdbuf() ; > std::cout << "4\n" ; > return 0 ; > } The reason that nothing is written the second time is beause badbit is set for std::cout. It seems to be set here: 0x0804e134 in std::ostream::sentry::~sentry() (__in_chrg=0xbffff510) at /usr/local/gcc-cvs-3.0/include/g++-v3/bits/std_ostream.h:200 200 _M_os.setstate(ios_base::badbit); (gdb) l 195 // XXX MT 196 if (_M_os.flags() & ios_base::unitbuf && !uncaught_exception()) 197 { 198 // Can't call flush directly or else will get into recursive lock. 199 if (_M_os.rdbuf() && _M_os.rdbuf()->pubsync() == -1) 200 _M_os.setstate(ios_base::badbit); 201 } 202 } right after the call to std::cout << i1.rdbuf(); This indeed seems to be a bug, because - this code seems to try to flush and sets badbit when that fails. However, there is nothing to flush because std::cout is both 1) unbuffered, 2) empty. That is hardly a case where an *attempt* to flush it can cause an error. -- Carlo Wood