[libcxx-commits] [libcxx] [libc++] Implements filebuf unbuffered. (PR #76629)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 5 09:23:33 PST 2024


================
@@ -308,6 +308,43 @@ private:
   state_type __st_;
   state_type __st_last_;
   ios_base::openmode __om_;
+  // There have been no file operations yet, which allows setting unbuffered
+  // I/O mode.
+  static const ios_base::openmode __no_io_operations = ios_base::trunc;
+  // Unbuffered I/O mode has been requested.
+  static const ios_base::openmode __use_unbuffered_io = ios_base::ate;
+  // Used to track the currently used mode and track whether the output should
+  // be unbuffered.
+  // [filebuf.virtuals]/12
+  //   If setbuf(0, 0) is called on a stream before any I/O has occurred on
----------------
ldionne wrote:

I wonder what is meant by "any I/O operation" here. Is `open` considered an IO operation? libstdc++ seems to think it is, since it doesn't make the stream unbuffered if it is already open: https://godbolt.org/z/T1G94174c. Either this patch is wrong (and libstdc++ is right), or libstdc++ is wrong in its handling of a stream that is already `open`.

Naively, I would expect that just opening a file and not reading/writing anything isn't considered "an IO operation", which means that this patch is correct and libstdc++ is wrong. But I don't know the iostreams spec very well, so I could be wrong. CC @jwakely 

https://github.com/llvm/llvm-project/pull/76629


More information about the libcxx-commits mailing list