This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofTC1 status.
basic_istream::sentry's constructor ever set eofbit?Section: 31.7.5.2.4[istream.sentry]Status:TC1Submitter: Matt AusternOpened: 1999-10-13Last modified: 2021-06-06
Priority:Not Prioritized
View all otherissues in [istream.sentry].
View all issues withTC1 status.
Discussion:
Suppose thatis.flags() & ios_base::skipws is nonzero.What shouldbasic_istream<>::sentry's constructor do if itreaches eof while skipping whitespace? 27.6.1.1.2/5 suggests itshould set failbit. Should it set eofbit as well? The standarddoesn't seem to answer that question.
On the one hand, nothing in [istream::sentry] says thatbasic_istream<>::sentry should ever set eofbit. On theother hand, 31.7.5.2[istream] paragraph 4 says that ifextraction from astreambuf "returnstraits::eof(), then the input function, except as explicitlynoted otherwise, completes its actions and doessetstate(eofbit)". So the question comes down towhetherbasic_istream<>::sentry's constructor is aninput function.
Comments from Jerry Schwarz:
It was always my intention that eofbit should be set any time that avirtual returned something to indicate eof, no matter what reasoniostream code had for calling the virtual.
The motivation for this is that I did not want to require streambufsto behave consistently if their virtuals are called after they havesignaled eof.
The classic case is a streambuf reading from a UNIX file. EOF isn'treally a state for UNIX file descriptors. The convention is that aread on UNIX returns 0 bytes to indicate "EOF", but the filedescriptor isn't shut down in any way and future reads do notnecessarily also return 0 bytes. In particular, you can read fromtty's on UNIX even after they have signaled "EOF". (Itisn't always understood that a ^D on UNIX is not an EOF indicator, butan EOL indicator. By typing a "line" consisting solely of^D you cause a read to return 0 bytes, and by convention this isinterpreted as end of file.)
Proposed resolution:
Add a sentence to the end of 27.6.1.1.2 paragraph 2:
If
is.rdbuf()->sbumpc()oris.rdbuf()->sgetc()returnstraits::eof(), the function callssetstate(failbit | eofbit)(which may throwios_base::failure).