[Bug libstdc++/46906] New: istreambuf_iterator is late?

marc.glisse at normalesup dot org gcc-bugzilla@gcc.gnu.org
Sun Dec 12 15:26:00 GMT 2010


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46906

           Summary: istreambuf_iterator is late?
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: marc.glisse@normalesup.org


The following program prints:
11
12
32

With some other libraries I get 11 22 33 (but libstdc++ is not the only one
that outputs 11 12 32).

As far as I understand the standard, operator++ and operator* should just call
sbumpc and sgetc on the underlying streambuf, which happens to be the same for
the two iterators. It looks like the iterator caches the result somehow. Am I
missing some provision for this in the standard?


#include <ios>
#include <istream>
#include <sstream>
#include <iostream>

using namespace std;
int main(){
    istringstream s("1234");
    istreambuf_iterator<char> i1(s);
    istreambuf_iterator<char> i2(i1);
    std::cerr << *i1 << *i2 << '\n';
    ++i2;
    std::cerr << *i1 << *i2 << '\n';
    ++i1;
    std::cerr << *i1 << *i2 << '\n';
}



More information about the Gcc-bugs mailing list