11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 13 #include "clang/Lex/Lexer.h" 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()))))))))
46 .bind(SpecialFunction),
50 cxxMethodDecl(isDeleted(), unless(
isPublic())).bind(DeletedNotPublic),
54 void UseEqualsDeleteCheck::check(
const MatchFinder::MatchResult &Result) {
55 if (
const auto *Func =
56 Result.Nodes.getNodeAs<CXXMethodDecl>(SpecialFunction)) {
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 =
65 Result.Nodes.getNodeAs<CXXMethodDecl>(DeletedNotPublic)) {
69 if (Func->getLocation().isMacroID())
72 diag(Func->getLocation(),
"deleted member function should be public");
static const char SpecialFunction[]
static bool isPublic(const clang::AccessSpecifier AS, const clang::Linkage Link)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static const char DeletedNotPublic[]