[llvm-bugs] [Bug 39635] New: Feature: Add a warning when case labels from a different enum than the one in switch(EXPR) are used

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Nov 12 03:06:56 PST 2018


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: unassignedclangbugs at nondot.org
          Reporter: avarab at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20181112/5315605e/attachment.html>


More information about the llvm-bugs mailing list