[cfe-dev] -Wunique-enum; is it worth it?

Richard Trieu rtrieu at google.com
Wed Sep 12 15:29:19 PDT 2012


On Wed, Sep 12, 2012 at 3:07 PM, Sean McBride <sean at rogue-research.com>wrote:

> On Wed, 12 Sep 2012 14:30:32 -0700, Richard Trieu said:
>
> >One way that this may manifest is during
> >testing of enum values:
> >
> >enum Foo { A = 0, B = 0 };
> >Foo f = B;
> >if (f == A)
> >  ActOnA();  // Runs since A == B
> >else if (f == B)
> >  ActOnB();  // Never runs.
>
> Not to hijack your thread, and I know it's just one example.... but
> catching 'if' conditions that match previous ones would be valuable whether
> there are enums involved or not.  I filed a PR long ago:
> <http://llvm.org/bugs/show_bug.cgi?id=9193>
>
> This is something PVS Studio can catch!  An example I saw the other day:
>
Does PVS Studio only catch identical conditional (x == 5 and later x == 5)
or can it catch equivalent, but differently coded conditionals (x == 5 then
x == 2 + 3)?

>
> ----------------------------------
> V517 The use of 'if (A) {...} else if (A) {...}' pattern was detected.
> There is a probability of logical error presence. Check lines: 224, 227.
> lproj lproj.c 224
>
> static void vprocess(FILE *fid) {
>   char *s;
>   ...
>   if (*s == 'I' || *s == 'i') {
>     linvers = 1;
>     ++s;
>   } else if (*s == 'I' || *s == 'i') {
>     linvers = 0;
>     ++s;
>   } else
>   ...
> }
> ----------------------------------
>
> Cheers,
>
> --
> ____________________________________________________________
> Sean McBride, B. Eng                 sean at rogue-research.com
> Rogue Research                        www.rogue-research.com
> Mac Software Developer              Montréal, Québec, Canada
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120912/ffb7ea65/attachment.html>


More information about the cfe-dev mailing list