They are covered by -Wcovered-switch-default.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202349
91177308-0d34-0410-b5e6-
96231b3b80d8
if (isBreakPrecededByNoReturn(B, S))
return;
+ // Was this an unreachable 'default' case? Such cases are covered
+ // by -Wcovered-switch-default, if the user so desires.
+ const Stmt *Label = B->getLabel();
+ if (Label && isa<DefaultStmt>(Label))
+ return;
+
SourceRange R1, R2;
SourceLocation Loc = GetUnreachableLoc(S, R1, R2);
CB.HandleUnreachable(Loc, R1, R2);
case C3:
return 1;
default: {
- int i = 0; // expected-warning{{will never be executed}}
+ int i = 0; // no-warning
++i;
return i;
}
}
return i;
}
+
+// Don't warn about unreachable 'default' cases, as that is covered
+// by -Wcovered-switch-default.
+typedef enum { Value1 = 1 } MyEnum;
+void unreachable_default(MyEnum e) {
+ switch (e) {
+ case Value1:
+ calledFun();
+ break;
+ default:
+ calledFun(); // no-warning
+ break;
+ }
+}
+void unreachable_in_default(MyEnum e) {
+ switch (e) {
+ default:
+ raze();
+ calledFun(); // expected-warning {{will never be executed}}
+ break;
+ }
+}
+