[libcxx-commits] [libcxx] WIP [libc++][format] Partial P3391R2: `constexpr` `std::format` (PR #230239)
Lucas Mellone via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Oct 16 17:46:36 PDT 2026
================
@@ -24,9 +24,12 @@ struct X : std::variant<X*> {
constexpr const std::variant<X*>& decay() const noexcept { return *this; }
};
+// P3391R2: the argument to storage calls need to be constexpr and they are
+// instantiated eagerly, so a deduced return type makes __formattable_with<X>
+// depend on itself.
template <>
struct std::formatter<X, char> : std::formatter<std::string, char> {
- static constexpr auto format(const X& x, auto& ctx) {
+ static constexpr auto format(const X& x, auto& ctx) -> decltype(ctx.out()) {
----------------
lknknm wrote:
So, after re-checking I think `bug_81590.compile.pass.cpp` will always fail as is with this patch and we might have 2 options. Without these changes we will get:
```
format_arg_store.h:162: error: satisfaction of constraint '!__formattable_with<_Tp, _Context>' depends on itself
```
Everything else passes as far as I could run the entire `format` test suite. C++ ver < C++23 passes in everything.
So, `formatter<X>::format` has a deduced return type and calls `format_to` on `X`. This paper requires that all of the flow for `format_to` should be constexpr so:
```cpp
constexpr format_to → constexpr make_format_args → constexpr __format_arg_store → constexpr __create_format_arg
```
IIUC Clang instantiates them right away so as a result, `__determine_arg_t` checks `__formattable_with<X>` while `format`'s return type is still being deduced.
Removing `constexpr` from any one of those functions OR if we just change the test `format` with `-> decltype(ctx.out())`, makes it compile again. For sure we need all the `constexpr`, but I'm not sure whether the latter is what we want.
So I think there are 2 alternatives: changing the test as I've done here or changing `__determine_arg_t` somehow? How do you think we should proceed?
cc @Zingam , @frederick-vs-ja
also @mordante since you fixed the original issue in #85548.
https://github.com/llvm/llvm-project/pull/230239
More information about the libcxx-commits
mailing list