[libcxx] r350603 - Set the buffer of an fstream to empty when the underlying file is closed. This 'fixes' PR#38052 - std::fstream still good after closing and updating content.
Marshall Clow
mclow.lists at gmail.com
Mon Jan 7 18:48:45 PST 2019
Author: marshall
Date: Mon Jan 7 18:48:45 2019
New Revision: 350603
URL: http://llvm.org/viewvc/llvm-project?rev=350603&view=rev
Log:
Set the buffer of an fstream to empty when the underlying file is closed. This 'fixes' PR#38052 - std::fstream still good after closing and updating content.
Added:
libcxx/trunk/test/libcxx/input.output/file.streams/fstreams/fstream.close.pass.cpp
Modified:
libcxx/trunk/include/fstream
Modified: libcxx/trunk/include/fstream
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/fstream?rev=350603&r1=350602&r2=350603&view=diff
==============================================================================
--- libcxx/trunk/include/fstream (original)
+++ libcxx/trunk/include/fstream Mon Jan 7 18:48:45 2019
@@ -702,6 +702,7 @@ basic_filebuf<_CharT, _Traits>::close()
__file_ = 0;
else
__rt = 0;
+ setbuf(0, 0);
}
return __rt;
}
Added: libcxx/trunk/test/libcxx/input.output/file.streams/fstreams/fstream.close.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/input.output/file.streams/fstreams/fstream.close.pass.cpp?rev=350603&view=auto
==============================================================================
--- libcxx/trunk/test/libcxx/input.output/file.streams/fstreams/fstream.close.pass.cpp (added)
+++ libcxx/trunk/test/libcxx/input.output/file.streams/fstreams/fstream.close.pass.cpp Mon Jan 7 18:48:45 2019
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+// <fstream>
+
+// template <class charT, class traits = char_traits<charT> >
+// class basic_fstream
+
+// close();
+
+// Inspired by PR#38052 - std::fstream still good after closing and updating content
+
+#include <fstream>
+#include <cassert>
+#include "platform_support.h"
+
+int main()
+{
+ std::string temp = get_temp_file_name();
+
+ std::fstream ofs(temp, std::ios::out | std::ios::trunc);
+ ofs << "Hello, World!\n";
+ assert( ofs.good());
+ ofs.close();
+ assert( ofs.good());
+ ofs << "Hello, World!\n";
+ assert(!ofs.good());
+
+ std::remove(temp.c_str());
+}
More information about the libcxx-commits
mailing list