[Bug c++/32291] New: -Wformat either too picky or not picky enough
scovich at gmail dot com
gcc-bugzilla@gcc.gnu.org
Mon Jun 11 20:29:00 GMT 2007
Compiling the following snippet with -Wformat (or -Wall) causes the compiler to
complain: "wformat-bug.C:8: warning: format '%u' expects type 'unsigned int',
but argument 2 has type 'uint32_t'"
The problem seems to be that stdint.h defines uint32_t as "long" in cygwin. I
realize that int != long on some platforms, but i686 isn't one of them. Why
should the user be forced to cast their uint32_t (read: 32-bit unsigned int) to
"unsigned int" before passing it to printf() when they are logically identical?
On the other hand, there's no complaint about passing a signed integer into an
unsigned format or vice-versa, even though the output value might actually
change because of the oversight in those cases.
wformat.C:
=======================================
#include <cstdio>
#include <stdint.h>
int main() {
uint32_t a = ~0;
unsigned int b = a;
uint32_t c = b;
printf("%u\n", c); // warning (?)
int d = c;
unsigned e = d;
printf("%d\n", e); // no warning
printf("%u\n", d); // no warning
}
--
Summary: -Wformat either too picky or not picky enough
Product: gcc
Version: 4.2.0
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: scovich at gmail dot com
GCC target triplet: i686-pc-cygwin
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32291
More information about the Gcc-bugs
mailing list