[PATCH] Cleanup in istream.tcc
Martin Sebor
sebor@roguewave.com
Tue Sep 23 18:28:00 GMT 2003
Pétur Runólfsson wrote:
> Several functions in istream.tcc use the construct
>
> sentry __cerb(*this, true);
> if (__cerb)
> {
> // ...
> }
> else
> this->setstate(ios_base::failbit);
>
> 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 particular, readsome() is explicitly required to set failbit when
the sentry is false.
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. 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.
Martin
More information about the Libstdc++
mailing list