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]

Bug in istream_iterator


Hello,

the following programm won't work with the CVS version.  The program
will not stop reading from cin, although I pressed Ctrl-d (it won't 
work with a file, either)

// Begin Programm
// Read input from standard in with help of a istream_iterator 
#include <iostream>
#include <iterator>
#include <list>

int main() 
{
  std::istream_iterator<int> inp(std::cin);
  std::istream_iterator<int> eofinp;
  std::list<int> l(inp, eofinp);
  std::cout << l.size() << std::endl;
}
// End Programm

The bug seems to be in stl_iterator.h or basic_ios.h

--------- stl_iterator.h::_M_read() (line 855)

  void _M_read() {
    _M_end_marker = (*_M_stream) ? true : false;
    if (_M_end_marker) *_M_stream >> _M_value;
    _M_end_marker = (*_M_stream) ? true : false;
  }

--------- end

---------- basic_ios.h::operator void*() (line 89)
      operator void*() const 
      { return this->fail() ? 0 : const_cast<basic_ios*>(this); }
---------- end

and it seems to come directly from the standard (24.5.1 (1) ; 27.4.5.3
(1) and (9)). Unfortunately, I only have the draft, so I can't be
sure (it's quite hard to get the standard here in switzerland, if you
don't have a credit card...)

I guess the bug is in 27.4.5.3, so a patch _may_ look like this

--------------------------- start patch
*** basic_ios.h 2000/03/21 06:24:04     1.34
--- basic_ios.h 2000/04/21 19:40:54
*************** namespace std {
*** 87,93 ****
        { return _M_fnumput; }

        operator void*() const
!       { return this->fail() ? 0 : const_cast<basic_ios*>(this); }

        inline bool
        operator!() const
--- 87,93 ----
        { return _M_fnumput; }

        operator void*() const
!       { return (this->fail() || this->eof()) ? 0 : const_cast<basic_ios*>(this); }

        inline bool
        operator!() const
--------------------------- end patch

2000-04-21  Thomas  <thomas@hex.ch>

	* basic_ios.h: operator void*() const changed (eof() added)


Thomas
	

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