https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91206
Bug ID: 91206 Summary: -Wformat doesn't warn for %hd with char parameter Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: ndesaulniers at google dot com Target Milestone: --- The linux kernel currently disables -Wformat when built with Clang (see scripts/Makefile.extrawarn). When looking into why the warning was disabled, I noticed that Clang and GCC differ slightly in behavior, which leads to a warning spew when building the kernel with Clang. Testing out the specific cases of using different size types with different format flags, I think I found the difference. It seems that both compilers warn for modifiers to %d (%hhd, %hd, %ld, %lld) when passed smaller parameters. Specifically, it seems that GCC does not warn in the case: char x = 0; printf("%hd", x); with -Wformat, but Clang does, and there are a lot of cases in the Linux kernel that print char's via %hd. Specifically, Clang would warn for the above: warning: format specifies type 'short' but the argument has type 'char' [-Wformat] printf("%hd", x); ~~~ ^ %hhd I think GCC should warn in this case as well, and we should clean up the issues in the Linux kernel, but today it's hard to get patches accepted without having to explain this subtly to kernel developers. But if we disagree, I'm happy to collect more feedback for the Clang developers if maybe Clang should not be warning for this case? See also: https://godbolt.org/z/qeuFoh https://github.com/ClangBuiltLinux/linux/issues/378