https://bugs.llvm.org/show_bug.cgi?id=39635

            Bug ID: 39635
           Summary: Feature: Add a warning when case labels from a
                    different enum than the one in switch(EXPR) are used
           Product: clang
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangb...@nondot.org
          Reporter: ava...@gmail.com
                CC: htmldevelo...@gmail.com, llvm-bugs@lists.llvm.org,
                    richard-l...@metafoo.co.uk

I've filed this against GCC as well:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87983


A bug was fixed in git that would have been spotted by the following program
warning:

```
#include <stdio.h>

enum { A, B } foo = A;
enum { C, D } bar = C;

int main(void)
{   
    switch (foo) {
      case C: /* Should warn: switch() on C instead of A */
        puts("A");
        break;
      case B:
        puts("B");
        break;
    }
}
```

I don't know how hard it would be to implement this. I understand why it's not
warning, in C enums are only skin-deep, so the compiler would need to keep
track of "foo" and the name (not just value) of C and B, and it wouldn't work
in the more general case of:

```
switch (some_complex_function(foo)) [...]
```

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to