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

Section: 30.7.4.3 [istream.unformatted], 30.7.5.1.4 [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.

Discussion:

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 30.7.4.3 [istream.unformatted] and to the Effects: clause of seekp() in 30.7.5.1.4 [ostream.seeks]:

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

Rationale:

Setting failbit is the usual error reporting mechanism for streams