[libcxx-commits] [libcxx] [libcxx][format] Partial P3391R2: `constexpr` `std::format` (PR #230239)
Lucas Mellone via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Oct 8 12:55:05 PDT 2026
https://github.com/lknknm updated https://github.com/llvm/llvm-project/pull/230239
>From 97060ca57e671661ac49aaed4c95bcccb734530e Mon Sep 17 00:00:00 2001
From: Lucas Mellone <github.snugness349 at passinbox.com>
Date: Thu, 8 Oct 2026 20:01:24 +0200
Subject: [PATCH 1/7] initial commit
---
libcxx/docs/Status/Cxx26Papers.csv | 2 +-
libcxx/include/__format/format_functions.h | 32 ++++++++++++----------
libcxx/include/format | 30 ++++++++++----------
3 files changed, 33 insertions(+), 31 deletions(-)
diff --git a/libcxx/docs/Status/Cxx26Papers.csv b/libcxx/docs/Status/Cxx26Papers.csv
index f3cdf8c53bab42..ef9e5d5c38f823 100644
--- a/libcxx/docs/Status/Cxx26Papers.csv
+++ b/libcxx/docs/Status/Cxx26Papers.csv
@@ -175,7 +175,7 @@
"`P3887R1 <https://wg21.link/P3887R1>`__","Make ``when_all`` a Ronseal Algorithm","2025-11 (Kona)","","","`#171289 <https://github.com/llvm/llvm-project/issues/171289>`__",""
"`P3923R0 <https://wg21.link/P3923R0>`__","Additional NB comment resolutions for Kona 2025","2025-11 (Kona)","","","`#171290 <https://github.com/llvm/llvm-project/issues/171290>`__",""
"`P3371R5 <https://wg21.link/P3371R5>`__","Fix C++26 by making the rank-1, rank-2, rank-k, and rank-2k updates consistent with the BLAS","2025-11 (Kona)","","","`#171291 <https://github.com/llvm/llvm-project/issues/171291>`__",""
-"`P3391R2 <https://wg21.link/P3391R2>`__","``constexpr`` ``std::format``","2025-11 (Kona)","","","`#171292 <https://github.com/llvm/llvm-project/issues/171292>`__",""
+"`P3391R2 <https://wg21.link/P3391R2>`__","``constexpr`` ``std::format``","2025-11 (Kona)","|Complete|","24","`#171292 <https://github.com/llvm/llvm-project/issues/171292>`__",""
"`P3913R1 <https://wg21.link/P3913R1>`__","Optimize ``for std::optional`` in range adaptors","2025-11 (Kona)","","","`#171294 <https://github.com/llvm/llvm-project/issues/171294>`__",""
"","","","","","",""
"`P3726R2 <https://wg21.link/P3726R2>`__","Adjustments to Union Lifetime Rules","2026-03 (Croydon)","","","`#189560 <https://github.com/llvm/llvm-project/issues/189560>`__",""
diff --git a/libcxx/include/__format/format_functions.h b/libcxx/include/__format/format_functions.h
index 8f214a493a49ec..2cdcf79b05bf22 100644
--- a/libcxx/include/__format/format_functions.h
+++ b/libcxx/include/__format/format_functions.h
@@ -351,15 +351,15 @@ struct __dynamic_format_string {
friend struct basic_format_string;
public:
- _LIBCPP_HIDE_FROM_ABI __dynamic_format_string(basic_string_view<_CharT> __s) noexcept : __str_(__s) {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __dynamic_format_string(basic_string_view<_CharT> __s) noexcept : __str_(__s) {}
__dynamic_format_string(const __dynamic_format_string&) = delete;
__dynamic_format_string& operator=(const __dynamic_format_string&) = delete;
};
-_LIBCPP_HIDE_FROM_ABI inline __dynamic_format_string<char> dynamic_format(string_view __fmt) noexcept { return __fmt; }
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 inline __dynamic_format_string<char> dynamic_format(string_view __fmt) noexcept { return __fmt; }
# if _LIBCPP_HAS_WIDE_CHARACTERS
-_LIBCPP_HIDE_FROM_ABI inline __dynamic_format_string<wchar_t> dynamic_format(wstring_view __fmt) noexcept {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 inline __dynamic_format_string<wchar_t> dynamic_format(wstring_view __fmt) noexcept {
return __fmt;
}
# endif
@@ -425,27 +425,28 @@ _LIBCPP_HIDE_FROM_ABI _OutIt __vformat_to(_OutIt __out_it,
// https://reviews.llvm.org/D110499#inline-1180704
// TODO FMT Evaluate whether we want to file a Clang bug report regarding this.
template <output_iterator<const char&> _OutIt>
-_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt vformat_to(_OutIt __out_it, string_view __fmt, format_args __args) {
+_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt
+vformat_to(_OutIt __out_it, string_view __fmt, format_args __args) {
return std::__vformat_to(std::move(__out_it), __fmt, __args);
}
# if _LIBCPP_HAS_WIDE_CHARACTERS
template <output_iterator<const wchar_t&> _OutIt>
-_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt
+_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt
vformat_to(_OutIt __out_it, wstring_view __fmt, wformat_args __args) {
return std::__vformat_to(std::move(__out_it), __fmt, __args);
}
# endif
template <output_iterator<const char&> _OutIt, class... _Args>
-_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt
+_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt
format_to(_OutIt __out_it, format_string<_Args...> __fmt, _Args&&... __args) {
return std::vformat_to(std::move(__out_it), __fmt.get(), std::make_format_args(__args...));
}
# if _LIBCPP_HAS_WIDE_CHARACTERS
template <output_iterator<const wchar_t&> _OutIt, class... _Args>
-_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt
+_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt
format_to(_OutIt __out_it, wformat_string<_Args...> __fmt, _Args&&... __args) {
return std::vformat_to(std::move(__out_it), __fmt.get(), std::make_wformat_args(__args...));
}
@@ -492,7 +493,8 @@ template <class _CharT>
// TODO FMT This needs to be a template or std::to_chars(floating-point) availability markup
// fires too eagerly, see http://llvm.org/PR61563.
template <class = void>
-[[nodiscard]] _LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI string vformat(string_view __fmt, format_args __args) {
+[[nodiscard]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI string
+vformat(string_view __fmt, format_args __args) {
auto __result = __format::__try_constant_folding(__fmt, __args);
if (__result.has_value())
return *std::move(__result);
@@ -505,7 +507,7 @@ template <class = void>
// TODO FMT This needs to be a template or std::to_chars(floating-point) availability markup
// fires too eagerly, see http://llvm.org/PR61563.
template <class = void>
-[[nodiscard]] _LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI wstring
+[[nodiscard]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI wstring
vformat(wstring_view __fmt, wformat_args __args) {
auto __result = __format::__try_constant_folding(__fmt, __args);
if (__result.has_value())
@@ -517,14 +519,14 @@ vformat(wstring_view __fmt, wformat_args __args) {
# endif
template <class... _Args>
-[[nodiscard]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI string
+[[nodiscard]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI string
format(format_string<_Args...> __fmt, _Args&&... __args) {
return std::vformat(__fmt.get(), std::make_format_args(__args...));
}
# if _LIBCPP_HAS_WIDE_CHARACTERS
template <class... _Args>
-[[nodiscard]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI wstring
+[[nodiscard]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI wstring
format(wformat_string<_Args...> __fmt, _Args&&... __args) {
return std::vformat(__fmt.get(), std::make_wformat_args(__args...));
}
@@ -543,14 +545,14 @@ __vformat_to_n(_OutIt __out_it,
}
template <output_iterator<const char&> _OutIt, class... _Args>
-_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt>
+_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt>
format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, format_string<_Args...> __fmt, _Args&&... __args) {
return std::__vformat_to_n<format_context>(std::move(__out_it), __n, __fmt.get(), std::make_format_args(__args...));
}
# if _LIBCPP_HAS_WIDE_CHARACTERS
template <output_iterator<const wchar_t&> _OutIt, class... _Args>
-_LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt>
+_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt>
format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, wformat_string<_Args...> __fmt, _Args&&... __args) {
return std::__vformat_to_n<wformat_context>(std::move(__out_it), __n, __fmt.get(), std::make_wformat_args(__args...));
}
@@ -565,14 +567,14 @@ _LIBCPP_HIDE_FROM_ABI size_t __vformatted_size(basic_string_view<_CharT> __fmt,
}
template <class... _Args>
-[[nodiscard]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI size_t
+[[nodiscard]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI size_t
formatted_size(format_string<_Args...> __fmt, _Args&&... __args) {
return std::__vformatted_size(__fmt.get(), basic_format_args{std::make_format_args(__args...)});
}
# if _LIBCPP_HAS_WIDE_CHARACTERS
template <class... _Args>
-[[nodiscard]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI size_t
+[[nodiscard]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI size_t
formatted_size(wformat_string<_Args...> __fmt, _Args&&... __args) {
return std::__vformatted_size(__fmt.get(), basic_format_args{std::make_wformat_args(__args...)});
}
diff --git a/libcxx/include/format b/libcxx/include/format
index d89c8d8b0ae89f..5f83ef33e56426 100644
--- a/libcxx/include/format
+++ b/libcxx/include/format
@@ -47,7 +47,7 @@ namespace std {
basic_string_view<charT> str; // exposition-only
public:
- dynamic-format-string(basic_string_view<charT> s) noexcept : str(s) {}
+ dynamic-format-string(basic_string_view<charT> s) noexcept : str(s) {} // constexpr since C++26
dynamic-format-string(const dynamic-format-string&) = delete;
dynamic-format-string& operator=(const dynamic-format-string&) = delete;
@@ -62,32 +62,32 @@ namespace std {
// [format.functions], formatting functions
template<class... Args>
- string format(format-string<Args...> fmt, Args&&... args);
+ string format(format-string<Args...> fmt, Args&&... args); // constexpr since C++26
template<class... Args>
- wstring format(wformat-string<Args...> fmt, Args&&... args);
+ wstring format(wformat-string<Args...> fmt, Args&&... args); // constexpr since C++26
template<class... Args>
string format(const locale& loc, format-string<Args...> fmt, Args&&... args);
template<class... Args>
wstring format(const locale& loc, wformat-string<Args...> fmt, Args&&... args);
- string vformat(string_view fmt, format_args args);
- wstring vformat(wstring_view fmt, wformat_args args);
+ string vformat(string_view fmt, format_args args); // constexpr since C++26
+ wstring vformat(wstring_view fmt, wformat_args args); // constexpr since C++26
string vformat(const locale& loc, string_view fmt, format_args args);
wstring vformat(const locale& loc, wstring_view fmt, wformat_args args);
template<class Out, class... Args>
- Out format_to(Out out, format-string<Args...> fmt, Args&&... args);
+ Out format_to(Out out, format-string<Args...> fmt, Args&&... args); // constexpr since C++26
template<class Out, class... Args>
- Out format_to(Out out, wformat-string<Args...> fmt, Args&&... args);
+ Out format_to(Out out, wformat-string<Args...> fmt, Args&&... args); // constexpr since C++26
template<class Out, class... Args>
Out format_to(Out out, const locale& loc, format-string<Args...> fmt, Args&&... args);
template<class Out, class... Args>
Out format_to(Out out, const locale& loc, wformat-string<Args...> fmt, Args&&... args);
template<class Out>
- Out vformat_to(Out out, string_view fmt, format_args args);
+ Out vformat_to(Out out, string_view fmt, format_args args); // constexpr since C++26
template<class Out>
- Out vformat_to(Out out, wstring_view fmt, wformat_args args);
+ Out vformat_to(Out out, wstring_view fmt, wformat_args args); // constexpr since C++26
template<class Out>
Out vformat_to(Out out, const locale& loc, string_view fmt,
format_args char> args);
@@ -101,10 +101,10 @@ namespace std {
};
template<class Out, class... Args>
format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
- format-string<Args...> fmt, Args&&... args);
+ format-string<Args...> fmt, Args&&... args); // constexpr since C++26
template<class Out, class... Args>
format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
- wformat-string<Args...> fmt, Args&&... args);
+ wformat-string<Args...> fmt, Args&&... args); // constexpr since C++26
template<class Out, class... Args>
format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
const locale& loc, format-string<Args...> fmt,
@@ -115,9 +115,9 @@ namespace std {
Args&&... args);
template<class... Args>
- size_t formatted_size(format-string<Args...> fmt, Args&&... args);
+ size_t formatted_size(format-string<Args...> fmt, Args&&... args); // constexpr since C++26
template<class... Args>
- size_t formatted_size(wformat-string<Args...> fmt, Args&&... args);
+ size_t formatted_size(wformat-string<Args...> fmt, Args&&... args); // constexpr since C++26
template<class... Args>
size_t formatted_size(const locale& loc, format-string<Args...> fmt, Args&&... args);
template<class... Args>
@@ -179,10 +179,10 @@ namespace std {
template<class Context, class... Args> struct format-arg-store; // exposition only
template<class Context = format_context, class... Args>
- format-arg-store<Context, Args...>
+ constexpr format-arg-store<Context, Args...>
make_format_args(Args&... args);
template<class... Args>
- format-arg-store<wformat_context, Args...>
+ constexpr format-arg-store<wformat_context, Args...>
make_wformat_args(Args&... args);
// [format.error], class format_error
>From b73562f360f90d67a160dc3b879c4e57598cfe24 Mon Sep 17 00:00:00 2001
From: Lucas Mellone <github.snugness349 at passinbox.com>
Date: Thu, 8 Oct 2026 20:25:22 +0200
Subject: [PATCH 2/7] add: constexpr to make_(w)format_args
---
libcxx/include/__format/format_functions.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libcxx/include/__format/format_functions.h b/libcxx/include/__format/format_functions.h
index 2cdcf79b05bf22..5bf0c86782fb59 100644
--- a/libcxx/include/__format/format_functions.h
+++ b/libcxx/include/__format/format_functions.h
@@ -69,13 +69,13 @@ using wformat_args = basic_format_args<wformat_context>;
# endif
template <class _Context = format_context, class... _Args>
-[[nodiscard]] _LIBCPP_HIDE_FROM_ABI __format_arg_store<_Context, _Args...> make_format_args(_Args&... __args) {
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __format_arg_store<_Context, _Args...> make_format_args(_Args&... __args) {
return std::__format_arg_store<_Context, _Args...>(__args...);
}
# if _LIBCPP_HAS_WIDE_CHARACTERS
template <class... _Args>
-[[nodiscard]] _LIBCPP_HIDE_FROM_ABI __format_arg_store<wformat_context, _Args...> make_wformat_args(_Args&... __args) {
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __format_arg_store<wformat_context, _Args...> make_wformat_args(_Args&... __args) {
return std::__format_arg_store<wformat_context, _Args...>(__args...);
}
# endif
>From da9c1424f45c5225791f29e9015a69f81e3f7174 Mon Sep 17 00:00:00 2001
From: Lucas Mellone <github.snugness349 at passinbox.com>
Date: Thu, 8 Oct 2026 20:30:51 +0200
Subject: [PATCH 3/7] add: constexpr to basic_format_string
---
libcxx/include/__format/format_functions.h | 2 +-
libcxx/include/format | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/libcxx/include/__format/format_functions.h b/libcxx/include/__format/format_functions.h
index 5bf0c86782fb59..7cc3831ec98aad 100644
--- a/libcxx/include/__format/format_functions.h
+++ b/libcxx/include/__format/format_functions.h
@@ -376,7 +376,7 @@ struct basic_format_string {
_LIBCPP_HIDE_FROM_ABI constexpr basic_string_view<_CharT> get() const noexcept { return __str_; }
# if _LIBCPP_STD_VER >= 26
- _LIBCPP_HIDE_FROM_ABI basic_format_string(__dynamic_format_string<_CharT> __s) noexcept : __str_(__s.__str_) {}
+ _LIBCPP_HIDE_FROM_ABI constexpr basic_format_string(__dynamic_format_string<_CharT> __s) noexcept : __str_(__s.__str_) {}
# endif
private:
diff --git a/libcxx/include/format b/libcxx/include/format
index 5f83ef33e56426..7de6a8cf5fd61b 100644
--- a/libcxx/include/format
+++ b/libcxx/include/format
@@ -31,7 +31,7 @@ namespace std {
public:
template<class T> consteval basic_format_string(const T& s);
- basic_format_string(dynamic-format-string<charT> s) noexcept : str(s.str) {} // since C++26
+ constexpr basic_format_string(dynamic-format-string<charT> s) noexcept : str(s.str) {} // constexpr since C++26
constexpr basic_string_view<charT> get() const noexcept { return str; }
};
>From e622b26068538a5ab51fcd1d7de36c3419e70c38 Mon Sep 17 00:00:00 2001
From: Lucas Mellone <github.snugness349 at passinbox.com>
Date: Thu, 8 Oct 2026 20:40:33 +0200
Subject: [PATCH 4/7] fix: clang-format
---
libcxx/include/__format/format_functions.h | 48 +++++++++++++---------
1 file changed, 28 insertions(+), 20 deletions(-)
diff --git a/libcxx/include/__format/format_functions.h b/libcxx/include/__format/format_functions.h
index 7cc3831ec98aad..42301a1d9436f0 100644
--- a/libcxx/include/__format/format_functions.h
+++ b/libcxx/include/__format/format_functions.h
@@ -69,13 +69,15 @@ using wformat_args = basic_format_args<wformat_context>;
# endif
template <class _Context = format_context, class... _Args>
-[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __format_arg_store<_Context, _Args...> make_format_args(_Args&... __args) {
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __format_arg_store<_Context, _Args...>
+make_format_args(_Args&... __args) {
return std::__format_arg_store<_Context, _Args...>(__args...);
}
# if _LIBCPP_HAS_WIDE_CHARACTERS
template <class... _Args>
-[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __format_arg_store<wformat_context, _Args...> make_wformat_args(_Args&... __args) {
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __format_arg_store<wformat_context, _Args...>
+make_wformat_args(_Args&... __args) {
return std::__format_arg_store<wformat_context, _Args...>(__args...);
}
# endif
@@ -351,15 +353,20 @@ struct __dynamic_format_string {
friend struct basic_format_string;
public:
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __dynamic_format_string(basic_string_view<_CharT> __s) noexcept : __str_(__s) {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __dynamic_format_string(basic_string_view<_CharT> __s) noexcept
+ : __str_(__s) {}
__dynamic_format_string(const __dynamic_format_string&) = delete;
__dynamic_format_string& operator=(const __dynamic_format_string&) = delete;
};
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 inline __dynamic_format_string<char> dynamic_format(string_view __fmt) noexcept { return __fmt; }
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 inline __dynamic_format_string<char>
+dynamic_format(string_view __fmt) noexcept {
+ return __fmt;
+}
# if _LIBCPP_HAS_WIDE_CHARACTERS
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 inline __dynamic_format_string<wchar_t> dynamic_format(wstring_view __fmt) noexcept {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 inline __dynamic_format_string<wchar_t>
+dynamic_format(wstring_view __fmt) noexcept {
return __fmt;
}
# endif
@@ -376,7 +383,8 @@ struct basic_format_string {
_LIBCPP_HIDE_FROM_ABI constexpr basic_string_view<_CharT> get() const noexcept { return __str_; }
# if _LIBCPP_STD_VER >= 26
- _LIBCPP_HIDE_FROM_ABI constexpr basic_format_string(__dynamic_format_string<_CharT> __s) noexcept : __str_(__s.__str_) {}
+ _LIBCPP_HIDE_FROM_ABI constexpr basic_format_string(__dynamic_format_string<_CharT> __s) noexcept
+ : __str_(__s.__str_) {}
# endif
private:
@@ -425,29 +433,29 @@ _LIBCPP_HIDE_FROM_ABI _OutIt __vformat_to(_OutIt __out_it,
// https://reviews.llvm.org/D110499#inline-1180704
// TODO FMT Evaluate whether we want to file a Clang bug report regarding this.
template <output_iterator<const char&> _OutIt>
-_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt
+_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt
vformat_to(_OutIt __out_it, string_view __fmt, format_args __args) {
return std::__vformat_to(std::move(__out_it), __fmt, __args);
}
# if _LIBCPP_HAS_WIDE_CHARACTERS
template <output_iterator<const wchar_t&> _OutIt>
-_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt
-vformat_to(_OutIt __out_it, wstring_view __fmt, wformat_args __args) {
+_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE
+_LIBCPP_HIDE_FROM_ABI _OutIt vformat_to(_OutIt __out_it, wstring_view __fmt, wformat_args __args) {
return std::__vformat_to(std::move(__out_it), __fmt, __args);
}
# endif
template <output_iterator<const char&> _OutIt, class... _Args>
-_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt
-format_to(_OutIt __out_it, format_string<_Args...> __fmt, _Args&&... __args) {
+_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE
+_LIBCPP_HIDE_FROM_ABI _OutIt format_to(_OutIt __out_it, format_string<_Args...> __fmt, _Args&&... __args) {
return std::vformat_to(std::move(__out_it), __fmt.get(), std::make_format_args(__args...));
}
# if _LIBCPP_HAS_WIDE_CHARACTERS
template <output_iterator<const wchar_t&> _OutIt, class... _Args>
-_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt
-format_to(_OutIt __out_it, wformat_string<_Args...> __fmt, _Args&&... __args) {
+_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE
+_LIBCPP_HIDE_FROM_ABI _OutIt format_to(_OutIt __out_it, wformat_string<_Args...> __fmt, _Args&&... __args) {
return std::vformat_to(std::move(__out_it), __fmt.get(), std::make_wformat_args(__args...));
}
# endif
@@ -493,7 +501,7 @@ template <class _CharT>
// TODO FMT This needs to be a template or std::to_chars(floating-point) availability markup
// fires too eagerly, see http://llvm.org/PR61563.
template <class = void>
-[[nodiscard]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI string
+[[nodiscard]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI string
vformat(string_view __fmt, format_args __args) {
auto __result = __format::__try_constant_folding(__fmt, __args);
if (__result.has_value())
@@ -519,15 +527,15 @@ vformat(wstring_view __fmt, wformat_args __args) {
# endif
template <class... _Args>
-[[nodiscard]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI string
-format(format_string<_Args...> __fmt, _Args&&... __args) {
+[[nodiscard]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE
+_LIBCPP_HIDE_FROM_ABI string format(format_string<_Args...> __fmt, _Args&&... __args) {
return std::vformat(__fmt.get(), std::make_format_args(__args...));
}
# if _LIBCPP_HAS_WIDE_CHARACTERS
template <class... _Args>
-[[nodiscard]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI wstring
-format(wformat_string<_Args...> __fmt, _Args&&... __args) {
+[[nodiscard]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE
+_LIBCPP_HIDE_FROM_ABI wstring format(wformat_string<_Args...> __fmt, _Args&&... __args) {
return std::vformat(__fmt.get(), std::make_wformat_args(__args...));
}
# endif
@@ -574,8 +582,8 @@ formatted_size(format_string<_Args...> __fmt, _Args&&... __args) {
# if _LIBCPP_HAS_WIDE_CHARACTERS
template <class... _Args>
-[[nodiscard]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI size_t
-formatted_size(wformat_string<_Args...> __fmt, _Args&&... __args) {
+[[nodiscard]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE
+_LIBCPP_HIDE_FROM_ABI size_t formatted_size(wformat_string<_Args...> __fmt, _Args&&... __args) {
return std::__vformatted_size(__fmt.get(), basic_format_args{std::make_wformat_args(__args...)});
}
# endif
>From 98d695fe360e229462567f2b9e5a372187911aec Mon Sep 17 00:00:00 2001
From: Lucas Mellone <github.snugness349 at passinbox.com>
Date: Thu, 8 Oct 2026 21:51:00 +0200
Subject: [PATCH 5/7] add: constexpr to vformat
---
libcxx/include/__format/format_functions.h | 45 ++++++++++++----------
1 file changed, 25 insertions(+), 20 deletions(-)
diff --git a/libcxx/include/__format/format_functions.h b/libcxx/include/__format/format_functions.h
index 42301a1d9436f0..c883ec206df853 100644
--- a/libcxx/include/__format/format_functions.h
+++ b/libcxx/include/__format/format_functions.h
@@ -415,9 +415,10 @@ using wformat_string = basic_format_string<wchar_t, type_identity_t<_Args>...>;
template <class _OutIt, class _CharT, class _FormatOutIt>
requires(output_iterator<_OutIt, const _CharT&>)
-_LIBCPP_HIDE_FROM_ABI _OutIt __vformat_to(_OutIt __out_it,
- basic_string_view<_CharT> __fmt,
- basic_format_args<basic_format_context<_FormatOutIt, _CharT>> __args) {
+_LIBCPP_HIDE_FROM_ABI constexpr _OutIt
+__vformat_to(_OutIt __out_it,
+ basic_string_view<_CharT> __fmt,
+ basic_format_args<basic_format_context<_FormatOutIt, _CharT>> __args) {
if constexpr (same_as<_OutIt, _FormatOutIt>)
return std::__format::__vformat_to(
basic_format_parse_context{__fmt, __args.__size()}, std::__format_context_create(std::move(__out_it), __args));
@@ -503,9 +504,13 @@ template <class _CharT>
template <class = void>
[[nodiscard]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI string
vformat(string_view __fmt, format_args __args) {
- auto __result = __format::__try_constant_folding(__fmt, __args);
- if (__result.has_value())
- return *std::move(__result);
+ // P3391R2: We don't need constant folding runtime optimizations in the scope of a constant evaluation.
+ // `if !consteval` is only present since C++23.
+ if (!__libcpp_is_constant_evaluated()) {
+ auto __result = __format::__try_constant_folding(__fmt, __args);
+ if (__result.has_value())
+ return *std::move(__result);
+ }
__format::__allocating_buffer<char> __buffer;
std::vformat_to(__buffer.__make_output_iterator(), __fmt, __args);
return string{__buffer.__view()};
@@ -541,7 +546,7 @@ _LIBCPP_HIDE_FROM_ABI wstring format(wformat_string<_Args...> __fmt, _Args&&...
# endif
template <class _Context, class _OutIt, class _CharT>
-_LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt>
+_LIBCPP_HIDE_FROM_ABI constexpr format_to_n_result<_OutIt>
__vformat_to_n(_OutIt __out_it,
iter_difference_t<_OutIt> __n,
basic_string_view<_CharT> __fmt,
@@ -567,7 +572,7 @@ format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, wformat_string<_Args
# endif
template <class _CharT>
-_LIBCPP_HIDE_FROM_ABI size_t __vformatted_size(basic_string_view<_CharT> __fmt, auto __args) {
+_LIBCPP_HIDE_FROM_ABI constexpr size_t __vformatted_size(basic_string_view<_CharT> __fmt, auto __args) {
__format::__formatted_size_buffer<_CharT> __buffer;
std::__format::__vformat_to(basic_format_parse_context{__fmt, __args.__size()},
std::__format_context_create(__buffer.__make_output_iterator(), __args));
@@ -617,22 +622,22 @@ vformat_to(_OutIt __out_it, locale __loc, string_view __fmt, format_args __args)
# if _LIBCPP_HAS_WIDE_CHARACTERS
template <output_iterator<const wchar_t&> _OutIt>
-_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt
-vformat_to(_OutIt __out_it, locale __loc, wstring_view __fmt, wformat_args __args) {
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_HIDE_FROM_ABI _OutIt vformat_to(_OutIt __out_it, locale __loc, wstring_view __fmt, wformat_args __args) {
return std::__vformat_to(std::move(__out_it), std::move(__loc), __fmt, __args);
}
# endif
template <output_iterator<const char&> _OutIt, class... _Args>
-_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt
-format_to(_OutIt __out_it, locale __loc, format_string<_Args...> __fmt, _Args&&... __args) {
+_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI
+_OutIt format_to(_OutIt __out_it, locale __loc, format_string<_Args...> __fmt, _Args&&... __args) {
return std::vformat_to(std::move(__out_it), std::move(__loc), __fmt.get(), std::make_format_args(__args...));
}
# if _LIBCPP_HAS_WIDE_CHARACTERS
template <output_iterator<const wchar_t&> _OutIt, class... _Args>
-_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt
-format_to(_OutIt __out_it, locale __loc, wformat_string<_Args...> __fmt, _Args&&... __args) {
+_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI
+_OutIt format_to(_OutIt __out_it, locale __loc, wformat_string<_Args...> __fmt, _Args&&... __args) {
return std::vformat_to(std::move(__out_it), std::move(__loc), __fmt.get(), std::make_wformat_args(__args...));
}
# endif
@@ -660,15 +665,15 @@ vformat(locale __loc, wstring_view __fmt, wformat_args __args) {
# endif
template <class... _Args>
-[[nodiscard]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI string
-format(locale __loc, format_string<_Args...> __fmt, _Args&&... __args) {
+[[nodiscard]] _LIBCPP_ALWAYS_INLINE
+_LIBCPP_HIDE_FROM_ABI string format(locale __loc, format_string<_Args...> __fmt, _Args&&... __args) {
return std::vformat(std::move(__loc), __fmt.get(), std::make_format_args(__args...));
}
# if _LIBCPP_HAS_WIDE_CHARACTERS
template <class... _Args>
-[[nodiscard]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI wstring
-format(locale __loc, wformat_string<_Args...> __fmt, _Args&&... __args) {
+[[nodiscard]] _LIBCPP_ALWAYS_INLINE
+_LIBCPP_HIDE_FROM_ABI wstring format(locale __loc, wformat_string<_Args...> __fmt, _Args&&... __args) {
return std::vformat(std::move(__loc), __fmt.get(), std::make_wformat_args(__args...));
}
# endif
@@ -720,8 +725,8 @@ formatted_size(locale __loc, format_string<_Args...> __fmt, _Args&&... __args) {
# if _LIBCPP_HAS_WIDE_CHARACTERS
template <class... _Args>
-[[nodiscard]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI size_t
-formatted_size(locale __loc, wformat_string<_Args...> __fmt, _Args&&... __args) {
+[[nodiscard]] _LIBCPP_ALWAYS_INLINE
+_LIBCPP_HIDE_FROM_ABI size_t formatted_size(locale __loc, wformat_string<_Args...> __fmt, _Args&&... __args) {
return std::__vformatted_size(std::move(__loc), __fmt.get(), basic_format_args{std::make_wformat_args(__args...)});
}
# endif
>From 9681d225748e47e412d10102949f8c4010b83696 Mon Sep 17 00:00:00 2001
From: Lucas Mellone <github.snugness349 at passinbox.com>
Date: Thu, 8 Oct 2026 21:52:07 +0200
Subject: [PATCH 6/7] update comment
---
libcxx/include/__format/format_functions.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcxx/include/__format/format_functions.h b/libcxx/include/__format/format_functions.h
index c883ec206df853..da7a46c458440e 100644
--- a/libcxx/include/__format/format_functions.h
+++ b/libcxx/include/__format/format_functions.h
@@ -505,7 +505,7 @@ template <class = void>
[[nodiscard]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI string
vformat(string_view __fmt, format_args __args) {
// P3391R2: We don't need constant folding runtime optimizations in the scope of a constant evaluation.
- // `if !consteval` is only present since C++23.
+ // `if !consteval` is only present since C++23, so we use !__libcpp_is_constant_evaluated().
if (!__libcpp_is_constant_evaluated()) {
auto __result = __format::__try_constant_folding(__fmt, __args);
if (__result.has_value())
>From f9b79f9b8c74b92c4cec38c7017117b7a9858341 Mon Sep 17 00:00:00 2001
From: Lucas Mellone <github.snugness349 at passinbox.com>
Date: Thu, 8 Oct 2026 21:54:50 +0200
Subject: [PATCH 7/7] clang-format: remove trailing space
---
libcxx/include/__format/format_functions.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcxx/include/__format/format_functions.h b/libcxx/include/__format/format_functions.h
index da7a46c458440e..132d7121c2cd03 100644
--- a/libcxx/include/__format/format_functions.h
+++ b/libcxx/include/__format/format_functions.h
@@ -505,7 +505,7 @@ template <class = void>
[[nodiscard]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI string
vformat(string_view __fmt, format_args __args) {
// P3391R2: We don't need constant folding runtime optimizations in the scope of a constant evaluation.
- // `if !consteval` is only present since C++23, so we use !__libcpp_is_constant_evaluated().
+ // `if !consteval` is only present since C++23, so we use !__libcpp_is_constant_evaluated().
if (!__libcpp_is_constant_evaluated()) {
auto __result = __format::__try_constant_folding(__fmt, __args);
if (__result.has_value())
More information about the libcxx-commits
mailing list