diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index f94f6b8a57f..243dcbdfd6b 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2003-11-26 Benjamin Kosnik + + 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 Petur Runolfsson diff --git a/libstdc++-v3/include/bits/istream.tcc b/libstdc++-v3/include/bits/istream.tcc index 9b87bc2bb6a..d710f0c54f9 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 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 00000000000..918870c54d2 --- /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 +#include + +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; +}