[libcxx-commits] [libcxx] [libc++] Port #200996 to ostream (PR #226372)
Nico Weber via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Sep 24 23:18:14 PDT 2026
https://github.com/nico created https://github.com/llvm/llvm-project/pull/226372
Reduces the time to compile a TU with just `#include <ostream>` from 254.7 ms ± 3.0 ms to 227.7 ms ± 2.1 ms on my system (-std=c++23, -O2, arm64 macOS).
See #195466 for details. Without this, the call is evaluated when the template is parsed, which evaluates format_string's consteval constructor for "\n" in every translation unit that includes <ostream>, even if nothing calls println().
No behavior change.
>From 57b2c0c5520b00f431028e809ee80898f65a1deb Mon Sep 17 00:00:00 2001
From: Nico Weber <thakis at chromium.org>
Date: Sun, 20 Sep 2026 13:23:25 -0400
Subject: [PATCH] [libc++] Port #200996 to ostream
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Reduces the time to compile a TU with just `#include <ostream>`
from 254.7 ms ± 3.0 ms to 227.7 ms ± 2.1 ms on my system
(-std=c++23, -O2, arm64 macOS).
See #195466 for details. Without this, the call is evaluated
when the template is parsed, which evaluates format_string's consteval
constructor for "\n" in every translation unit that includes <ostream>,
even if nothing calls println().
No behavior change.
---
libcxx/include/__ostream/print.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libcxx/include/__ostream/print.h b/libcxx/include/__ostream/print.h
index 4a519c177b990d..f9810a4d7d26a0 100644
--- a/libcxx/include/__ostream/print.h
+++ b/libcxx/include/__ostream/print.h
@@ -159,9 +159,9 @@ _LIBCPP_HIDE_FROM_ABI void println(ostream& __os, format_string<_Args...> __fmt,
# endif // _LIBCPP_HAS_UNICODE
}
-template <class = void> // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563).
+template <class _Void = void> // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563).
_LIBCPP_HIDE_FROM_ABI inline void println(ostream& __os) {
- std::print(__os, "\n");
+ std::print(__os, (_Void(), "\n"));
}
# endif // _LIBCPP_STD_VER >= 23
More information about the libcxx-commits
mailing list