http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60194
Bug ID: 60194
Summary: -Wformat should also warn when using %d (instead of
%u) for unsigned arguments
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: burnus at gcc dot gnu.org
cppcheck has the following warning:
(warning) %d in format string (no. 1) requires 'int' but the argument type is
'unsigned int'
I think it would be useful to have the same warning with -Wformat. [One can
argue whether the warning should be always printed with -Wformat[=1] or only
with -Wformat=2 (+ -Wformat-unsigned).]
And of course also the other way round, e.g. using "%lu" or "%lz" with an
argument which is (signed) "long".
Example:
#include <stdio.h>
#include <limits.h>
void foo(unsigned i) {
printf("%d\n", i);
}
int main() {
foo(UINT_MAX);
return 0;
}