// under separate flags.
//
def UnreachableCodeLoopIncrement : DiagGroup<"unreachable-code-loop-increment">;
+def UnreachableCodeFallthrough : DiagGroup<"unreachable-code-fallthrough">;
def UnreachableCode : DiagGroup<"unreachable-code",
- [UnreachableCodeLoopIncrement]>;
+ [UnreachableCodeLoopIncrement,
+ UnreachableCodeFallthrough]>;
def UnreachableCodeBreak : DiagGroup<"unreachable-code-break">;
def UnreachableCodeReturn : DiagGroup<"unreachable-code-return">;
def UnreachableCodeAggressive : DiagGroup<"unreachable-code-aggressive",
def warn_unreachable_loop_increment : Warning<
"loop will run at most once (loop increment never executed)">,
InGroup<UnreachableCodeLoopIncrement>, DefaultIgnore;
+def warn_unreachable_fallthrough_attr : Warning<
+ "fallthrough annotation in unreachable code">,
+ InGroup<UnreachableCodeFallthrough>, DefaultIgnore;
def note_unreachable_silence : Note<
"silence by adding parentheses to mark code as explicitly dead">;
"fallthrough annotation is outside switch statement">;
def err_fallthrough_attr_invalid_placement : Error<
"fallthrough annotation does not directly precede switch label">;
-def warn_fallthrough_attr_unreachable : Warning<
- "fallthrough annotation in unreachable code">,
- InGroup<ImplicitFallthrough>, DefaultIgnore;
def warn_unreachable_default : Warning<
"default label in switch which covers all enumeration values">,
// unreachable in all instantiations of the template.
if (!IsTemplateInstantiation)
S.Diag(AS->getBeginLoc(),
- diag::warn_fallthrough_attr_unreachable);
+ diag::warn_unreachable_fallthrough_attr);
markFallthroughVisited(AS);
++AnnotatedCnt;
break;
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wimplicit-fallthrough %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wimplicit-fallthrough -Wunreachable-code-fallthrough %s
// expected-no-diagnostics
template<bool param>
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wimplicit-fallthrough %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wimplicit-fallthrough -Wunreachable-code-fallthrough %s
int fallthrough(int n) {
;
}
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunreachable-code-fallthrough"
+ switch (n) {
+ n += 300;
+ [[clang::fallthrough]]; // no warning here
+ case 221:
+ return 1;
+ [[clang::fallthrough]]; // no warning here
+ case 222:
+ return 2;
+ __attribute__((fallthrough)); // no warning here
+ case 223:
+ if (1)
+ return 3;
+ __attribute__((fallthrough)); // no warning here
+ case 224:
+ n += 400;
+ }
+#pragma clang diagnostic pop
+
long p = static_cast<long>(n) * n;
switch (sizeof(p)) {
case 9: