//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++03 // // template , class Allocator = allocator > // class basic_stringbuf // basic_stringbuf& operator=(basic_stringbuf&& rhs); #include #include #include #include "make_string.h" #include "test_macros.h" #define STR(S) MAKE_STRING(CharT, S) template struct test_stringbuf : std::basic_stringbuf { using std::basic_stringbuf::basic_stringbuf; // Checks the following requirement after being moved from: // The six pointers of std::basic_streambuf in *this are guaranteed to be different // from the corresponding pointers in the moved-from rhs unless null. void check_different_pointers(test_stringbuf const& other) const { assert(this->eback() == nullptr || this->eback() != other.eback()); assert(this->gptr() == nullptr || this->gptr() != other.gptr()); assert(this->egptr() == nullptr || this->egptr() != other.egptr()); assert(this->pbase() == nullptr || this->pbase() != other.pbase()); assert(this->pptr() == nullptr || this->pptr() != other.pptr()); assert(this->epptr() == nullptr || this->epptr() != other.epptr()); } }; template void test() { std::basic_string strings[] = {STR(""), STR("short"), STR("loooooooooooooooooooong")}; for (std::basic_string const& s : strings) { { test_stringbuf buf1(s); test_stringbuf buf; buf = std::move(buf1); assert(buf.str() == s); buf.check_different_pointers(buf1); } { test_stringbuf buf1(s, std::ios_base::in); test_stringbuf buf; buf = std::move(buf1); assert(buf.str() == s); buf.check_different_pointers(buf1); } { test_stringbuf buf1(s, std::ios_base::out); test_stringbuf buf; buf = std::move(buf1); assert(buf.str() == s); buf.check_different_pointers(buf1); } { test_stringbuf buf1; test_stringbuf buf; buf = std::move(buf1); buf.check_different_pointers(buf1); } // Use the assignment operator on an actual std::stringbuf, not test_stringbuf { std::basic_stringbuf buf1(s); std::basic_stringbuf buf; buf = std::move(buf1); assert(buf.str() == s); } } } int main(int, char**) { test(); #ifndef TEST_HAS_NO_WIDE_CHARACTERS test(); #endif return 0; }