10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
18AST_MATCHER(CXXRecordDecl, hasDirectVirtualBaseClass) {
19 if (!
Node.hasDefinition())
return false;
20 if (!
Node.getNumVBases())
return false;
21 for (
const CXXBaseSpecifier &Base :
Node.bases())
22 if (Base.isVirtual())
return true;
29 Finder->addMatcher(cxxRecordDecl(hasDirectVirtualBaseClass()).bind(
"decl"),
34 if (
const auto *D = Result.Nodes.getNodeAs<CXXRecordDecl>(
"decl"))
35 diag(D->getBeginLoc(),
"direct virtual inheritance is disallowed");
::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(Decl, declHasNoReturnAttr)
matches a Decl if it has a "no return" attribute of any kind