closing stream before opening sets fail bit
Benjamin Kosnik
bkoz@cygnus.com
Fri Jun 23 12:28:00 GMT 2000
I've added a testcase based on this report, so the current behavior
will be at least codified. I think libstdc++-v3 has
standards-conforming behaivor.
I believe that close() in this case should set failbit. I don't think
that's really unclear -- the question really is if ifstream/ofstream
open resets state...
I think the current libstdc++-v3 behavior is conformant. I agree that
this behavior is perhaps counter-intiutive and needs further
specification. The following defect report also touches on this issue:
-benjamin
-----
22. Member open vs. flags
Section: 27.8.1.7 lib.ifstream.members
Status: DR
Submitter: Nathan
Myers Date: 6 Aug 98
The description of basic_istream<>::open leaves unanswered questions
about how it responds to or changes flags in the error status for the
stream. A strict reading indicates that it ignores the bits and does
not change them, which confuses users who do not expect eofbit and
failbit to remain set after a successful open. There are three
reasonable resolutions: 1) status quo 2) fail if fail(), ignore eofbit
3) clear failbit and eofbit on call to open().
Proposed Resolution:
In 27.8.1.7 [lib.ifstream.members] paragraph 3, _and_ in 27.8.1.10
[lib.ofstream.members] paragraph 3, under open() effects, add a
footnote:
A successful open does not change the error state.
More information about the Libstdc++
mailing list