<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Feature: Add a warning when case labels from a different enum than the one in switch(EXPR) are used"
   href="https://bugs.llvm.org/show_bug.cgi?id=39635">39635</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Feature: Add a warning when case labels from a different enum than the one in switch(EXPR) are used
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>avarab@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I've filed this against GCC as well:
<a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87983">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87983</a>


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)) [...]
```</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>