10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
12#include "clang/Lex/Lexer.h"
20 if (Node.hasBody() || Node.isPureVirtual() || Node.isDefaulted() ||
24 if (
const FunctionDecl *Definition = Node.getDefinition())
35 if (
const auto *Constructor = dyn_cast<CXXConstructorDecl>(&Node))
39 return isa<CXXDestructorDecl>(Node) || Node.isCopyAssignmentOperator() ||
40 Node.isMoveAssignmentOperator();
44 const DeclContext::lookup_result LookupResult =
45 Node.getParent()->lookup(Node.getNameInfo().getName());
47 if (LookupResult.isSingleResult())
50 static constexpr auto IsPublicOverload = [](
const Decl *Overload) {
51 return isa<CXXMethodDecl, FunctionTemplateDecl>(Overload) &&
52 Overload->getAccess() == AS_public;
55 return llvm::any_of(LookupResult, IsPublicOverload);
65 IgnoreMacros(Options.get(
"IgnoreMacros", true)) {}
68 Options.store(Opts,
"IgnoreMacros", IgnoreMacros);
72 auto PrivateSpecialFn = cxxMethodDecl(isPrivate(), isSpecialFunction());
76 PrivateSpecialFn, unless(hasAnyDefinition()), unless(isUsed()),
79 unless(ofClass(hasMethod(cxxMethodDecl(unless(PrivateSpecialFn),
80 unless(hasAnyDefinition()))))))
87 cxxMethodDecl(isDeleted(), unless(isPublic()),
88 anyOf(hasPublicOverload(), isSpecialFunction()))
94 if (
const auto *Func =
96 const SourceLocation EndLoc = Lexer::getLocForEndOfToken(
97 Func->getEndLoc(), 0, *Result.SourceManager, getLangOpts());
99 if (IgnoreMacros && Func->getLocation().isMacroID())
102 diag(Func->getLocation(),
103 "use '= delete' to prohibit calling of a special member function")
104 << FixItHint::CreateInsertion(EndLoc,
" = delete");
105 }
else if (
const auto *Func =
110 if (IgnoreMacros && Func->getLocation().isMacroID())
113 diag(Func->getLocation(),
"deleted member function should be public");
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
UseEqualsDeleteCheck(StringRef Name, ClangTidyContext *Context)
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
AST_MATCHER(BinaryOperator, isRelationalOperator)
static constexpr char SpecialFunction[]
static constexpr char DeletedNotPublic[]
llvm::StringMap< ClangTidyValue > OptionMap