[Bug c++/77958] printf format checking -vs- variadic template functions
bugzilla@poradnik-webmastera.com
gcc-bugzilla@gcc.gnu.org
Wed Feb 22 23:47:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77958
--- Comment #3 from Daniel Fruzynski <bugzilla@poradnik-webmastera.com> ---
This attribute should also work when some parameters are not variadic ones. One
use case presented in bug 79680 is to have two overloaded logging function: one
printf-like, and another one which accepts constant string only. So something
like this should work too:
template<typename Arg1, typename... Args>
static void
__attribute__ ((format (printf, 1, 2)))
whatever(const char *fmt, Arg1&& arg1, Args&&... args)
{
printf(fmt, arg1, args...);
}
Please also consider case when type of arg1 is specified explicitly, someone
may find it useful too:
template<typename... Args>
static void
__attribute__ ((format (printf, 1, 2)))
whatever(const char *fmt, int arg1, Args&&... args)
{
printf(fmt, arg1, args...);
}
More information about the Gcc-bugs
mailing list