Bug 12297

Summary: istream::sentry::sentry() handles eof() incorrectly.
Product: gcc Reporter: Pétur Runólfsson <peturrun>
Component: libstdc++Assignee: Benjamin Kosnik <bkoz>
Status: RESOLVED FIXED    
Severity: normal CC: gcc-bugs
Priority: P2    
Version: 3.4.0   
Target Milestone: 3.3.3   
Host: i686-pc-linux-gnu Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu Known to work:
Known to fail: Last reconfirmed: 2003-10-22 20:06:40
Attachments: Test case

Description Pétur Runólfsson 2003-09-16 08:36:24 UTC
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.
Comment 1 Pétur Runólfsson 2003-09-16 08:36:45 UTC
Created attachment 4770 [details]
Test case
Comment 2 Andrew Pinski 2003-09-28 20:59:42 UTC
I can confirm this on the mainline (20030925).
Comment 3 GCC Commits 2003-11-26 22:46:03 UTC
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

Comment 4 GCC Commits 2003-11-26 22:49:33 UTC
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

Comment 5 Andrew Pinski 2003-11-26 22:57:05 UTC
Fixed for 3.3.3.