LWG issue 2341; Make the two variants of basic_ostream::seekp and basic_istream::seekg behave consistently; update tests to make sure
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@193814 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
09f8550e1c
commit
76a8670ce4
@ -1369,8 +1369,10 @@ basic_istream<_CharT, _Traits>::seekg(pos_type __pos)
|
|||||||
this->clear(this->rdstate() & ~ios_base::eofbit);
|
this->clear(this->rdstate() & ~ios_base::eofbit);
|
||||||
sentry __sen(*this, true);
|
sentry __sen(*this, true);
|
||||||
if (__sen)
|
if (__sen)
|
||||||
|
{
|
||||||
if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1))
|
if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1))
|
||||||
this->setstate(ios_base::failbit);
|
this->setstate(ios_base::failbit);
|
||||||
|
}
|
||||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
@ -1391,7 +1393,10 @@ basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir)
|
|||||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||||
sentry __sen(*this, true);
|
sentry __sen(*this, true);
|
||||||
if (__sen)
|
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
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
|
@ -1159,7 +1159,8 @@ inline _LIBCPP_INLINE_VISIBILITY
|
|||||||
basic_ostream<_CharT, _Traits>&
|
basic_ostream<_CharT, _Traits>&
|
||||||
basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
|
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))
|
if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
|
||||||
this->setstate(ios_base::failbit);
|
this->setstate(ios_base::failbit);
|
||||||
@ -1172,8 +1173,12 @@ inline _LIBCPP_INLINE_VISIBILITY
|
|||||||
basic_ostream<_CharT, _Traits>&
|
basic_ostream<_CharT, _Traits>&
|
||||||
basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
|
basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
|
||||||
{
|
{
|
||||||
if (!this->fail())
|
sentry __s(*this);
|
||||||
this->rdbuf()->pubseekoff(__off, __dir, ios_base::out);
|
if (__s)
|
||||||
|
{
|
||||||
|
if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))
|
||||||
|
this->setstate(ios_base::failbit);
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,12 +57,18 @@ int main()
|
|||||||
is.seekg(5, std::ios_base::cur);
|
is.seekg(5, std::ios_base::cur);
|
||||||
assert(is.good());
|
assert(is.good());
|
||||||
assert(seekoff_called == 1);
|
assert(seekoff_called == 1);
|
||||||
|
is.seekg(-1, std::ios_base::beg);
|
||||||
|
assert(is.fail());
|
||||||
|
assert(seekoff_called == 2);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
testbuf<wchar_t> sb(L" 123456789");
|
testbuf<wchar_t> sb(L" 123456789");
|
||||||
std::wistream is(&sb);
|
std::wistream is(&sb);
|
||||||
is.seekg(5, std::ios_base::cur);
|
is.seekg(5, std::ios_base::cur);
|
||||||
assert(is.good());
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,6 @@ int main()
|
|||||||
assert(os.good());
|
assert(os.good());
|
||||||
assert(&os.seekp(-1, std::ios_base::beg) == &os);
|
assert(&os.seekp(-1, std::ios_base::beg) == &os);
|
||||||
assert(seekoff_called == 2);
|
assert(seekoff_called == 2);
|
||||||
assert(os.good());
|
assert(os.fail());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user