Question

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");
Was it helpful?

Solution

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.

https://svn.boost.org/trac/boost/ticket/6815

OTHER TIPS

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}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top