https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110322
Bug ID: 110322
Summary: Be more helpful when a varargs function is called in a
wrong way
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: roland.illig at gmx dot de
Target Milestone: ---
~~~c
#include <stdarg.h>
#include <stdio.h>
static void __attribute__((__format__(__printf__, 1, 2)))
my_printf(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
fprintf(stderr, fmt, ap);
va_end(ap);
}
int
main(int argc, char **argv)
{
my_printf("%d", 4);
my_printf("%.*s\n", 5, "hello, world");
return 0;
}
~~~
In the above program, I am accidentally trying to call fprintf with a va_list,
instead of the correct vfprintf. GCC warns:
sl.c:10:2: error: format not a string literal, argument types not checked
[-Werror=format-nonliteral]
10 | fprintf(stderr, fmt, ap);
| ^~~~~~~
In this situation, where my only mistake was to forget the 'v' from the
function name, GCC should not complain that the format string is not a string
literal, but rather that I'm calling the wrong function.