summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2017-12-19 23:33:16 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2017-12-19 23:33:16 +0000
commit4b54e0fc2abfe7b1fa48425d8e72eb6a146ba49c (patch)
tree40ece12b92a02ed7a0f0e411487ccc54ae8105fa /test
parent5638e7b9c4143cbef0f12405ce65bf7b1dd1c13d (diff)
libcxx: Fix for basic_stringbuf::seekoff() after r320604.
As a result of this change, the basic_stringbuf constructor that takes a mode ends up leaving __hm_ set to 0, causing the comparison "__hm_ - __str_.data() < __noff" in seekoff() to succeed, which caused the function to incorrectly return -1. The fix is to account for the possibility of __hm_ being 0 when computing the distance from __hm_ to the start of the string. Differential Revision: https://reviews.llvm.org/D41319 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@321124 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/seekoff.pass.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/seekoff.pass.cpp b/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/seekoff.pass.cpp
index 6d20db131..8ec69cb24 100644
--- a/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/seekoff.pass.cpp
+++ b/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/seekoff.pass.cpp
@@ -21,6 +21,30 @@
int main()
{
{
+ std::stringbuf sb(std::ios_base::in);
+ assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out) == -1);
+ assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out) == -1);
+ assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out) == -1);
+ assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in | std::ios_base::out) == -1);
+ assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in | std::ios_base::out) == -1);
+ assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in | std::ios_base::out) == -1);
+ assert(sb.pubseekoff(0, std::ios_base::beg, std::ios_base::in) == 0);
+ assert(sb.pubseekoff(0, std::ios_base::cur, std::ios_base::in) == 0);
+ assert(sb.pubseekoff(0, std::ios_base::end, std::ios_base::in) == 0);
+ }
+ {
+ std::stringbuf sb(std::ios_base::out);
+ assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in) == -1);
+ assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in) == -1);
+ assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in) == -1);
+ assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in | std::ios_base::out) == -1);
+ assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in | std::ios_base::out) == -1);
+ assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in | std::ios_base::out) == -1);
+ assert(sb.pubseekoff(0, std::ios_base::beg, std::ios_base::out) == 0);
+ assert(sb.pubseekoff(0, std::ios_base::cur, std::ios_base::out) == 0);
+ assert(sb.pubseekoff(0, std::ios_base::end, std::ios_base::out) == 0);
+ }
+ {
std::stringbuf sb("0123456789", std::ios_base::in);
assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out) == -1);
assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out) == -1);