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.

No activity

Activity on this issue will appear here.

Activity

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