From mboxrd@z Thu Jan 1 00:00:00 1970 From: bkoz@gcc.gnu.org To: bkoz@gcc.gnu.org, brendan@zen.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org Subject: Re: libstdc++/4545: basic_ostream op<< should set badbit, not failbit Date: Thu, 25 Oct 2001 21:36:00 -0000 Message-id: <20011026043644.11387.qmail@sourceware.cygnus.com> X-SW-Source: 2001-10/msg00542.html List-Id: Synopsis: basic_ostream op<< should set badbit, not failbit Responsible-Changed-From-To: unassigned->bkoz Responsible-Changed-By: bkoz Responsible-Changed-When: Thu Oct 25 21:36:43 2001 Responsible-Changed-Why: Mine. State-Changed-From-To: open->feedback State-Changed-By: bkoz State-Changed-When: Thu Oct 25 21:36:43 2001 State-Changed-Why: Brendan, thanks for pointing this out. I think that badbit is set when the streambuf is null, and failbit is set when no characters were copied. I believe this is consistent with a careful read of the standard: 1: If sb is null calls setstate(badbit) 2: If the function inserts no characters, it calls setstate(failbit) Anyway. I believe the function should look like this: template basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(__streambuf_type* __sbin) { sentry __cerb(*this); if (__cerb) { try { streamsize __xtrct = 0; if (__sbin) { __streambuf_type* __sbout = this->rdbuf(); __xtrct = __copy_streambufs(*this, __sbin, __sbout); } else this->setstate(ios_base::badbit); if (!__xtrct) this->setstate(ios_base::failbit); } catch(exception& __fail) { // 27.6.2.5.1 Common requirements. // Turn this on without causing an ios::failure to be thrown. this->setstate(ios_base::badbit); if ((this->exceptions() & ios_base::badbit) != 0) __throw_exception_again; } } return *this; } http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&pr=4545&database=gcc