This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: C++11 variadic function and format attribute
On 16 April 2012 08:11, Diego Ongaro wrote:
> Hi all,
Questions about using GCC should go to the gcc-help@gcc.gnu.org list,
not this one.
> I was working on some C++11 template hacks to be able to pass C++ objects to a
> function wrapping printf. What I want to do looks like this, where convert
> might do fancy things like create string representations of objects:
>
> template<typename... Args>
> void Printf(const char* format, Args&&... args)
> {
> ? ? printf(format, convert(std::forward<Args>(args))...);
> }
>
> However, it seems that this is incompatible with the
> __attribute__((format(printf, 1, 2))) applied to printf.
>
> When trying to call this function as
> ?Printf("%d\n", 3);
> I get the following errors:
> ?In function 'void Printf(const char*, Args&& ...) [with Args = int]':
> ? instantiated from here
> ?warning: format not a string literal, argument types not checked
>
> Unfortunately, the compiler believes my format string is not a string literal,
> but it is!
No it isn't, it's a const char*