https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81857
Bug ID: 81857 Summary: istreambuf_iterator not work as input iterator Product: gcc Version: 6.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: abominable-snowman at yandex dot ru Target Milestone: --- istreambuf_iterator not increment g-pointer of istream, so character will be extracted twice (or more, under some occasion), so it not work as single-pass input iterator: std::stringstream s; char b[] = "c2ee3d09-43b3-466d-b490-db35999a22cf"; char r[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // 012345678901234567890123456789012345 s << b; EXAM_CHECK( !s.fail() ); // pass std::copy_n( std::istreambuf_iterator<char>(s), 36, r ); EXAM_CHECK( !s.fail() ); // pass EXAM_CHECK( memcmp(b, r, 36) == 0 ); // pass EXAM_CHECK( s.tellg() == 35 ); // pass ?! char c = 'q'; std::copy_n( std::istreambuf_iterator<char>(s), 1, &c ); EXAM_CHECK( !s.fail() ); // pass ?! EXAM_CHECK( c == 'f' ); // pass ?! EXAM_CHECK( s.tellg() == 35 ); // pass ?!