This is the mail archive of the libstdc++@sourceware.cygnus.com 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]

re: Another problem with istringstream



Thanks for the elaborated test case. What do you think the output
should be, and why? There has been a defect report (195) that
explicitly sets failbit | eofbit in the istream::sentry ctor -- that's
why there might be some confusion WRT the standard. I've asked for
clarification on this point, and will let you know what I find out.

Take a look at this pared-down example based on your last post. I
believe the current behavior is odd, but conformant to the standard +
defect patches. I would think that only eofbit should be set for both
of the two cases below, but that is not strictly conformant.

-benjamin

#include <string>
#include <sstream>

int main()
{
  bool test = true;
  int i = 0, j = 0;

  // part one -- eofbit set
  istringstream is1("123");
  is1 >> i >> j;
  test = is1.fail();

  // part two -- eofbit | failbit set
  istringstream is3("123 ");
  is3 >> i >> j;
  test = is1.fail();

  return 0;
}


  // part one
  operator>>(int& __n)
    sentry
    num_get::get(..., int)
      num_get::do_get 
      // 22.2.2.1.2 num_get virtual functions
      // p 13 and 16
      // -> eofbit set, not eofbit | failbit
    setstate(eofbit)
    // as per 27.6.1.2.2 

  operator>>(int& __n)
    sentry
    // as not good (this->good() != true) then doesn't prepare for input
    // and sentry is not ok, so no input can take place


  // part two    
  operator>>(int& __n)
    sentry
    num_get::get(..., int)
      num_get::do_get 
    setstate(goodbit)

  operator>>(int& __n)
    sentry
    // extracts remaining white space, hits eof -- sets eof | failbit?
      setstate(eofbit | failbit)
      








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