11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 18 namespace cppcoreguidelines {
22 return Node.getLocStart() < Node.getLabel()->getLocStart();
26 void AvoidGotoCheck::registerMatchers(MatchFinder *Finder) {
27 if (!getLangOpts().CPlusPlus)
36 auto Loop = stmt(anyOf(forStmt(), cxxForRangeStmt(), whileStmt(), doStmt()));
38 stmt(anyOf(forStmt(hasAncestor(Loop)), cxxForRangeStmt(hasAncestor(Loop)),
39 whileStmt(hasAncestor(Loop)), doStmt(hasAncestor(Loop))));
41 Finder->addMatcher(gotoStmt(anyOf(unless(hasAncestor(NestedLoop)),
42 unless(isForwardJumping())))
47 void AvoidGotoCheck::check(
const MatchFinder::MatchResult &Result) {
48 const auto *Goto = Result.Nodes.getNodeAs<GotoStmt>(
"goto");
50 diag(Goto->getGotoLoc(),
"avoid using 'goto' for flow control")
51 << Goto->getSourceRange();
52 diag(Goto->getLabel()->getLocStart(),
"label defined here",
AST_MATCHER(BinaryOperator, isAssignmentOperator)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//