10 #include "clang/AST/ASTContext.h"
11 #include "clang/ASTMatchers/ASTMatchFinder.h"
17 namespace cppcoreguidelines {
21 return Node.getBeginLoc() < Node.getLabel()->getBeginLoc();
25 void AvoidGotoCheck::registerMatchers(MatchFinder *Finder) {
32 auto Loop = stmt(anyOf(forStmt(), cxxForRangeStmt(), whileStmt(), doStmt()));
34 stmt(anyOf(forStmt(hasAncestor(Loop)), cxxForRangeStmt(hasAncestor(Loop)),
35 whileStmt(hasAncestor(Loop)), doStmt(hasAncestor(Loop))));
37 Finder->addMatcher(gotoStmt(anyOf(unless(hasAncestor(NestedLoop)),
38 unless(isForwardJumping())))
43 void AvoidGotoCheck::check(
const MatchFinder::MatchResult &Result) {
44 const auto *Goto = Result.Nodes.getNodeAs<GotoStmt>(
"goto");
46 diag(Goto->getGotoLoc(),
"avoid using 'goto' for flow control")
47 << Goto->getSourceRange();
48 diag(Goto->getLabel()->getBeginLoc(),
"label defined here",