This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] Fix libstdc++/12296
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 29 Sep 2003 19:40:36 +0200
- Subject: [v3] Fix libstdc++/12296
Hi,
tested x86-linux, committed.
Paolo.
////////////
2003-09-29 Paolo Carlini <pcarlini@unitus.it>
PR libstdc++/12296
* include/bits/istream.tcc (peek): Set eofbit if sgetc
returns eof.
* testsuite/27_io/basic_istream/peek/char/12296.cc:
New, from the PR.
diff -urN libstdc++-v3-1/include/bits/istream.tcc libstdc++-v3/include/bits/istream.tcc
--- libstdc++-v3-1/include/bits/istream.tcc 2003-09-22 20:29:56.000000000 +0200
+++ libstdc++-v3/include/bits/istream.tcc 2003-09-29 10:11:48.000000000 +0200
@@ -761,7 +761,11 @@
if (__cerb)
{
try
- { __c = this->rdbuf()->sgetc(); }
+ {
+ __c = this->rdbuf()->sgetc();
+ if (traits_type::eq_int_type(__c, traits_type::eof()))
+ this->setstate(ios_base::eofbit);
+ }
catch(...)
{
// 27.6.1.3 paragraph 1
diff -urN libstdc++-v3-1/testsuite/27_io/basic_istream/peek/char/12296.cc libstdc++-v3/testsuite/27_io/basic_istream/peek/char/12296.cc
--- libstdc++-v3-1/testsuite/27_io/basic_istream/peek/char/12296.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/basic_istream/peek/char/12296.cc 2003-09-29 10:33:46.000000000 +0200
@@ -0,0 +1,41 @@
+// Copyright (C) 2003 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 27.6.1.3 unformatted input functions
+
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/12296
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ istringstream stream;
+ VERIFY( stream.rdstate() == ios_base::goodbit );
+ istringstream::int_type c = stream.peek();
+ VERIFY( c == istringstream::traits_type::eof() );
+ VERIFY( stream.rdstate() == ios_base::eofbit );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}