11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 13 #include "clang/Lex/Lexer.h" 25 Options.store(Opts,
"IgnoreMacros", IgnoreMacros);
28 void UseEqualsDeleteCheck::registerMatchers(MatchFinder *Finder) {
29 if (!getLangOpts().CPlusPlus)
32 auto PrivateSpecialFn = cxxMethodDecl(
34 anyOf(cxxConstructorDecl(anyOf(isDefaultConstructor(),
35 isCopyConstructor(), isMoveConstructor())),
37 anyOf(isCopyAssignmentOperator(), isMoveAssignmentOperator())),
38 cxxDestructorDecl()));
43 unless(anyOf(hasBody(stmt()), isDefaulted(), isDeleted(),
44 ast_matchers::isTemplateInstantiation(),
47 hasParent(cxxRecordDecl(hasMethod(unless(
48 anyOf(PrivateSpecialFn, hasBody(stmt()), isPure(),
49 isDefaulted(), isDeleted()))))))))
50 .bind(SpecialFunction),
54 cxxMethodDecl(isDeleted(), unless(
isPublic())).bind(DeletedNotPublic),
58 void UseEqualsDeleteCheck::check(
const MatchFinder::MatchResult &
Result) {
59 if (
const auto *Func =
60 Result.Nodes.getNodeAs<CXXMethodDecl>(SpecialFunction)) {
61 SourceLocation EndLoc = Lexer::getLocForEndOfToken(
62 Func->getEndLoc(), 0, *Result.SourceManager, getLangOpts());
64 if (Func->getLocation().isMacroID() && IgnoreMacros)
67 diag(Func->getLocation(),
68 "use '= delete' to prohibit calling of a special member function")
69 << FixItHint::CreateInsertion(EndLoc,
" = delete");
70 }
else if (
const auto *Func =
71 Result.Nodes.getNodeAs<CXXMethodDecl>(DeletedNotPublic)) {
75 if (Func->getLocation().isMacroID() && IgnoreMacros)
78 diag(Func->getLocation(),
"deleted member function should be public");
static const char SpecialFunction[]
std::map< std::string, std::string > OptionMap
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
static bool isPublic(const clang::AccessSpecifier AS, const clang::Linkage Link)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static const char DeletedNotPublic[]