[Bug c/57137] spurious "format string is not literal" when the format string is marked with __attribute__((format))

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Apr 22 23:14:00 GMT 2016


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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2016-04-22
                 CC|                            |msebor at gcc dot gnu.org
     Ever confirmed|0                           |1
      Known to fail|                            |4.9.3, 5.3.0, 6.0

--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed.  In addition, as the example below illustrates, the warning in this
case is issued for the call where it could be avoided (in function g) and not
for the call that should be diagnosed (in function h).

$ cat v.c && gcc -S -Wformat -Wformat-nonliteral v.c
void f (const char*, ...) __attribute__ ((format (printf, 1, 2)));

void g (const char*) __attribute__ ((format (printf, 1, 0)));
void g (const char *fmt)
{
  f (fmt, "xxx");
}

void h (const char *fmt)
{
  g (fmt);
}
v.c: In function ‘g’:
v.c:6:3: warning: format not a string literal, argument types not checked
[-Wformat-nonliteral]
   f (fmt, "xxx");
   ^


More information about the Gcc-bugs mailing list