According to the resolution to DR 195: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html#195 basic_istream::sentry::sentry() should call setstate(failbit | eofbit) if is.rdbuf()->sgetc() or is.rdbuf()->sbumpc() return eof(). Currently, the sentry constructor calls is.setstate(eofbit) and later calls is.setstate(failbit). This means that failbit will not be set in is.rdstate() as it should if the call to setstate(eofbit) throws an exception.
Created attachment 4770 [details] Test case
I can confirm this on the mainline (20030925).
Subject: Bug 12297 CVSROOT: /cvs/gcc Module name: gcc Changes by: bkoz@gcc.gnu.org 2003-11-26 22:45:57 Modified files: libstdc++-v3 : ChangeLog libstdc++-v3/include/bits: istream.tcc Added files: libstdc++-v3/testsuite/27_io/basic_istream/sentry/char: 12297.cc Log message: 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. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&r1=1.2110&r2=1.2111 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/istream.tcc.diff?cvsroot=gcc&r1=1.56&r2=1.57 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/12297.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
Subject: Bug 12297 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: bkoz@gcc.gnu.org 2003-11-26 22:49:28 Modified files: libstdc++-v3 : ChangeLog libstdc++-v3/include/bits: istream.tcc Log message: 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. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.1464.2.155&r2=1.1464.2.156 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/istream.tcc.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.36.4.7&r2=1.36.4.8
Fixed for 3.3.3.