Skip to content

FMT_COMPILE fails to format std::array #4949

Description

@james-panayis

On main (e4751cc), 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

#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 61e3b92.

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.

Activity

  1. HarshXAI commented on Sep 29, 2026

    @HarshXAI

    I can take this.

    FMT_COMPILE failing on std::array looks like a missing formatter / compile-time path for contiguous fixed-size ranges. I will reproduce against current main, check how std::span / other ranges are handled in the compile-time formatter, and add a failing test then the fix so both runtime and FMT_COMPILE format std::array the same way.

    Will open a PR with a focused test case once I have the repro locked down.

  2. mayankjaiswal12 commented on Oct 5, 2026

    @mayankjaiswal12

    I opened #4974 with a fix and the reproducer from this issue as a test in compile-test.cc. It keeps the outer context's arguments, so dynamic element specs like {:*>20:{}} also work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions