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