From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5919 invoked by alias); 5 Sep 2011 11:11:48 -0000 Received: (qmail 5909 invoked by uid 22791); 5 Sep 2011 11:11:47 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 05 Sep 2011 11:11:29 +0000 From: "daniel.kruegler at googlemail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/46906] istreambuf_iterator is late? Date: Mon, 05 Sep 2011 11:11:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: daniel.kruegler at googlemail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-09/txt/msg00305.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D46906 --- Comment #6 from Daniel Kr=C3=BCgler 2011-09-05 11:11:26 UTC --- (In reply to comment #5) > On the other hand, it looks like I can > construct i2 from s (instead of copying from i1) and still hit the same i= ssue > with a valid program. Do you agree? (Hmm, could the standard make it unde= fined > to interlace uses of an istreambuf_iterator and other operations on the > istreambuf, to allow this behavior?) You still hit the same result, but the result has nothing to do with some special implementation details of std::istreambuf_iterator: 1) The fact that repeated calls of operator* without intervening operator++ calls produce the same result for a given iterator object is required by expression *a: "The expression (void)*a, *a is equivalent to *a." This explains the repeated values '1' and '1' from it1 and '2' and '2' from it2. 2) The observation that the last output produces a "3" for the first iterat= or is to be expected from the fact, that std::istreambuf_iterator is a shallow wrapper for the actual stream buffer, as described in [istreambuf.iterator]= p1 says:=20 "The class template istreambuf_iterator defines an input iterator (24.2.3) = that reads successive characters from the streambuf for which it was constructed= ."=20 Any "external" accesses to that stream buffer (and the usage of an effective sbumpc() call via the second std::istreambuf_iterator object on the same st= ream buffer) obviously changes the state of the stream buffer in the expected wa= y. The same result would be observed when you would replace the second iterator object by explicit calls of the stream buffer as follows: #include #include #include #include using namespace std; int main(){ istringstream s("1234"); istreambuf_iterator i1(s); std::basic_streambuf& b =3D *s.rdbuf(); std::cerr << *i1 << (char) b.sgetc() << '\n'; b.sbumpc(); char c =3D b.sgetc(); std::cerr << *i1 << c << '\n'; ++i1; std::cerr << *i1 << c << '\n'; } I'm getting: 11 12 32 which is non-distinguishable from the example program with two different std::istreambuf_iterator objects. I don't see why there would be undefined behaviour involved.