[cfe-dev] warning with conditional operator and printf, is this a bug ?

Abramo Bagnara abramo.bagnara at gmail.com
Fri Nov 4 12:10:53 PDT 2011


Il 04/11/2011 08:20, John McCall ha scritto:
> It's a clear false positive in our format checker.  Promoting an unsigned value to a wider signed type performs a zero-extend, so the distinction between signed and unsigned formats is irrelevant and either %d or %ud should be acceptable.  (The reverse would not be true:  we should still warn about using unsigned formats with promoted signed types).

It is not clear to me how you intend to do that: conditional operator
operands are promoted *before* to evaluate the operator. Unless you use
some complex way to track the original type despite the promotions I
don't see any way to avoid this warning.

Also I don't believe it is so clear that it is a false positive: indeed
we are passing an integer argument to an unsigned short format.

Of course if the example was:

unsigned short x;
printf("%d", x);
printf("%u", x);

you argument would be very accurate and agreeable.



More information about the cfe-dev mailing list