mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-11-30 07:14:09 +08:00
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
This commit is contained in:
parent
aef81a9acb
commit
48f499cf81
@ -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>
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user