-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed
Description
When formatting a variant, fmt 12.0.0 chokes if any of the alternatives relies on format_as to be formattable.
The documentation says:
A std::variant is only formattable if every variant alternative is formattable, and requires the __cpp_lib_variant library feature.
Which does not seem to align with the behavior.
Godbolt link: https://godbolt.org/z/vrjEPsbvr
Code:
#include <fmt/format.h>
#include <fmt/std.h>
#include <iostream>
struct foo {
float bar;
friend float format_as(const foo& f) { return f.bar; }
};
int main() {
foo simple_foo{};
std::variant<foo> variant_foo{};
std::variant<float> variant_float{};
std::cout << fmt::format("{}", simple_foo); // ok
std::cout << fmt::format("{}", variant_float); // ok
std::cout << fmt::format("{}", variant_foo); // broken
}
Error log (from Godbolt): https://pastebin.com/LXiBz4mX
Metadata
Metadata
Assignees
Labels
No labels