129. Need error indication from seekp() and seekg()

Section: [istream.unformatted], [ostream.seeks] Status: TC1 Submitter: Angelika Langer Opened: 1999-02-22 Last modified: 2016-02-10

Priority: Not Prioritized

View all other issues in [istream.unformatted].

View all issues with TC1 status.


Currently, the standard does not specify how seekg() and seekp() indicate failure. They are not required to set failbit, and they can't return an error indication because they must return *this, i.e. the stream. Hence, it is undefined what happens if they fail. And they can fail, for instance, when a file stream is disconnected from the underlying file (is_open()==false) or when a wide character file stream must perform a state-dependent code conversion, etc.

The stream functions seekg() and seekp() should set failbit in the stream state in case of failure.

Proposed resolution:

Add to the Effects: clause of  seekg() in [istream.unformatted] and to the Effects: clause of seekp() in [ostream.seeks]:

In case of failure, the function calls setstate(failbit) (which may throw ios_base::failure).


Setting failbit is the usual error reporting mechanism for streams