public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: johnb@stl.sarov.ru To: gcc-gnats@gcc.gnu.org Subject: libstdc++/8258: basic_istream::readsome() with default buffer change stream state to ios_base::eofbit Date: Thu, 17 Oct 2002 09:56:00 -0000 [thread overview] Message-ID: <20021017165336.1154.qmail@sources.redhat.com> (raw) >Number: 8258 >Category: libstdc++ >Synopsis: basic_istream::readsome() with default buffer change stream state to ios_base::eofbit >Confidential: no >Severity: non-critical >Priority: medium >Responsible: unassigned >State: open >Class: sw-bug >Submitter-Id: net >Arrival-Date: Thu Oct 17 09:56:00 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Eugeny Belov >Release: g++ v3.2 >Organization: >Environment: Red Hat linux 8.0 release >Description: Possibly this is not a bug, but the g++ v3.1 version of basic_istream::readsome() don`t change the stream state in case of using default basic_streambuf constructor (zero length buffer). Here is an example: #include <istream> #include <cassert> using namespace std; class mybuf : public basic_streambuf <char> { }; int main () { char arr[10]; mybuf sbuf; basic_istream <char, char_traits<char> > istr(&sbuf); assert (istr.rdstate() == ios_base::goodbit); assert (istr.readsome(arr, 10) == 0); assert (istr.rdstate() == ios_base::goodbit); return 0; } The result here is that the last assertion is failing with g++ v3.2. I found in ISO/IEC 14882 C++ standard (27.6.1.3.30) only 2 possibilities of changing the stream state related to readsome(): 1. if !good() - setstate (failbit) 2. if rdbuf()->in_avail() == -1 - setstate (eofbit) The example above gives: 1. good() == true 2. rdbuf()->in_avail() == 0 (!= -1) so, I can expect that stream state will not change. I made a diff for 3.1 and 3.2 versions of bits/istream.tcc and noted that here are the following changes which give such unexpected (for me) behavior: streamsize __num = this->rdbuf()->in_avail(); 3.1: if (__num != static_cast <streamsize>(__eof)) { ...read from buffer... } else this->setstate (ios_base::eofbit) 3.2: if (__num > 0) { ...read from buffer... } else this->setstate (ios_base::eofbit) Shure, changing the stream state in such case can be useful, but my opinion is that previous version was more standard conformant. >How-To-Repeat: Compile attached testcaes with g++ v3.2 and run. >Fix: >Release-Note: >Audit-Trail: >Unformatted: ----gnatsweb-attachment---- Content-Type: application/octet-stream; name="istr_readsome.cpp" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="istr_readsome.cpp" I2luY2x1ZGUgPGlzdHJlYW0+CiNpbmNsdWRlIDxjYXNzZXJ0PgoKdXNpbmcgbmFtZXNwYWNlIHN0 ZDsKCgpjbGFzcyBteWJ1ZiA6IHB1YmxpYyBiYXNpY19zdHJlYW1idWYgPGNoYXI+IHsKCX07Cgpp bnQgbWFpbiAoKSAKIHsKICAgIGNoYXIgYXJyWzEwXTsKICAgIG15YnVmIHNidWY7CiAgICBiYXNp Y19pc3RyZWFtIDxjaGFyLCBjaGFyX3RyYWl0czxjaGFyPiA+IGlzdHIoJnNidWYpOwoKICAgIGFz c2VydCAoaXN0ci5yZHN0YXRlKCkgPT0gaW9zX2Jhc2U6Omdvb2RiaXQpOwogICAgYXNzZXJ0IChp c3RyLnJlYWRzb21lKGFyciwgMTApID09IDApOwogICAgYXNzZXJ0IChpc3RyLnJkc3RhdGUoKSA9 PSBpb3NfYmFzZTo6Z29vZGJpdCk7CgogIHJldHVybiAwOwogfQoK
next reply other threads:[~2002-10-17 16:56 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-10-17 9:56 johnb [this message] 2002-11-05 15:17 bkoz 2002-11-06 8:53 bkoz
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20021017165336.1154.qmail@sources.redhat.com \ --to=johnb@stl.sarov.ru \ --cc=gcc-gnats@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).