Skip to content

Compilation error with upgrade of FMT library to 12.2 #396

Description

@oleksandr-pavlyk

Updating FMT library from 11.2 to 12.2 runs into similar compilation errors.

Representative snippet of the compilation error
/home/coder/nvbench/build/_deps/fmt-src/include/fmt/base.h(487): error: a constexpr function cannot have a parameter of nonliteral type "std::back_insert_iterator<fmt::v12::memory_buffer>" (aka "std::back_insert_iterator<fmt::v12::basic_memory_buffer<char, 500UL, fmt::v12::detail::allocator<char>>>")
      constexpr accessor(OutputIt base) : OutputIt(base) {}
                ^
          detected during:
            instantiation of "auto fmt::v12::detail::get_container(OutputIt)->OutputIt::container_type & [with OutputIt=std::back_insert_iterator<fmt::v12::memory_buffer>]" at line 2094
            instantiation of "auto fmt::v12::detail::get_buffer<T,OutputIt,<unnamed>>(OutputIt)->fmt::v12::detail::buffer<T> & [with T=char, OutputIt=std::back_insert_iterator<fmt::v12::memory_buffer>, <unnamed>=0]" at line 2797
            instantiation of "auto fmt::v12::vformat_to(OutputIt &&, fmt::v12::string_view, fmt::v12::format_args)->fmt::v12::remove_cvref_t<OutputIt> [with OutputIt=std::back_insert_iterator<fmt::v12::memory_buffer> &, <unnamed>=0]" at line 2817
            instantiation of "auto fmt::v12::format_to(OutputIt &&, fmt::v12::format_string<T...>, T &&...)->fmt::v12::remove_cvref_t<OutputIt> [with OutputIt=std::back_insert_iterator<fmt::v12::memory_buffer>, T=<const std::string &>, <unnamed>=0]" at line 129 of /home/coder/nvbench/testing/axes_metadata.cu

1 error detected in the compilation of "/home/coder/nvbench/testing/axes_metadata.cu".

This happens because fmt 12.2 now routes std::back_insert_iterator through an optimized/internal buffer-unwrapping path. That path uses a
constexpr helper involving the output iterator type. Under nvcc, std::back_insert_iterator<fmt::memory_buffer> is rejected because it is not a
literal type.

The correct fix to support both fmt 11.2 and 12.2 is to avoid std::back_inserter for fmt’s own buffer type and use fmt’s appender API instead:

  fmt::format_to(fmt::appender(buffer), "Axis: {}\n", axis->get_name());

For internal code that was formatting into std::vector<char> only to build a string, we can similarly switch the temporary buffer to fmt::memory_buffer and use fmt::appender(buffer).

Metadata

Metadata

Labels

type: cleanupModernization, dead code removal, style fixes, etc.

Type

No type
No fields configured for issues without a type.

Projects

Status
In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions