fmtlib / fmt

A modern formatting library
https://fmt.dev
Other
19.83k stars 2.42k forks source link

Formatting with `std::string` fail to compile with `consteval` #4046

Closed TLCFEM closed 3 days ago

TLCFEM commented 3 days ago

Bad: Trunk with consteval: https://godbolt.org/z/6rKczqfdP

Good: Trunk with no consteval: https://godbolt.org/z/j9zG1jqGa

Good: 10.2.1 with consteval: https://godbolt.org/z/nbG836scW

vitaut commented 3 days ago

This is expected: the format string must be known at compile time. There are multiple ways to fix this, e.g.

auto s = fmt::format(fg(color::green_yellow), "{}", std::string("something"));
TLCFEM commented 3 days ago

This is expected: the format string must be known at compile time. There are multiple ways to fix this, e.g.

auto s = fmt::format(fg(color::green_yellow), "{}", std::string("something"));

Oh, Okay, so I presume what is happening is that it is an attempt to constexpr/consteval as much as possible?

vitaut commented 3 days ago

Yes. See also: https://fmt.dev/latest/api/#compile-time-checks.

TLCFEM commented 3 days ago

hats off