https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61864
Bug ID: 61864 Summary: Feature Request, -Wcovered-switch-default to identify "dead" default branch Product: gcc Version: 4.10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: chengniansun at gmail dot com Currently, GCC supports -Wswitch and -Wswitch-enum. But it does not warn on the case that all the possible values of an enum are covered in a switch, making the default branch unreachable. The following code is extracted and simplified from the SPEC benchmark, the enum only has three values, which are all covered in the switch. Therefore the default branch is "dead". $: cat t.c enum clust_strategy { CLUSTER_MEAN, CLUSTER_MAX, CLUSTER_MIN }; int Cluster(enum clust_strategy mode) { switch(mode) { case CLUSTER_MEAN: break; case CLUSTER_MAX: break; case CLUSTER_MIN: break; default: break; } return 0; } $: clang-trunk -Wcovered-switch-default -c t.c t.c:10:3: warning: default label in switch which covers all enumeration values [-Wcovered-switch-default] default: break; ^ 1 warning generated. $: