Looks like it is not supported A ticket has been created on boost as well to track it. You may want to pick up trunk version if you really need it.
Compile-time checking of Boost.Format
-
29-06-2022 - |
Вопрос
Both Clang and GCC can check printf-style functions for mismatches between their format strings and their arguments. For example, they'll complain about statements like this:
printf("Hello, %s!\n");
Does anything similar exist for Boost.Format? In other words, are there any compiler switches, static analysis tools, etc. that can warn about code like
std::string s1 = str(boost::format("Hello, %s!"));
or
std::string s2 = str(boost::format("Hello, %s!") % "John" % "Doe");
Решение
Другие советы
It is not possible in Boost Format but the {fmt} formatting library which is similar in spirit but uses Python-like format string syntax provides compile-time checks.
For example:
#include <fmt/format.h> std::string s = format(FMT_STRING("{2}"), 42);
gives a compile-time error because the format string refers to argument 2 which was not provided.
Disclaimer: I'm the author of {fmt}
Не связан с StackOverflow