https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119891
Bug ID: 119891
Summary: Incorrect suggestion for sizeof and printf
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: nightstrike at gmail dot com
Target Milestone: ---
void f() {
int x;
__builtin_printf("%d\n", sizeof(x));
}
$ gcc -c a.c -Wformat
a.c: In function 'f':
a.c:3:28: warning: format '%d' expects argument of type 'int', but argument 2
has type 'long unsigned int' [-Wformat=]
3 | __builtin_printf("%d\n", sizeof(x));
| ~^ ~~~~~~~~~
| | |
| int long unsigned int
| %ld
I think this should be recommending %zu, not %ld. Even if it didn't recognize
the sizeof operator, it should at least have said %lu.