From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7919 invoked by alias); 30 Dec 2008 22:24:16 -0000 Received: (qmail 6773 invoked by uid 48); 30 Dec 2008 22:22:56 -0000 Date: Tue, 30 Dec 2008 22:24:00 -0000 Subject: [Bug libstdc++/38678] New: istream::read() calls streambuf::xsgetn() X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "sebor at roguewave dot com" 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: 2008-12/txt/msg02985.txt.bz2 As mentioned in bug 38476, [lib.istream], p2 specifies that: Both [formatted and unformatted] input functions are described as if they obtain (or extract) input characters by calling rdbuf()->sbumpc() or rdbuf()->sgetc(). They may use other public members of istream. sgetc() is required to return the result of underflow() and sbumpc() is required to return the result of uflow(). An implementation of istream::read() may call streambuf::xsgetn() but it must do so in a way that achieves the "as if" effect described above. Notably, it must avoid calling an xsgetn() overridden in a derived class. The test case below shows that the gcc implementation fails to do so. $ cat z.cpp && g++ z.cpp && ./a.out #include #include #include int main () { static int x = '0'; struct: std::streambuf { char c; int_type underflow () { c = x++; setg (&c, &c, &c + 1); return c; } std::streamsize xsgetn (char*, std::streamsize) { assert (!"xsgetn should not be called"); return 0; } } sb; std::istream in (&sb); char s [4] = ""; in.read (s, sizeof s); assert (in.good ()); assert (sizeof s == in.gcount ()); assert ('0' == s [0] && '1' == s [1] && '2' == s [2] && '3' == s [3]); } a.out: z.cpp:19: virtual std::streamsize main()::::xsgetn(char*, std::streamsize): Assertion `!"xsgetn should not be called"' failed. Aborted -- Summary: istream::read() calls streambuf::xsgetn() Product: gcc Version: 4.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: sebor at roguewave dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38678