https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95130
--- Comment #21 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jonathan Yong <jy...@gcc.gnu.org>: https://gcc.gnu.org/g:966f3c134bb4802ac7ba0517de4e8e3f6384cfa3 commit r14-3334-g966f3c134bb4802ac7ba0517de4e8e3f6384cfa3 Author: Tomas Kalibera <tomas.kalib...@gmail.com> Date: Sun Aug 20 02:16:16 2023 +0000 Fix format attribute for printf Since a long time (GCC 4.4?) GCC does support annotating functions with either the format attribute "gnu_printf" or "ms_printf" to distinguish between different format string interpretations. However, it seems like the attribute is ignored for the "printf" symbol; regardless what the function declaration says, GCC treats it as "ms_printf". This has become an issue now that mingw-w64 supports using the UCRT instead of msvcrt.dll, and in this case the stdio functions are declared with the gnu_printf attribute, and inttypes.h uses the same format specifiers as in GNU mode. A reproducible example of the problem: $ cat format.c __attribute__((__format__ (gnu_printf, 1, 2))) int printf (const char *__format, ...); __attribute__((__format__ (gnu_printf, 1, 2))) int othername (const char *__format, ...); void function(void) { long long unsigned x = 42; othername("%llu\n", x); printf("%llu\n", x); } $ x86_64-w64-mingw32-gcc -c -Wformat format.c format.c: In function 'function': format.c:7:15: warning: unknown conversion type character 'l' in format [-Wformat=] 7 | printf("%llu\n", x); | ^ format.c:7:12: warning: too many arguments for format [-Wformat-extra-args] 7 | printf("%llu\n", x); | ^~~~~~~~ Note how both functions, printf and othername, are declare with identical gnu_printf format attributes - GCC does take this into account for "othername" and doesn't produce a warning, but GCC seems to disregard the attribute in the printf declaration and behave as if it was declared as ms_printf. If the printf function declaration is changed into a static inline function, the actual attribute used is honored though. gcc/c-family/ChangeLog: PR c/95130 * c-format.cc: skip default format for printf symbol if explicitly declared by prototype. Signed-off-by: Tomas Kalibera <tomas.kalib...@gmail.com> Signed-off-by: Jonathan Yong <10wa...@gmail.com>