aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Kosnik <bkoz@redhat.com>2003-11-26 22:45:56 +0000
committerBenjamin Kosnik <bkoz@gcc.gnu.org>2003-11-26 22:45:56 +0000
commit48f499cf81387cc10cc5045519b1bab9ccf40d83 (patch)
tree61eeb4755c2a89ce526968f83572aff8eafeb13e
parentaef81a9acb17a9eadc5df75007b4364fbfa3a9de (diff)
downloadgcc-48f499cf81387cc10cc5045519b1bab9ccf40d83.zip
gcc-48f499cf81387cc10cc5045519b1bab9ccf40d83.tar.gz
gcc-48f499cf81387cc10cc5045519b1bab9ccf40d83.tar.bz2
re PR libstdc++/12297 (istream::sentry::sentry() handles eof() incorrectly.)
2003-11-26 Benjamin Kosnik <bkoz@redhat.com> PR libstdc++/12297 * include/bits/istream.tcc (basic_istream::sentry::sentry): Set failbit and eofbit when eof. * testsuite/27_io/basic_istream/sentry/char/12297.cc: New. From-SVN: r73968
-rw-r--r--libstdc++-v3/ChangeLog7
-rw-r--r--libstdc++-v3/include/bits/istream.tcc8
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/12297.cc50
3 files changed, 62 insertions, 3 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index f94f6b8..243dcbd 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,10 @@
+2003-11-26 Benjamin Kosnik <bkoz@redhat.com>
+
+ PR libstdc++/12297
+ * include/bits/istream.tcc
+ (basic_istream::sentry::sentry): Set failbit and eofbit when eof.
+ * testsuite/27_io/basic_istream/sentry/char/12297.cc: New.
+
2003-11-26 Paolo Carlini <pcarlini@suse.de>
Petur Runolfsson <peturr02@ru.is>
diff --git a/libstdc++-v3/include/bits/istream.tcc b/libstdc++-v3/include/bits/istream.tcc
index 9b87bc2..d710f0c 100644
--- a/libstdc++-v3/include/bits/istream.tcc
+++ b/libstdc++-v3/include/bits/istream.tcc
@@ -46,6 +46,7 @@ namespace std
basic_istream<_CharT, _Traits>::sentry::
sentry(basic_istream<_CharT, _Traits>& __in, bool __noskipws)
{
+ ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (__in.good())
{
if (__in.tie())
@@ -66,17 +67,18 @@ namespace std
// 195. Should basic_istream::sentry's constructor ever
// set eofbit?
if (traits_type::eq_int_type(__c, __eof))
- __in.setstate(ios_base::eofbit);
+ __err |= ios_base::eofbit;
}
}
- if (__in.good())
+ if (__in.good() && __err == ios_base::goodbit)
_M_ok = true;
else
{
_M_ok = false;
- __in.setstate(ios_base::failbit);
+ __err |= ios_base::failbit;
}
+ __in.setstate(__err);
}
template<typename _CharT, typename _Traits>
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/12297.cc b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/12297.cc
new file mode 100644
index 0000000..918870c
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/12297.cc
@@ -0,0 +1,50 @@
+// Copyright (C) 2003 Free Software Foundation, Inc.
+//
+// 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.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+// 27.6.1.1.2 class basic_istream::sentry
+
+#include <sstream>
+#include <testsuite_hooks.h>
+
+int main()
+{
+ using namespace std;
+ istringstream stream;
+ stream.exceptions(ios_base::eofbit);
+
+ try
+ {
+ istream::sentry sentry(stream, false);
+ VERIFY( false );
+ }
+ catch (ios_base::failure&)
+ {
+ VERIFY( stream.rdstate() == (ios_base::eofbit | ios_base::failbit) );
+ }
+
+ return 0;
+}