[PATCH] Cleanup in istream.tcc

Pétur Runólfsson peturr02@ru.is
Wed Sep 24 08:15:00 GMT 2003


Martin Sebor wrote:
> > The call to setstate is redundant since sentry::operator bool() only
> > returns false if sentry::sentry() has already set failbit.
> 
> Not necessarily. Failbit (or any other bit) may have been set prior
> to the call to the ctor, in which case the sentry might do nothing
> and the input function would then call setstate(failbit).

In *this* implementation, sentry::sentry() always calls
setstate(failbit) if !good(), so this patch will not change the
visible behaviour of any conforming program. This behaviour makes
sense to me, since otherwise every input function would have to call
setstate(failbit) if sentry::operator bool() returns false.

This implementation is conforming since the description of
sentry::sentry states that it "may" set failbit.

> Also, even when failbit is already set prior to the call to the
> sentry ctor, whether the input function does or does not call
> setstate(failbit) is detectable simply by setting failbit in
> exceptions.

Yes, but in this implementation, setstate(failbit) is always
called if !good(), both before and after this patch.

> AFAIK, the standard doesn't say whether input
> functions must call setstate(failbit) if the bit is already
> set. I suspect that it was not even considered when exceptions
> were added to iostreams. I would like to see this specified
> more precisely.

I agree.

Petur



More information about the Libstdc++ mailing list