This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of TC1 status.

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

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

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