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]

goodbit and zero as ios_base::iostate values


Hello!

I don't know whether this issue is of any interest, but some time ago
I ran to this.

In ISO/IEC 14882:1998(E) Standard [lib.locale] contains the example:

[Example: An iostream operator<< might be implemented as:220)
      template <class charT, class traits>
            basic_ostream<charT,traits>&
            operator<< (basic_ostream<charT,traits>& s, Date d)
      { typename basic_ostream<charT,traits>::sentry cerberos(s);
            if (cerberos) {
              ios_base::iostate err = 0;
              tm tmbuf; d.extract(tmbuf);
              use_facet< time_put<charT,ostreambuf_iterator<charT,traits> > >(
                 s.getloc()).put(s, s, s.fill(), err, &tmbuf, 'x');
              s.setstate(err); // might throw
            }return s;
      }
-end example]

It is actually erroneous because time_put<>.put() doesn't have "err"
argument. (!!!)  However, it contains the line

  ios_base::iostate err = 0;

which doesn't compile with g++ 3.2 because it says:

  invalid conversion from `int' to `std::_Ios_Iostate'

Also [lib.istream.formatted.arithmetic] contains a code fragment where

  iostate err = 0;

ios_base::iostate is of [lib.bitmask.types] bitmask type and it seems to me
that the Standard doesn't there say anything about from int to bitmask
conversion nor about initialization from int.

However, [lib.ios::iostate] first tells about the three elements
badbit, eofbit and failbit, and then mentions that:

Type iostate also defines the constant:
     - goodbit, the value zero.

I cannot judge from these two code excerpts and the vague mention of
zero value, whether the libstdc++ implementation is conformant or not.  (If the
authors of the Standard had been careful enough, they woud have written
"err = goodbit" also in those two places as they do in [lib.facets.examples].)

Yours,

Jorma Laaksonen

-- 
Jorma Laaksonen                                 email: jorma.laaksonen@hut.fi
Dr. of Science in Technology, Docent            http://www.cis.hut.fi/jorma/
Laboratory of Computer and Information Science  tel. +358-9-4513269
Helsinki University of Technology               fax. +358-9-4513277
P.O.Box 5400, Fin-02015 HUT, Finland            mob. +358-50-3058719


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