10 #include "../utils/LexerUtils.h"
11 #include "../utils/Matchers.h"
12 #include "clang/AST/ASTContext.h"
13 #include "clang/ASTMatchers/ASTMatchFinder.h"
16 using namespace clang::ast_matchers::internal;
21 namespace performance {
27 AST_MATCHER_P(CXXRecordDecl, hasBase, Matcher<QualType>, InnerMatcher) {
28 for (
const CXXBaseSpecifier &BaseSpec : Node.bases()) {
29 QualType BaseType = BaseSpec.getType();
30 if (InnerMatcher.matches(BaseType, Finder,
Builder))
38 void TriviallyDestructibleCheck::registerMatchers(MatchFinder *Finder) {
42 unless(anyOf(isFirstDecl(), isVirtual(),
43 ofClass(cxxRecordDecl(
52 const auto *MatchedDecl = Result.Nodes.getNodeAs<CXXDestructorDecl>(
"decl");
55 SourceManager &SM = *Result.SourceManager;
56 const auto *FirstDecl = cast<CXXMethodDecl>(MatchedDecl->getFirstDecl());
58 FirstDecl->getEndLoc(), SM, getLangOpts());
59 const CharSourceRange SecondDeclRange = CharSourceRange::getTokenRange(
60 MatchedDecl->getBeginLoc(),
63 if (FirstDeclEnd.isInvalid() || SecondDeclRange.isInvalid())
67 diag(FirstDecl->getLocation(),
68 "class %0 can be made trivially destructible by defaulting the "
69 "destructor on its first declaration")
70 << FirstDecl->getParent()
71 << FixItHint::CreateInsertion(FirstDeclEnd,
" = default")
72 << FixItHint::CreateRemoval(SecondDeclRange);
73 diag(MatchedDecl->getLocation(),
"destructor definition is here",