I'm trying to combine gcc's compile-time checking of printf format strings with c++11's variadic template packs.
I know I can decorate a variadic function with gcc's __attribute__((format(__printf__, ...))
decorator.
I know I can expand a variadic template pack into a variadic function. eg: printf(fmt, pack...);
Is it possible to combine the two?
Working example of what I'm trying to achieve:
#include <iostream>
void check(const char*, ...) __attribute__((format(__printf__, 1, 2)));
void check(const char*, ...)
{
// exists only for the purposes of catching bogus format strings
}
template<typename... Ts>
void check_t(const char fmt[], Ts... ts)
{
// check the format string by expanding ts into the check function
check(fmt, ts...);
}
int main()
{
const char f[] = "foo %s";
check_t(f, 5); // compiles
check(f, 5); // fails to compile
return 0;
}