[libcxx-commits] [libcxx] [libc++] Fix filebuf resetting its underlying buffer upon close() (PR #168947)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Nov 21 03:22:46 PST 2025
================
@@ -0,0 +1,132 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// This test requires the fix to std::filebuf::close() (which is defined in the
+// built library) from https://github.com/llvm/llvm-project/pull/168947.
+// UNSUPPORTED: using-built-library-before-llvm-22
+
+// <fstream>
+
+// basic_filebuf<charT,traits>* close();
+
+//
+// Ensure that basic_filebuf::close() does not get rid of the underlying buffer set
+// via pubsetbuf(). Otherwise, reopening the stream will result in not reusing the
+// same buffer, which might be conforming but is definitely surprising. The standard
+// is not very clear on whether that is actually conforming.
----------------
philnik777 wrote:
I think the standard is quite clear. `setbuf` has implementation-defined behaviour except for `setbuf(0, 0)` (https://eel.is/c++draft/input.output#filebuf.virtuals-12), so we can do whatever we want in terms of buffering and when we throw away buffers. Speaking of, this seems to want an entry in `ImplementationDefinedBehavior.rst`.
https://github.com/llvm/llvm-project/pull/168947
More information about the libcxx-commits
mailing list