1 //===--- DeallocInCategoryCheck.cpp - clang-tidy -------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "DeallocInCategoryCheck.h"
10 #include "clang/AST/ASTContext.h"
11 #include "clang/AST/DeclObjC.h"
12 #include "clang/ASTMatchers/ASTMatchFinder.h"
14 using namespace clang::ast_matchers
;
20 void DeallocInCategoryCheck::registerMatchers(MatchFinder
*Finder
) {
21 // Non-NSObject/NSProxy-derived objects may not have -dealloc as a special
22 // method. However, it seems highly unrealistic to expect many false-positives
23 // by warning on -dealloc in categories on classes without one of those
26 objcMethodDecl(isInstanceMethod(), hasName("dealloc"),
27 hasDeclContext(objcCategoryImplDecl().bind("impl")))
32 void DeallocInCategoryCheck::check(const MatchFinder::MatchResult
&Result
) {
33 const auto *DeallocDecl
= Result
.Nodes
.getNodeAs
<ObjCMethodDecl
>("dealloc");
34 const auto *CID
= Result
.Nodes
.getNodeAs
<ObjCCategoryImplDecl
>("impl");
35 assert(DeallocDecl
!= nullptr);
36 diag(DeallocDecl
->getLocation(), "category %0 should not implement -dealloc")