Given this code:
#include <stdio.h>
int main( int argc, char** argv )
{
switch (0) {
case 1: printf("1");
case 2: printf("2");
default:
printf("default");
break;
}
return 0;
}
I'd expect that the compiler would tell me something about either conditional expression is constant (switch (0) while VS2012 issues this warning for an if(0)) or unreachable code (case 1, case 2).
However, neither on ideone nor on Visual Studio 2012 nor on recent GCCs I receive anything like that.
Why don't even decent compilers complain here?
I just tried it on CLANG with extended warning turned on and received the following warning:

Referring to (oddly enough) only the the first of the two lines in the switch that will never be executed:
case 1: printf("1");
From the C 2011 standard:
5.1.1.3 Diagnostics
1 A conforming implementation shall produce at least one diagnostic message (identified in an implementation-defined manner) if a preprocessing translation unit or translation unit contains a violation of any syntax rule or constraint, even if the behavior is also explicitly specified as undefined or implementation-defined. Diagnostic messages need not be produced in other circumstances.9)
9) The intent is that an implementation should identify the nature of, and where possible localize, each violation. Of course, an implementation is free to produce any number of diagnostics as long as a valid program is still correctly translated. It may also successfully translate an invalid program.
Emphasis added.
So, a diagnostic is required if using a constant expression in a switch or if control expression is a constraint violation...
6.8.4.1 Theifstatement
Constraints
1 The controlling expression of anifstatement shall have scalar type.
...
6.8.4.2 Theswitchstatement
Constraints
1 The controlling expression of aswitchstatement shall have integer type.
2 If aswitchstatement has an associatedcaseordefaultlabel within the scope of an identifier with a variably modified type, the entireswitchstatement shall be within the scope of that identifier.154)
3 The expression of eachcaselabel shall be an integer constant expression and no two of the case constant expressions in the sameswitchstatement shall have the same value after conversion. There may be at most onedefaultlabel in a switch statement. (Any enclosedswitchstatement may have adefaultlabel orcaseconstant expressions with values that duplicatecaseconstant expressions in the enclosingswitchstatement.)
154) That is, the declaration either precedes theswitchstatement, or it follows the lastcaseordefaultlabel associated with theswitchthat is in the block containing the declaration.
...which it isn't.
This is basically a quality of implementation issue; the implementation may issue a diagnostic for using a constant expression in an if or switch statement, but it doesn't have to. if( 0 ) and switch( 0 ) may strike most of us as being hinky, but the implementation is not required to issue any diagnostics over them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With