diff --git a/libcxx/include/sstream b/libcxx/include/sstream --- a/libcxx/include/sstream +++ b/libcxx/include/sstream @@ -420,10 +420,9 @@ this->__pbump(__nout); } __hm_ = __hm == -1 ? nullptr : __p + __hm; - __p = const_cast(__rhs.__str_.data()); - __rhs.setg(__p, __p, __p); - __rhs.setp(__p, __p); - __rhs.__hm_ = __p; + __rhs.setg(nullptr, nullptr, nullptr); + __rhs.setp(nullptr, nullptr); + __rhs.__hm_ = nullptr; this->pubimbue(__rhs.getloc()); } @@ -467,10 +466,9 @@ __hm_ = __hm == -1 ? nullptr : __p + __hm; __mode_ = __rhs.__mode_; - __p = const_cast(__rhs.__str_.data()); - __rhs.setg(__p, __p, __p); - __rhs.setp(__p, __p); - __rhs.__hm_ = __p; + __rhs.setg(nullptr, nullptr, nullptr); + __rhs.setp(nullptr, nullptr); + __rhs.__hm_ = nullptr; this->pubimbue(__rhs.getloc()); return *this; } diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.assign/move.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.assign/move.pass.cpp --- a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.assign/move.pass.cpp +++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.assign/move.pass.cpp @@ -16,48 +16,53 @@ #include #include +#include "make_string.h" #include "test_macros.h" -int main(int, char**) -{ - { - std::stringbuf buf1("testing"); - std::stringbuf buf; - buf = std::move(buf1); - assert(buf.str() == "testing"); - } - { - std::stringbuf buf1("testing", std::ios_base::in); - std::stringbuf buf; - buf = std::move(buf1); - assert(buf.str() == "testing"); - } - { - std::stringbuf buf1("testing", std::ios_base::out); - std::stringbuf buf; - buf = std::move(buf1); - assert(buf.str() == "testing"); - } -#ifndef TEST_HAS_NO_WIDE_CHARACTERS - { - std::wstringbuf buf1(L"testing"); - std::wstringbuf buf; - buf = std::move(buf1); - assert(buf.str() == L"testing"); - } - { - std::wstringbuf buf1(L"testing", std::ios_base::in); - std::wstringbuf buf; - buf = std::move(buf1); - assert(buf.str() == L"testing"); - } - { - std::wstringbuf buf1(L"testing", std::ios_base::out); - std::wstringbuf buf; - buf = std::move(buf1); - assert(buf.str() == L"testing"); - } -#endif // TEST_HAS_NO_WIDE_CHARACTERS +#define STR(S) MAKE_STRING(CharT, S) + +template +struct test_stringbuf : std::basic_stringbuf { + using std::basic_stringbuf::basic_stringbuf; + void check() { + LIBCPP_ASSERT(this->eback() == nullptr); + LIBCPP_ASSERT(this->gptr() == nullptr); + LIBCPP_ASSERT(this->egptr() == nullptr); + LIBCPP_ASSERT(this->pbase() == nullptr); + LIBCPP_ASSERT(this->pptr() == nullptr); + LIBCPP_ASSERT(this->epptr() == nullptr); + } +}; +template +static void test() { + { + test_stringbuf buf1(STR("testing")); + std::basic_stringbuf buf; + buf = std::move(buf1); + assert(buf.str() == STR("testing")); + buf1.check(); + } + { + test_stringbuf buf1(STR("testing"), std::ios_base::in); + std::basic_stringbuf buf; + buf = std::move(buf1); + assert(buf.str() == STR("testing")); + buf1.check(); + } + { + test_stringbuf buf1(STR("testing"), std::ios_base::out); + std::basic_stringbuf buf; + buf = std::move(buf1); + assert(buf.str() == STR("testing")); + buf1.check(); + } +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif return 0; } diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/move.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/move.alloc.pass.cpp --- a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/move.alloc.pass.cpp +++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/move.alloc.pass.cpp @@ -25,13 +25,27 @@ #define STR(S) MAKE_STRING(CharT, S) #define SV(S) MAKE_STRING_VIEW(CharT, S) +template +struct test_stringbuf : std::basic_stringbuf, test_allocator> { + using std::basic_stringbuf, test_allocator>::basic_stringbuf; + void check() { + LIBCPP_ASSERT(this->eback() == nullptr); + LIBCPP_ASSERT(this->gptr() == nullptr); + LIBCPP_ASSERT(this->egptr() == nullptr); + LIBCPP_ASSERT(this->pbase() == nullptr); + LIBCPP_ASSERT(this->pptr() == nullptr); + LIBCPP_ASSERT(this->epptr() == nullptr); + } +}; + template static void test() { - std::basic_stringbuf, test_allocator> buf1(STR("testing")); + test_stringbuf buf1(STR("testing")); const test_allocator a(2); const std::basic_stringbuf, test_allocator> buf(std::move(buf1), a); assert(buf.get_allocator() == a); assert(buf.view() == SV("testing")); + buf1.check(); } int main(int, char**) { diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/move.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/move.pass.cpp --- a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/move.pass.cpp +++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/move.pass.cpp @@ -16,42 +16,50 @@ #include #include +#include "make_string.h" #include "test_macros.h" -int main(int, char**) -{ - { - std::stringbuf buf1("testing"); - std::stringbuf buf(std::move(buf1)); - assert(buf.str() == "testing"); - } - { - std::stringbuf buf1("testing", std::ios_base::in); - std::stringbuf buf(std::move(buf1)); - assert(buf.str() == "testing"); - } - { - std::stringbuf buf1("testing", std::ios_base::out); - std::stringbuf buf(std::move(buf1)); - assert(buf.str() == "testing"); - } +#define STR(S) MAKE_STRING(CharT, S) + +template +struct test_stringbuf : std::basic_stringbuf { + using std::basic_stringbuf::basic_stringbuf; + void check() { + LIBCPP_ASSERT(this->eback() == nullptr); + LIBCPP_ASSERT(this->gptr() == nullptr); + LIBCPP_ASSERT(this->egptr() == nullptr); + LIBCPP_ASSERT(this->pbase() == nullptr); + LIBCPP_ASSERT(this->pptr() == nullptr); + LIBCPP_ASSERT(this->epptr() == nullptr); + } +}; + +template +static void test() { + { + test_stringbuf buf1(STR("testing")); + std::basic_stringbuf buf(std::move(buf1)); + assert(buf.str() == STR("testing")); + buf1.check(); + } + { + test_stringbuf buf1(STR("testing"), std::ios_base::in); + std::basic_stringbuf buf(std::move(buf1)); + assert(buf.str() == STR("testing")); + buf1.check(); + } + { + test_stringbuf buf1(STR("testing"), std::ios_base::out); + std::basic_stringbuf buf(std::move(buf1)); + assert(buf.str() == STR("testing")); + buf1.check(); + } +} + +int main(int, char**) { + test(); #ifndef TEST_HAS_NO_WIDE_CHARACTERS - { - std::wstringbuf buf1(L"testing"); - std::wstringbuf buf(std::move(buf1)); - assert(buf.str() == L"testing"); - } - { - std::wstringbuf buf1(L"testing", std::ios_base::in); - std::wstringbuf buf(std::move(buf1)); - assert(buf.str() == L"testing"); - } - { - std::wstringbuf buf1(L"testing", std::ios_base::out); - std::wstringbuf buf(std::move(buf1)); - assert(buf.str() == L"testing"); - } + test(); #endif - return 0; }