[libcxx-commits] [libcxx] [libc++] Refactor std::print to allow for constant folding of the format part (PR #185459)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Mar 13 07:02:41 PDT 2026


================
@@ -207,20 +207,18 @@ _LIBCPP_HIDE_FROM_ABI inline bool __is_terminal([[maybe_unused]] FILE* __stream)
 }
 #    endif // _LIBCPP_WIN32API
 
+[[noreturn]] _LIBCPP_HIDE_FROM_ABI inline void __handle_output_error(FILE* __stream) {
+  if (std::feof(__stream))
+    std::__throw_system_error(EIO, "EOF while writing the formatted output");
+  std::__throw_system_error(std::ferror(__stream), "failed to write formatted output");
+}
+
 template <class = void> // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563).
-_LIBCPP_HIDE_FROM_ABI inline void
-__vprint_nonunicode(FILE* __stream, string_view __fmt, format_args __args, bool __write_nl) {
+_LIBCPP_HIDE_FROM_ABI inline void __output_nonunicode(FILE* __stream, string_view __text) {
   _LIBCPP_ASSERT_NON_NULL(__stream, "__stream must be a valid pointer to an output C stream");
-  string __str = std::vformat(__fmt, __args);
-  if (__write_nl)
-    __str.push_back('\n');
-
-  size_t __size = fwrite(__str.data(), 1, __str.size(), __stream);
-  if (__size < __str.size()) {
-    if (std::feof(__stream))
-      std::__throw_system_error(EIO, "EOF while writing the formatted output");
-    std::__throw_system_error(std::ferror(__stream), "failed to write formatted output");
-  }
+  size_t __size = fwrite(__text.data(), 1, __text.size(), __stream);
----------------
ldionne wrote:

```suggestion
  size_t __size = std::fwrite(__text.data(), 1, __text.size(), __stream);
```

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


More information about the libcxx-commits mailing list