[cfe-dev] -Wunreachable-code vs -Wcovered-switch-default
Magnus Reftel
magnus.reftel at gmail.com
Tue Sep 11 00:40:14 PDT 2012
Hi all,
consider the following example code:
#include <stdlib.h>
enum e {E1, E2};
int main(int argc, char* argv[])
{
enum e e = atoi(argv[argc-1]);
switch(e)
{
case E1: return 1;
case E2: return 2;
default: return 3;
}
}
If compiled with Clang with -Wcovered-switch-default, it rightly warns
about the default case. This can be suppressed when intentional by
using -Wno-covered-switch-default. If compiled with
-Wunreachable-code, it will also warn on that line, but it seems that
that warning cannot be silenced when intentional without also
silencing all other occurrences of unreachable code in the file
("-Wunreachable-code -Wno-covered-switch-default" still warns).
I'd like to get warnings if there is unreachable code in the general
case, but not have it warn on covered switch defaults. Is there a way
of accomplishing that?
Best Regards
Magnus Reftel
More information about the cfe-dev
mailing list