This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC] err |= ios_base::failbit or err = ios_base::failbit?!?


On Mon, Jan 05, 2004 at 04:26:02PM +0100, Paolo Carlini wrote:
> Nathan Myers wrote:
> 
> >On Mon, Jan 05, 2004 at 03:42:05PM +0100, Paolo Carlini wrote:
> >
> >>the standard, in 22.2.2.1.2, p11-12, always talks about:
> >>
> >>"... ios_base::failbit is assigned to err."
> >>
> >>On the other hand, we have been always doing:
> >>
> >>err |= ios_base::failbit.
> >>...
> >
> >If, in every case where it prescribes assigning failbit, that point
> >could not be reached unless the error state was already clear, then
> >they are equivalent. I suspect that was the reasoning in committee.
> >Have you found a case where the code can set failbit but the error
> >state was not zero? (I.e., maybe our use of operator|= is merely
> >defensive coding.)
> 
> Well this is the sequence of calls:
> 
>  get -> do_get -> _M_extract_int(float)
> 
> the latter contains the |= and nothing in the middle in our implementation,
> (neither in 22.2.2.1.2) changes the err passed by get.
> 
> Therefore, it looks like we have *plenty* of cases!!!

I remember now.

The "err" argument to the num_get members is not synonymous with the 
error state of the stream.  The correct usage of that argument by 
the istream members is to pass in a zero value; and then apply any 
failures that come back to the calling stream's error state (and throw 
exceptions, where specified).  

It probably would be better actually to assign failbit, rather than 
ORing it in.  We should check that the istream extractor code does
the Right Thing with error results from facet calls, and does not 
(e.g.) just pass the basic_ios member directly as the err argument.

Good catch.

Nathan Myers
ncm-nospam@cantrip.org


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]