Title
Inconsistency between basic_ostream::seekp(pos) and basic_ostream::seekp(off, dir)
Status
c++14
Section
[ostream.seeks]
Submitter
Marshall Clow

Created on 2013-10-21.00:00:00 last changed 130 months ago

Messages

Date: 2014-02-13.06:35:03

Proposed resolution:

This wording is relative to N3797.

  1. Modify [ostream.seeks]p5 as indicated:

    basic_ostream<charT,traits>& seekp(off_type off, ios_base::seekdir dir);
    

    -5- Effects: If fail() != true, executes rdbuf()->pubseekoff(off, dir, ios_base::out). In case of failure, the function calls setstate(failbit) (which may throw ios_base::failure).

    -6- Returns: *this.

Date: 2014-02-13.06:35:03

[ Issaquah 2014-02-11: Move to Immediate ]

Date: 2013-10-21.00:00:00

In [ostream.seeks], we have:

basic_ostream<charT,traits>& seekp(pos_type pos);

-3- Effects: If fail() != true, executes rdbuf()->pubseekpos(pos, ios_base::out). In case of failure, the function calls setstate(failbit) (which may throw ios_base::failure).

-4- Returns: *this.

basic_ostream<charT,traits>& seekp(off_type off, ios_base::seekdir dir);

-5- Effects: If fail() != true, executes rdbuf()->pubseekoff(off, dir, ios_base::out).

-6- Returns: *this.

The first call is required to set the failbit on failure, but the second is not

So (given two ostreams, os1 and os2) the following code (confusingly) works:

os1.seekp(-1);
assert(os1.fail());

os2.seekp(-1, std::ios_base::beg);
assert(os2.good());

Note that the description of basic_istream<charT,traits>& seekg(off_type off, ios_base::seekdir dir) in [istream.unformatted] p43 does require setting failbit.

History
Date User Action Args
2014-02-27 17:03:20adminsetstatus: wp -> c++14
2014-02-20 13:52:38adminsetstatus: immediate -> wp
2014-02-13 06:35:03adminsetmessages: + msg6837
2014-02-13 06:35:03adminsetstatus: new -> immediate
2013-10-22 18:36:28adminsetmessages: + msg6760
2013-10-21 00:00:00admincreate