Skip to content

Ambiguous formatter<std::optional<T>> between fmt/std.h and fmt/ranges.h on C++26 (P3168R2) #4760

Description

@indiosmo

With C++26 std::optional range support, including both <fmt/std.h> and <fmt/ranges.h> fails with ambiguous template instantiation.

Environment

  • fmt 12.1.0 (also reproduces on current master at the time of writing)
  • GCC 16.1.0, libstdc++ (ships P3168R2)
  • -std=c++26
  • Linux x86_64

Reproduction

#include <optional>
#include <string>

#include <fmt/format.h>
// commenting either works.
// ranges prints: ["hi"] []
// std prints: optional("hi") none
#include <fmt/ranges.h>
#include <fmt/std.h>

int main() {
  std::optional<std::string> some{"hi"};
  std::optional<std::string> none{};
  fmt::print("{} {}\n", some, none);
}

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