c/1017: -Wmissing-format-attribute gives too many warnings

Joseph S. Myers jsm28@cam.ac.uk
Fri Dec 8 11:07:00 GMT 2000


On Fri, 8 Dec 2000 aj@suse.de wrote:

> Compile this small program with -Wmissing-format-attribute -Wformat:
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> extern void dbg_log (const char *str, ...)
>      __attribute__ ((__format__ (__printf__, 1, 0)));
>
> int
> test (void)
> {
>   dbg_log ("%s:", "Test");
>
>   return 0;
> }
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is as documented - the attribute of dbg_log suggests that it is
vprintf-like - but since the function test plainly can't have a format
attribute since it lacks of suitable parameter, I'll add a check that the
possible candidate for a format attribute has at least one parameter to
which the attribute could be attached.

(If this example came from real code, why can't dbg_log have a non-zero
first_arg_num specified, and is this something that could reasonably be
addressed as part of extensible format checking?)

-- 
Joseph S. Myers
jsm28@cam.ac.uk



More information about the Gcc-bugs mailing list