10#include "../utils/LexerUtils.h"
11#include "../utils/Matchers.h"
12#include "clang/AST/ASTContext.h"
13#include "clang/ASTMatchers/ASTMatchFinder.h"
16using namespace clang::ast_matchers::internal;
25AST_MATCHER_P(CXXRecordDecl, hasBase, Matcher<QualType>, InnerMatcher) {
26 for (
const CXXBaseSpecifier &BaseSpec :
Node.bases()) {
27 QualType BaseType = BaseSpec.getType();
28 if (InnerMatcher.matches(BaseType, Finder,
Builder))
40 unless(anyOf(isFirstDecl(), isVirtual(),
41 ofClass(cxxRecordDecl(
42 anyOf(hasBase(unless(isTriviallyDestructible())),
44 hasType(isTriviallyDestructible()))))))))))
50 const auto *MatchedDecl = Result.Nodes.getNodeAs<CXXDestructorDecl>(
"decl");
53 SourceManager &SM = *Result.SourceManager;
54 const auto *FirstDecl = cast<CXXMethodDecl>(MatchedDecl->getFirstDecl());
57 const CharSourceRange SecondDeclRange = CharSourceRange::getTokenRange(
58 MatchedDecl->getBeginLoc(),
61 if (FirstDeclEnd.isInvalid() || SecondDeclRange.isInvalid())
65 diag(FirstDecl->getLocation(),
66 "class %0 can be made trivially destructible by defaulting the "
67 "destructor on its first declaration")
68 << FirstDecl->getParent()
69 << FixItHint::CreateInsertion(FirstDeclEnd,
" = default")
70 << FixItHint::CreateRemoval(SecondDeclRange);
71 diag(MatchedDecl->getLocation(),
"destructor definition is here",
const FunctionDecl * Decl
CodeCompletionBuilder Builder
::clang::DynTypedNode Node
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
const LangOptions & getLangOpts() const
Returns the language options from the context.
AST_MATCHER_P(UserDefinedLiteral, hasLiteral, clang::ast_matchers::internal::Matcher< Expr >, InnerMatcher)
AST_MATCHER(Decl, declHasNoReturnAttr)
matches a Decl if it has a "no return" attribute of any kind
SourceLocation findNextTerminator(SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts)