OSDN Git Service

2003-11-26 Benjamin Kosnik <bkoz@redhat.com>
authorbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 26 Nov 2003 22:45:56 +0000 (22:45 +0000)
committerbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 26 Nov 2003 22:45:56 +0000 (22:45 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@73968 138bc75d-0d04-0410-961f-82ee72b054a4

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/istream.tcc
libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/12297.cc [new file with mode: 0644]

index f94f6b8..243dcbd 100644 (file)
@@ -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>
 
index 9b87bc2..d710f0c 100644 (file)
@@ -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 (file)
index 0000000..918870c
--- /dev/null
@@ -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;
+}