[libcxx] r240286 - Make seeking on an ostream that has eofbit set work correctly. Fixes PR#21361
Marshall Clow
mclow.lists at gmail.com
Mon Jun 22 08:01:21 PDT 2015
Author: marshall
Date: Mon Jun 22 10:01:21 2015
New Revision: 240286
URL: http://llvm.org/viewvc/llvm-project?rev=240286&view=rev
Log:
Make seeking on an ostream that has eofbit set work correctly. Fixes PR#21361
Modified:
libcxx/trunk/include/ostream
libcxx/trunk/test/std/input.output/iostream.format/output.streams/ostream.seeks/seekp.pass.cpp
libcxx/trunk/test/std/input.output/iostream.format/output.streams/ostream.seeks/seekp2.pass.cpp
Modified: libcxx/trunk/include/ostream
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/ostream?rev=240286&r1=240285&r2=240286&view=diff
==============================================================================
--- libcxx/trunk/include/ostream (original)
+++ libcxx/trunk/include/ostream Mon Jun 22 10:01:21 2015
@@ -1004,7 +1004,7 @@ basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
{
sentry __s(*this);
- if (__s)
+ if (!this->fail())
{
if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
this->setstate(ios_base::failbit);
@@ -1018,7 +1018,7 @@ basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
{
sentry __s(*this);
- if (__s)
+ if (!this->fail())
{
if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))
this->setstate(ios_base::failbit);
Modified: libcxx/trunk/test/std/input.output/iostream.format/output.streams/ostream.seeks/seekp.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/input.output/iostream.format/output.streams/ostream.seeks/seekp.pass.cpp?rev=240286&r1=240285&r2=240286&view=diff
==============================================================================
--- libcxx/trunk/test/std/input.output/iostream.format/output.streams/ostream.seeks/seekp.pass.cpp (original)
+++ libcxx/trunk/test/std/input.output/iostream.format/output.streams/ostream.seeks/seekp.pass.cpp Mon Jun 22 10:01:21 2015
@@ -40,11 +40,13 @@ protected:
int main()
{
{
+ seekpos_called = 0;
std::ostream os((std::streambuf*)0);
assert(&os.seekp(5) == &os);
assert(seekpos_called == 0);
}
{
+ seekpos_called = 0;
testbuf<char> sb;
std::ostream os(&sb);
assert(&os.seekp(10) == &os);
@@ -54,4 +56,13 @@ int main()
assert(seekpos_called == 2);
assert(os.fail());
}
+ { // See https://llvm.org/bugs/show_bug.cgi?id=21361
+ seekpos_called = 0;
+ testbuf<char> sb;
+ std::ostream os(&sb);
+ os.setstate(std::ios_base::eofbit);
+ assert(&os.seekp(10) == &os);
+ assert(seekpos_called == 1);
+ assert(os.rdstate() == std::ios_base::eofbit);
+ }
}
Modified: libcxx/trunk/test/std/input.output/iostream.format/output.streams/ostream.seeks/seekp2.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/input.output/iostream.format/output.streams/ostream.seeks/seekp2.pass.cpp?rev=240286&r1=240285&r2=240286&view=diff
==============================================================================
--- libcxx/trunk/test/std/input.output/iostream.format/output.streams/ostream.seeks/seekp2.pass.cpp (original)
+++ libcxx/trunk/test/std/input.output/iostream.format/output.streams/ostream.seeks/seekp2.pass.cpp Mon Jun 22 10:01:21 2015
@@ -42,11 +42,13 @@ protected:
int main()
{
{
+ seekoff_called = 0;
std::ostream os((std::streambuf*)0);
assert(&os.seekp(5, std::ios_base::beg) == &os);
assert(seekoff_called == 0);
}
{
+ seekoff_called = 0;
testbuf<char> sb;
std::ostream os(&sb);
assert(&os.seekp(10, std::ios_base::beg) == &os);
@@ -56,4 +58,13 @@ int main()
assert(seekoff_called == 2);
assert(os.fail());
}
+ { // See https://llvm.org/bugs/show_bug.cgi?id=21361
+ seekoff_called = 0;
+ testbuf<char> sb;
+ std::ostream os(&sb);
+ os.setstate(std::ios_base::eofbit);
+ assert(&os.seekp(10, std::ios_base::beg) == &os);
+ assert(seekoff_called == 1);
+ assert(os.rdstate() == std::ios_base::eofbit);
+ }
}
More information about the cfe-commits
mailing list