11 #include "clang/AST/ASTContext.h"
12 #include "clang/ASTMatchers/ASTMatchFinder.h"
13 #include "clang/Lex/Lexer.h"
15 using namespace clang::ast_matchers;
24 void UseEqualsDeleteCheck::registerMatchers(MatchFinder *
Finder) {
25 if (!getLangOpts().CPlusPlus)
28 auto PrivateSpecialFn = cxxMethodDecl(
30 anyOf(cxxConstructorDecl(anyOf(isDefaultConstructor(),
31 isCopyConstructor(), isMoveConstructor())),
33 anyOf(isCopyAssignmentOperator(), isMoveAssignmentOperator())),
34 cxxDestructorDecl()));
39 unless(anyOf(hasBody(stmt()), isDefaulted(), isDeleted(),
40 ast_matchers::isTemplateInstantiation(),
43 hasParent(cxxRecordDecl(hasMethod(unless(
44 anyOf(PrivateSpecialFn, hasBody(stmt()), isPure(),
45 isDefaulted(), isDeleted()))))))))
54 void UseEqualsDeleteCheck::check(
const MatchFinder::MatchResult &Result) {
55 if (
const auto *Func =
57 SourceLocation EndLoc = Lexer::getLocForEndOfToken(
58 Func->getLocEnd(), 0, *Result.SourceManager, getLangOpts());
61 diag(Func->getLocation(),
62 "use '= delete' to prohibit calling of a special member function")
63 << FixItHint::CreateInsertion(EndLoc,
" = delete");
64 }
else if (
const auto *Func =
69 if (Func->getLocation().isMacroID())
72 diag(Func->getLocation(),
"deleted member function should be public");
static const char SpecialFunction[]
std::unique_ptr< ast_matchers::MatchFinder > Finder
static const char DeletedNotPublic[]