LWG issue 2341; Make the two variants of basic_ostream::seekp and basic_istream::seekg behave consistently; update tests to make sure

llvm-svn: 193814
This commit is contained in:
Marshall Clow 2013-10-31 22:20:45 +00:00
parent fc0447b8e4
commit e1bedf4e93
4 changed files with 22 additions and 6 deletions

View File

@ -1369,8 +1369,10 @@ basic_istream<_CharT, _Traits>::seekg(pos_type __pos)
this->clear(this->rdstate() & ~ios_base::eofbit);
sentry __sen(*this, true);
if (__sen)
{
if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1))
this->setstate(ios_base::failbit);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
@ -1391,7 +1393,10 @@ basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir)
#endif // _LIBCPP_NO_EXCEPTIONS
sentry __sen(*this, true);
if (__sen)
this->rdbuf()->pubseekoff(__off, __dir, ios_base::in);
{
if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::in) == pos_type(-1))
this->setstate(ios_base::failbit);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)

View File

@ -1159,7 +1159,8 @@ inline _LIBCPP_INLINE_VISIBILITY
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
{
if (!this->fail())
sentry __s(*this);
if (__s)
{
if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
this->setstate(ios_base::failbit);
@ -1172,8 +1173,12 @@ inline _LIBCPP_INLINE_VISIBILITY
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
{
if (!this->fail())
this->rdbuf()->pubseekoff(__off, __dir, ios_base::out);
sentry __s(*this);
if (__s)
{
if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))
this->setstate(ios_base::failbit);
}
return *this;
}

View File

@ -57,12 +57,18 @@ int main()
is.seekg(5, std::ios_base::cur);
assert(is.good());
assert(seekoff_called == 1);
is.seekg(-1, std::ios_base::beg);
assert(is.fail());
assert(seekoff_called == 2);
}
{
testbuf<wchar_t> sb(L" 123456789");
std::wistream is(&sb);
is.seekg(5, std::ios_base::cur);
assert(is.good());
assert(seekoff_called == 2);
assert(seekoff_called == 3);
is.seekg(-1, std::ios_base::beg);
assert(is.fail());
assert(seekoff_called == 4);
}
}

View File

@ -54,6 +54,6 @@ int main()
assert(os.good());
assert(&os.seekp(-1, std::ios_base::beg) == &os);
assert(seekoff_called == 2);
assert(os.good());
assert(os.fail());
}
}