This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/87983] New: Feature: Add a warning when case labels from a different enum than the one in switch(EXPR) are used
- From: "avarab at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 12 Nov 2018 09:11:12 +0000
- Subject: [Bug c/87983] New: Feature: Add a warning when case labels from a different enum than the one in switch(EXPR) are used
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87983
Bug ID: 87983
Summary: Feature: Add a warning when case labels from a
different enum than the one in switch(EXPR) are used
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: avarab at gmail dot com
Target Milestone: ---
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)) [...]
```