[libcxx-commits] [libcxx] [libc++] Fix unnecessary flushes in std::print() on POSIX (PR #70321)

Dimitrij Mijoski via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 10 03:07:41 PDT 2026


================
@@ -236,26 +236,11 @@ __vprint_nonunicode(FILE* __stream, string_view __fmt, format_args __args, bool
 // terminal when the output is redirected. Typically during testing the
 // output is redirected to be able to capture it. This makes it hard to
 // test this code path.
-template <class = void> // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563).
-_LIBCPP_HIDE_FROM_ABI inline void
-__vprint_unicode_posix(FILE* __stream, string_view __fmt, format_args __args, bool __write_nl, bool __is_terminal) {
-  // TODO PRINT Should flush errors throw too?
-  if (__is_terminal)
-    std::fflush(__stream);
-
-  __print::__vprint_nonunicode(__stream, __fmt, __args, __write_nl);
-}
 
 #      if _LIBCPP_HAS_WIDE_CHARACTERS
 template <class = void> // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563).
 _LIBCPP_HIDE_FROM_ABI inline void
-__vprint_unicode_windows(FILE* __stream, string_view __fmt, format_args __args, bool __write_nl, bool __is_terminal) {
-  if (!__is_terminal)
-    return __print::__vprint_nonunicode(__stream, __fmt, __args, __write_nl);
-
-  // TODO PRINT Should flush errors throw too?
-  std::fflush(__stream);
----------------
dimztimz wrote:

The flush is moved about 50 lines below because previously in the ostream case (`__vprint_unicode(ostream&,...`) two flushes were done, one via `os.flush()` and another via `fflush`. With this fix on Windows only one flush is done in both variants and on POSIX no flushes are done because there is no separate "native Unicode API" there.

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


More information about the libcxx-commits mailing list