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

Sean McBride sean at rogue-research.com
Wed Sep 12 15:07:40 PDT 2012


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:

----------------------------------
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






More information about the cfe-dev mailing list