[Bug c++/77958] New: printf format checking -vs- variadic template functions

tromey at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Oct 12 17:51:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77958

            Bug ID: 77958
           Summary: printf format checking -vs- variadic template
                    functions
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tromey at gcc dot gnu.org
  Target Milestone: ---

Consider this test case, derived from code I found in firefox:

#include <stdio.h>
#include <stdarg.h>

template<typename... Args>
static void
// __attribute__ ((format (printf, 1, 2)))
whatever(const char *fmt, Args&&... args)
{
  printf(fmt, args...);
}

void qq()
{
  whatever("hi %d", "bob");
}


If I compile this with -Wformat, I don't get any warnings.

However, if I uncomment the __attribute__, I get:

pokyo. g++ -Wall -c -Wformat q.cc
q.cc: In substitution of ‘template<class ... Args> void whatever(const char*,
Args&& ...) [with Args = {const char (&)[4]}]’:
q.cc:14:26:   required from here
q.cc:7:1: error: args to be formatted is not ‘...’
 whatever(const char *fmt, Args&&... args)
 ^~~~~~~~


I think the attribute approach ought to work.


More information about the Gcc-bugs mailing list