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 auto PrivateSpecialFn = cxxMethodDecl(
30 anyOf(cxxConstructorDecl(anyOf(isDefaultConstructor(),
31 isCopyConstructor(), isMoveConstructor())),
33 anyOf(isCopyAssignmentOperator(), isMoveAssignmentOperator())),
34 cxxDestructorDecl()));
39 unless(anyOf(hasAnyBody(stmt()), isDefaulted(), isDeleted(),
40 ast_matchers::isTemplateInstantiation(),
43 hasParent(cxxRecordDecl(hasMethod(unless(
44 anyOf(PrivateSpecialFn, hasAnyBody(stmt()), isPure(),
45 isDefaulted(), isDeleted()))))))))
55 if (
const auto *Func =
57 SourceLocation EndLoc = Lexer::getLocForEndOfToken(
58 Func->getEndLoc(), 0, *Result.SourceManager, getLangOpts());
60 if (Func->getLocation().isMacroID() && IgnoreMacros)
63 diag(Func->getLocation(),
64 "use '= delete' to prohibit calling of a special member function")
65 << FixItHint::CreateInsertion(EndLoc,
" = delete");
66 }
else if (
const auto *Func =
71 if (Func->getLocation().isMacroID() && IgnoreMacros)
74 diag(Func->getLocation(),
"deleted member function should be public");