[Bug c++/78014] -Wformat -vs- size_t
dmalcolm at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Jan 20 15:37:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78014
David Malcolm <dmalcolm at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |dmalcolm at gcc dot gnu.org
--- Comment #4 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
I wonder if it would be useful to have some kind of "-Wportability" or
somesuch: warn about code that, although it might work OK on the user's current
configuration, would be problematic on other configurations.
This sounds useful for the end-user, but hard to implement (could be done
piecemeal, I suppose).
(and "portability" would cover a lot of aspects: 32-bit vs 64-bit, little vs
big-endian, etc etc).
What should a warning for the code in comment #0 look like?
test.c:5: format code '%lu' assumes 'unsigned long', but argument is 'size_t'
[-Wportability]
printf("got %lu\n", x);
~~^
%zu
or somesuch?
Or even, brainstorming here, give it some knowledge of other archs e.g.:
test.c:5: format code '%lu' assumes 'unsigned long', but argument is 'size_t';
this will break on NAMES_OF_ARCHS_HERE [-Wportability=i686,ppcle]
printf("got %lu\n", x);
~~^
%zu
(not sure that this last one is a good idea, but mentioning it for sake of
argument)
More information about the Gcc-bugs
mailing list