fmt icon indicating copy to clipboard operation
fmt copied to clipboard

Add consteval format string checks for wide strings

Open alabuzhev opened this issue 3 years ago • 2 comments

char-strings are properly rejected, but the same wchar_t-strings are happily compiled.

Example:

#include <string>
#include <string_view>

#include <fmt/core.h>
#include <fmt/xchar.h>

using namespace std::literals;

int main()
{
    fmt::format(L"{:d}", L"I am not a number");
    fmt::format(L"{:d}"s, L"I am not a number");
    fmt::format(L"{:d}"sv, L"I am not a number");

    fmt::format("{:d}", "I am not a number");
    fmt::format("{:d}"s, "I am not a number");
    fmt::format("{:d}"sv, "I am not a number");
}

Godbolt: https://godbolt.org/z/jKr43Tqfs

alabuzhev avatar Jun 26 '21 15:06 alabuzhev

Yeah, compile-time checks are currently enabled for the char overloads only.

vitaut avatar Jun 26 '21 15:06 vitaut

We also need to do this for function taking text styles and potentially named arguments.

vitaut avatar Sep 09 '21 17:09 vitaut

This has been implemented in {fmt} v9.

vitaut avatar Sep 13 '22 21:09 vitaut