This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/87983] New: Feature: Add a warning when case labels from a different enum than the one in switch(EXPR) are used


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)) [...]
```

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]