Example program:
#include <fmt/format.h>
#include <fmt/compile.h>
#include <algorithm>
#include <array>
#include <string_view>
struct UDT {};
template<>
struct fmt::formatter<UDT> : formatter<std::string_view> {
constexpr auto format(
UDT const&,
fmt::format_context& ctx
) const noexcept {
return fmt::formatter<std::string_view>::format("hello", ctx);
}
};
#include <fmt/format.h>
int main() {
std::array<char, 256> buf = {};
// fmt::format_to(buf.data(), "{}", UDT{}); // compiles
fmt::format_to(buf.data(), FMT_COMPILE("{}"), UDT{}); // fails to compile
fmt::println("{}", std::string_view(buf.begin(), std::find(buf.begin(), buf.end(), '\0')));
}
Locally I've tested with fmt version 12.1 and
Homebrew clang version 22.1.0
Target: arm64-apple-darwin24.5.0
On Compiler Explorer I've tested x86-64 clang 22.1.0 and gcc 15.2 with fmt version 12.0 and trunk. They all fail.
Example program:
Locally I've tested with fmt version 12.1 and
On Compiler Explorer I've tested x86-64 clang 22.1.0 and gcc 15.2 with fmt version 12.0 and trunk. They all fail.