[cfe-dev] tautological-compare for unsigned chars

Tim Northover t.p.northover at gmail.com
Tue Jul 30 10:40:23 PDT 2013


> Am I right in thinking that char types are not checked for tautological-compare?

Certainly looks like it, but not through any active choice I think:

>       unsigned char c = (unsigned char)-1;
>       if(c >= 0) test();

This comparison is actually signed after the usual arithmetic
conversions have kicked in. An implicit cast is inserted making it
roughly "if ((int)c >= 0)".

It looks like code could be added to AnalyzeComparison to deal with
this case. CheckTrivialUnsignedComparison can probably do the right
thing already *if* it gets called.

Tim.



More information about the cfe-dev mailing list