diff --git a/include/fmt/os.h b/include/fmt/os.h index caf6a4b2..66e66678 100644 --- a/include/fmt/os.h +++ b/include/fmt/os.h @@ -396,7 +396,9 @@ class ostream : private detail::buffer { } public: - ostream(ostream&& other) : file_(std::move(other.file_)) { + ostream(ostream&& other) + : detail::buffer(other.data(), other.size(), other.capacity()), + file_(std::move(other.file_)) { other.set(nullptr, 0); } ~ostream() { diff --git a/test/os-test.cc b/test/os-test.cc index 4a54c063..359b5ff8 100644 --- a/test/os-test.cc +++ b/test/os-test.cc @@ -287,6 +287,12 @@ TEST(BufferedFileTest, Fileno) { EXPECT_READ(copy, FILE_CONTENT); } +TEST(OStreamTest, Move) { + fmt::ostream out = fmt::output_file("test-file"); + fmt::ostream moved(std::move(out)); + moved.print("hello"); +} + TEST(OStreamTest, Print) { fmt::ostream out = fmt::output_file("test-file"); out.print("The answer is {}.\n", 42);