10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
19 return Node.getBeginLoc() <
Node.getLabel()->getBeginLoc();
30 auto Loop = mapAnyOf(forStmt, cxxForRangeStmt, whileStmt, doStmt);
31 auto NestedLoop = Loop.with(hasAncestor(Loop));
33 Finder->addMatcher(gotoStmt(anyOf(unless(hasAncestor(NestedLoop)),
34 unless(isForwardJumping())))
40 const auto *Goto = Result.Nodes.getNodeAs<GotoStmt>(
"goto");
42 diag(Goto->getGotoLoc(),
"avoid using 'goto' for flow control")
43 << Goto->getSourceRange();
44 diag(Goto->getLabel()->getBeginLoc(),
"label defined here",
::clang::DynTypedNode Node
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
AST_MATCHER(CXXRecordDecl, hasPublicVirtualOrProtectedNonVirtualDestructor)