From 6cccdc24bcb8605965c1e2497c61504cd388bde9 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 1 Sep 2020 08:16:53 -0700 Subject: [PATCH] Fix move constructor (#1844) --- include/fmt/os.h | 4 +++- test/os-test.cc | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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);