summaryrefslogtreecommitdiff
path: root/libcxx
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2013-10-31 22:20:45 +0000
committerMarshall Clow <mclow.lists@gmail.com>2013-10-31 22:20:45 +0000
commite1bedf4e939995fc190700f4a8a7fa12410c8577 (patch)
tree8fb53c0442dd52489410c92bcb1f55471600d286 /libcxx
parentModify CMakeLists.txt to work around pr17763 and bring some bots back. (diff)
downloadllvm-project-e1bedf4e939995fc190700f4a8a7fa12410c8577.tar.gz
llvm-project-e1bedf4e939995fc190700f4a8a7fa12410c8577.tar.bz2
llvm-project-e1bedf4e939995fc190700f4a8a7fa12410c8577.zip
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
Diffstat (limited to 'libcxx')
-rw-r--r--libcxx/include/istream7
-rw-r--r--libcxx/include/ostream11
-rw-r--r--libcxx/test/input.output/iostream.format/input.streams/istream.unformatted/seekg_off.pass.cpp8
-rw-r--r--libcxx/test/input.output/iostream.format/output.streams/ostream.seeks/seekp2.pass.cpp2
4 files changed, 22 insertions, 6 deletions
diff --git a/libcxx/include/istream b/libcxx/include/istream
index 7284fc1fee06..14fa466057cf 100644
--- a/libcxx/include/istream
+++ b/libcxx/include/istream
@@ -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 (...)
diff --git a/libcxx/include/ostream b/libcxx/include/ostream
index 2c618d41b9dd..041314acc756 100644
--- a/libcxx/include/ostream
+++ b/libcxx/include/ostream
@@ -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;
}
diff --git a/libcxx/test/input.output/iostream.format/input.streams/istream.unformatted/seekg_off.pass.cpp b/libcxx/test/input.output/iostream.format/input.streams/istream.unformatted/seekg_off.pass.cpp
index 005b3b48446c..73f3da1c6bd1 100644
--- a/libcxx/test/input.output/iostream.format/input.streams/istream.unformatted/seekg_off.pass.cpp
+++ b/libcxx/test/input.output/iostream.format/input.streams/istream.unformatted/seekg_off.pass.cpp
@@ -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);
}
}
diff --git a/libcxx/test/input.output/iostream.format/output.streams/ostream.seeks/seekp2.pass.cpp b/libcxx/test/input.output/iostream.format/output.streams/ostream.seeks/seekp2.pass.cpp
index 16fbf6560769..69b26f3a96e8 100644
--- a/libcxx/test/input.output/iostream.format/output.streams/ostream.seeks/seekp2.pass.cpp
+++ b/libcxx/test/input.output/iostream.format/output.streams/ostream.seeks/seekp2.pass.cpp
@@ -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());
}
}