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

            Bug ID: 77328
           Summary: incorrect caret location in -Wformat calling printf
                    via a macro
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

With recent improvements to token location range information, GCC has started
to underline entire format directives in -Wformat diagnostics issued for calls
to functions like printf.  However, when the function invocation happens as a
result of even simple macro expansion, the caret is still in the wrong place:

$ cat t.c && /build/gcc-trunk/gcc/xgcc -B /build/gcc-trunk/gcc -S -Wformat t.c
void f (void)
{
  char d [8];

#define P(d, f, a, b) __builtin_sprintf (d, f, a, b)

  __builtin_sprintf (d, "%i %i", 1, 2.0);

  P (d, "%i %i", 1, 2.0);
}
t.c: In function ‘f’:
t.c:7:30: warning: format ‘%i’ expects argument of type ‘int’, but argument 4
has type ‘double’ [-Wformat=]
   __builtin_sprintf (d, "%i %i", 1, 2.0);
                             ~^
                             %f
t.c:9:9: warning: format ‘%i’ expects argument of type ‘int’, but argument 4
has type ‘double’ [-Wformat=]
   P (d, "%i %i", 1, 2.0);
         ^
t.c:5:45: note: in definition of macro ‘P’
 #define P(d, f, a, b) __builtin_sprintf (d, f, a, b)
                                             ^

Reply via email to