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

* [Bug libstdc++/38678] istream::read() calls streambuf::xsgetn()
  2008-12-30 22:24 [Bug libstdc++/38678] New: istream::read() calls streambuf::xsgetn() sebor at roguewave dot com
@ 2008-12-31  0:08 ` 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
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: paolo dot carlini at oracle dot com @ 2008-12-31  0:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from paolo dot carlini at oracle dot com  2008-12-31 00:06 -------
Ok, thanks.


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |paolo dot carlini at oracle
                   |dot org                     |dot com
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2008-12-31 00:06:28
               date|                            |


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


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/38678] istream::read() calls streambuf::sgetn()
  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 ` paolo dot carlini at oracle dot com
  2009-01-01 10:10 ` paolo at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: paolo dot carlini at oracle dot com @ 2008-12-31 17:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from paolo dot carlini at oracle dot com  2008-12-31 17:44 -------
Note, istream::read currently calls streambuf::sgetn *not* streambuf::xsgetn,
because the latter is protected and in general would be incorrect calling it
anyway.


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|istream::read() calls       |istream::read() calls
                   |streambuf::xsgetn()         |streambuf::sgetn()


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


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/38678] istream::read() calls streambuf::sgetn()
  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
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: paolo at gcc dot gnu dot org @ 2009-01-01 10:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from paolo at gcc dot gnu dot org  2009-01-01 10:09 -------
Subject: Bug 38678

Author: paolo
Date: Thu Jan  1 10:08:31 2009
New Revision: 142994

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=142994
Log:
2009-01-01  Paolo Carlini  <paolo.carlini@oracle.com>

        PR libstdc++/38678
        * include/std/istream (basic_istream<>::_M_read): New.
        * include/bits/istream.tcc (basic_istream<>::_M_read): Define.
        (basic_istream<>::read, basic_istream<>::readsome): Use it.
        * include/std/ostream (basic_ostream<>::_M_write_): New.
        (basic_ostream<>::_M_write): Adjust.
        * include/bits/ostream.tcc (basic_ostream<>::_M_write_): Define.
        * testsuite/27_io/basic_istream/read/char/38678.cc: New.
        * testsuite/27_io/basic_istream/read/wchar_t/38678.cc: Likewise.
        * testsuite/27_io/basic_ostream/write/char/38678.cc: Likewise.
        * testsuite/27_io/basic_ostream/write/wchar_t/38678.cc: Likewise.

Added:
    trunk/libstdc++-v3/testsuite/27_io/basic_istream/read/char/38678.cc
    trunk/libstdc++-v3/testsuite/27_io/basic_istream/read/wchar_t/38678.cc
    trunk/libstdc++-v3/testsuite/27_io/basic_ostream/write/char/38678.cc
    trunk/libstdc++-v3/testsuite/27_io/basic_ostream/write/wchar_t/38678.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/bits/istream.tcc
    trunk/libstdc++-v3/include/bits/ostream.tcc
    trunk/libstdc++-v3/include/std/istream
    trunk/libstdc++-v3/include/std/ostream


-- 


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


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/38678] istream::read() calls streambuf::sgetn()
  2008-12-30 22:24 [Bug libstdc++/38678] New: istream::read() calls streambuf::xsgetn() sebor at roguewave dot com
                   ` (2 preceding siblings ...)
  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
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-01-01 10:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from paolo dot carlini at oracle dot com  2009-01-01 10:10 -------
Fixed for 4.4.0.


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.4.0


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


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/38678] [DR XXX] istream::read() calls streambuf::sgetn()
  2008-12-30 22:24 [Bug libstdc++/38678] New: istream::read() calls streambuf::xsgetn() sebor at roguewave dot com
                   ` (4 preceding siblings ...)
  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
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-01-03 22:37 UTC (permalink / raw)
  To: gcc-bugs



-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |SUSPENDED


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


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/38678] [DR XXX] istream::read() calls streambuf::sgetn()
  2008-12-30 22:24 [Bug libstdc++/38678] New: istream::read() calls streambuf::xsgetn() sebor at roguewave dot com
                   ` (3 preceding siblings ...)
  2009-01-01 10:12 ` paolo dot carlini at oracle dot com
@ 2009-01-03 22:37 ` paolo dot carlini at oracle dot com
  2009-01-03 22:37 ` paolo dot carlini at oracle dot com
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-01-03 22:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from paolo dot carlini at oracle dot com  2009-01-03 22:37 -------
Changes reverted for now, consistently with the discussion:

  http://gcc.gnu.org/ml/gcc-patches/2009-01/msg00004.html

Waiting for the resolution of a new DR (# to be added Summary).


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |
            Summary|istream::read() calls       |[DR XXX] istream::read()
                   |streambuf::sgetn()          |calls streambuf::sgetn()


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


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/38678] [DR XXX] istream::read() calls streambuf::sgetn()
  2008-12-30 22:24 [Bug libstdc++/38678] New: istream::read() calls streambuf::xsgetn() sebor at roguewave dot com
                   ` (5 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-04-21 16:02 UTC (permalink / raw)
  To: gcc-bugs



-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.4.0                       |4.4.1


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


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/38678] [DR XXX] istream::read() calls streambuf::sgetn()
  2008-12-30 22:24 [Bug libstdc++/38678] New: istream::read() calls streambuf::xsgetn() sebor at roguewave dot com
                   ` (6 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-07-22 10:35 UTC (permalink / raw)
  To: gcc-bugs



-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.4.1                       |4.4.2


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


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/38678] [DR XXX] istream::read() calls streambuf::sgetn()
  2008-12-30 22:24 [Bug libstdc++/38678] New: istream::read() calls streambuf::xsgetn() sebor at roguewave dot com
                   ` (7 preceding siblings ...)
  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
  10 siblings, 0 replies; 16+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-10-15 12:58 UTC (permalink / raw)
  To: gcc-bugs



-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.4.2                       |4.4.3


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


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/38678] [DR XXX] istream::read() calls streambuf::sgetn()
  2008-12-30 22:24 [Bug libstdc++/38678] New: istream::read() calls streambuf::xsgetn() sebor at roguewave dot com
                   ` (8 preceding siblings ...)
  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
  10 siblings, 0 replies; 16+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-01-21 13:16 UTC (permalink / raw)
  To: gcc-bugs



-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.4.3                       |4.4.4


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


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/38678] [DR XXX] istream::read() calls streambuf::sgetn()
  2008-12-30 22:24 [Bug libstdc++/38678] New: istream::read() calls streambuf::xsgetn() sebor at roguewave dot com
                   ` (9 preceding siblings ...)
  2010-01-21 13:16 ` jakub at gcc dot gnu dot org
@ 2010-04-30  8:59 ` jakub at gcc dot gnu dot org
  10 siblings, 0 replies; 16+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-04-30  8:59 UTC (permalink / raw)
  To: gcc-bugs



-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.4.4                       |4.4.5


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


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/38678] [DR XXX] istream::read() calls streambuf::sgetn()
       [not found] <bug-38678-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2011-04-28 16:39 ` rguenth at gcc dot gnu.org
@ 2024-06-13 15:26 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2024-06-13 15:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38678

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
MSVC and libc++ both behave the same as libstdc++, calling rdbuf()->sgetn():

https://github.com/microsoft/STL/blob/e36ee6c2b9bc6f5b1f70776c18cf5d3a93a69798/stl/inc/istream#L522

https://github.com/llvm/llvm-project/blob/525c25acd364f018b4fa55e941bd702587478b1c/libcxx/include/istream#L897

I think at this point it seems pretty clear we should open a new issue as the
istream counterpart to https://cplusplus.github.io/LWG/issue165 and make the
spec match reality. I can't find an issue on the topic from Martin, so I don't
think it was ever opened.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/38678] [DR XXX] istream::read() calls streambuf::sgetn()
       [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
  3 siblings, 0 replies; 16+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-04-28 16:39 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.4.7                       |---


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/38678] [DR XXX] istream::read() calls streambuf::sgetn()
       [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
  3 siblings, 0 replies; 16+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-04-16 10:45 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.4.6                       |4.4.7


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/38678] [DR XXX] istream::read() calls streambuf::sgetn()
       [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
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 16+ messages in thread
From: jakub at gcc dot gnu.org @ 2010-10-01 11:58 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.4.5                       |4.4.6


^ permalink raw reply	[flat|nested] 16+ messages in thread

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).