[enum comparison] switch vs if

Hi all!

I’m interested in developing a clang static checker for enum comparison in switch and throwing a warning.
I found out that it already exists in if comparison in clang but my question is:
Is this on purpose that different enum types don’t send warning or int and enum comparison in switches but send in if?
Example:

enum MIXED_ENUMS_e { E1, E2 };
enum MIXED_ENUMS_f { F0, F1, F2, F3 };

void mixed_enums(MIXED_ENUMS_e ee)
{
  int x;

  switch (ee)
  {
    case E1: x = 1; break;
    case F1: x = 2; break; // TODO warning: ee and F1 have different types.
  }

  switch (x)
  {
    case E1: ++x; break; // TODO warning: x and E1 have different types.
    case F3: --x; break; // TODO warning: x and F3 have different types.
  }
  if  (ee == F0) {} // Already exsisting warning: ee and F0 have different types.
  **if**  (ee == x) {}<i> // Already exsisting warning: ee and x have different types.
</i>}

BR Alex.

Hello!

Sounds great! In my humble opinion that would be a great addition. And I would suggest it's added in Sema as a normal compiler warning (on by default).

Best regards,
Daniel Marjamäki

..................................................................................................................
Daniel Marjamäki
Senior Engineer
Evidente ES East AB
Warfvinges väg 34 SE-112 51 Stockholm Sweden

Mobile:
+46 (0)709 12 42 62
E-mail:
Daniel.Marjamaki@evidente.se

www.evidente.se