diff --git a/include/fmt/os.h b/include/fmt/os.h index f6c0f329858c..43ffd3cf0ac8 100644 --- a/include/fmt/os.h +++ b/include/fmt/os.h @@ -401,12 +401,6 @@ class FMT_API ostream final : private detail::buffer { private: file file_; - void flush() { - if (size() == 0) return; - file_.write(data(), size()); - clear(); - } - void grow(size_t) override; ostream(cstring_view path, const detail::ostream_params& params) @@ -426,6 +420,12 @@ class FMT_API ostream final : private detail::buffer { delete[] data(); } + void flush() { + if (size() == 0) return; + file_.write(data(), size()); + clear(); + } + template friend ostream output_file(cstring_view path, T... params); diff --git a/test/os-test.cc b/test/os-test.cc index b2bd20f2a2c9..01ab7036c678 100644 --- a/test/os-test.cc +++ b/test/os-test.cc @@ -336,6 +336,14 @@ TEST(ostream_test, truncate) { EXPECT_EQ("foo", read(in, 4)); } +TEST(ostream_test, flush) { + auto out = fmt::output_file("test-file"); + out.print("x"); + out.flush(); + auto in = fmt::file("test-file", file::RDONLY); + EXPECT_READ(in, "x"); +} + TEST(file_test, default_ctor) { file f; EXPECT_EQ(-1, f.descriptor());