#4949·fmt

FMT_COMPILE fails to format std::array

Author: james-panayisCreated Sep 17, 2026Updated Sep 17, 2026

On main (e4751cc70), this fails to compile with GCC 15.2 and -std=c++20. It compiles and runs correctly with fmt 12.2.0.

Compiler Explorer: https://godbolt.org/z/hxMdoozx8

cpp
#include <array>
#include <fmt/compile.h>
#include <fmt/ranges.h>

int main() {
  std::array<int, 3> values{1, 2, 3};
  auto s = fmt::format(FMT_COMPILE("array={}"), values);
  fmt::print("{}\n", s);
}

Expected output: array=[1, 2, 3]

It works without FMT_COMPILE.

This issue seems to have been introduced in 61e3b923.

A branch in nested_format_specs::write attempts to construct an iterator-specific FormatContext from a basic_appender<char>, which cannot be converted to a std::back_insert_iterator<std::string> as required by the generic_context<std::back_insert_iterator<std::string>, char> constructor. This example never actually tries to construct the FormatContext (as the branch is for padding, and we don't specify a width), but it still needs to be instantiated.