This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/53391] New: Slightly misleading warning on printf format mismatch
- From: "Keith.S.Thompson at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 18 May 2012 00:01:22 +0000
- Subject: [Bug c/53391] New: Slightly misleading warning on printf format mismatch
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53391
Bug #: 53391
Summary: Slightly misleading warning on printf format mismatch
Classification: Unclassified
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: Keith.S.Thompson@gmail.com
Given the following program (c.c):
#include <stdio.h>
int main(void) {
typedef long my_long;
my_long x = 42;
printf("x = %d\n", (long)x);
return 0;
}
"gcc -c c.c" produces the following warning:
c.c: In function âmainâ:
c.c:5:5: warning: format â%dâ expects argument of type âintâ, but argument 2
has type âmy_longâ [-Wformat]
The argument is actually of type long, not my_long; the warning should say
"..., but argument 2 has type âlongâ".
Now because of the way typedefs work, long and my_long are really different
names for the same type. gcc is obviously trying to be clever about which name
makes for a clearer warning message. In this case, since x is explicitly
converted to long, referring to "long" would be less confusing. *Some* warning
is certainly appropriate, since "%d" requires an int argument.
(Speculation: gcc sees that the cast is a no-op, so it ignores it, which is
fine except that it results in this misleading warning message.)
Ubuntu x86 12.04
gcc (Ubuntu/Linaro 4.7.0-7ubuntu3) 4.7.0