public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/38678]  New: istream::read() calls streambuf::xsgetn()
@ 2008-12-30 22:24 sebor at roguewave dot com
  2008-12-31  0:08 ` [Bug libstdc++/38678] " paolo dot carlini at oracle dot com
                   ` (10 more replies)
  0 siblings, 11 replies; 16+ messages in thread
From: sebor at roguewave dot com @ 2008-12-30 22:24 UTC (permalink / raw)
  To: gcc-bugs

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 <cassert>
#include <istream>
#include <streambuf>

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()::<anonymous
struct>::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


^ permalink raw reply	[flat|nested] 16+ messages in thread
[parent not found: <bug-38678-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2024-06-13 15:26 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-30 22:24 [Bug libstdc++/38678] New: istream::read() calls streambuf::xsgetn() sebor at roguewave dot com
2008-12-31  0:08 ` [Bug libstdc++/38678] " paolo dot carlini at oracle dot com
2008-12-31 17:46 ` [Bug libstdc++/38678] istream::read() calls streambuf::sgetn() paolo dot carlini at oracle dot com
2009-01-01 10:10 ` paolo at gcc dot gnu dot org
2009-01-01 10:12 ` paolo dot carlini at oracle dot com
2009-01-03 22:37 ` [Bug libstdc++/38678] [DR XXX] " paolo dot carlini at oracle dot com
2009-01-03 22:37 ` paolo dot carlini at oracle dot com
2009-04-21 16:02 ` jakub at gcc dot gnu dot org
2009-07-22 10:35 ` jakub at gcc dot gnu dot org
2009-10-15 12:58 ` jakub at gcc dot gnu dot org
2010-01-21 13:16 ` jakub at gcc dot gnu dot org
2010-04-30  8:59 ` jakub at gcc dot gnu dot org
     [not found] <bug-38678-4@http.gcc.gnu.org/bugzilla/>
2010-10-01 11:58 ` jakub at gcc dot gnu.org
2011-04-16 10:45 ` jakub at gcc dot gnu.org
2011-04-28 16:39 ` rguenth at gcc dot gnu.org
2024-06-13 15:26 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).