29 const auto *Switch = Result.Nodes.getNodeAs<SwitchStmt>(
"switch");
30 if (IgnoreMacros && Switch->getBeginLoc().isMacroID())
33 std::size_t CaseCount = 0;
34 bool HasDefault =
false;
36 for (
const SwitchCase *CurrentCase = Switch->getSwitchCaseList(); CurrentCase;
37 CurrentCase = CurrentCase->getNextSwitchCase()) {
39 if (isa<DefaultStmt>(CurrentCase))
44 switch (
const SourceLocation Loc = Switch->getBeginLoc(); CaseCount) {
46 diag(Loc,
"switch statement without labels has no effect");
50 diag(Loc,
"switch with default label only");
52 diag(Loc,
"switch with only one case; use an if statement");
56 diag(Loc,
"switch could be better written as an if-else statement");
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.