[cfe-commits] [Patch] Format string warnings should refer to "%zu" etc by typedef type

Hans Wennborg hans at chromium.org
Fri Dec 2 12:42:12 PST 2011


On Fri, Dec 2, 2011 at 7:43 PM, David Blaikie <dblaikie at gmail.com> wrote:
> This raises a question: Ideally this diagnostic should:
>
> a) verify that the type used for the parameter to printf is actually
> size_t, not unsigned int, for example

I suppose that depends how strict we want to be. If the type of size_t
on the platform is unsigned int, then the programmer isn't technically
doing anything wrong to pass such an argument for "%zu", though it
certainly isn't portable.

And what if the programmer has introduced their own "typedef size_t
my_size_type", should that be ok? Or "typedef __typeof(sizeof(int))
my_size_type" ?

> b) shouldn't mention the underlying type, only the typedef - since
> that's what the format specifier is for.

The problem is what it should do when the typedef isn't available (or
worse, typedeffed to the wrong type).


I'm not sure what the best thing to do is, but I think my patch made
it slightly better than it was before :)

 - Hans



More information about the cfe-commits mailing list