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) {
26 if (!getLangOpts().CPlusPlus)
35 auto Loop = stmt(anyOf(forStmt(), cxxForRangeStmt(), whileStmt(), doStmt()));
37 stmt(anyOf(forStmt(hasAncestor(Loop)), cxxForRangeStmt(hasAncestor(Loop)),
38 whileStmt(hasAncestor(Loop)), doStmt(hasAncestor(Loop))));
40 Finder->addMatcher(gotoStmt(anyOf(unless(hasAncestor(NestedLoop)),
41 unless(isForwardJumping())))
46 void AvoidGotoCheck::check(
const MatchFinder::MatchResult &Result) {
47 const auto *Goto = Result.Nodes.getNodeAs<GotoStmt>(
"goto");
49 diag(Goto->getGotoLoc(),
"avoid using 'goto' for flow control")
50 << Goto->getSourceRange();
51 diag(Goto->getLabel()->getBeginLoc(),
"label defined here",
AST_MATCHER(Expr, isMacroID)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//