From c922df97b67e69cd78697adf55f4f7b17480e3d8 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 17 Dec 2013 22:44:28 +0000 Subject: [PATCH] Objctive-C. warn if dealloc is being overridden in a category implementation. // rdar://15397430 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197534 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticGroups.td | 1 + include/clang/Basic/DiagnosticSemaKinds.td | 3 +++ lib/Sema/SemaDeclObjC.cpp | 8 ++++++++ test/SemaObjC/dealloc.m | 20 ++++++++++++++++++-- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td index 1be01a2ed4..1c69e0075f 100644 --- a/include/clang/Basic/DiagnosticGroups.td +++ b/include/clang/Basic/DiagnosticGroups.td @@ -385,6 +385,7 @@ def ARCRepeatedUseOfWeak : DiagGroup<"arc-repeated-use-of-weak", [ARCRepeatedUseOfWeakMaybe]>; def ObjCBridge : DiagGroup<"bridge-cast">; +def DeallocInCategory:DiagGroup<"dealloc-in-category">; def SelectorTypeMismatch : DiagGroup<"selector-type-mismatch">; def Selector : DiagGroup<"selector", [SelectorTypeMismatch]>; def Protocol : DiagGroup<"protocol">; diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 19456297f2..d257e17501 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -776,6 +776,9 @@ def err_arc_perform_selector_retains : Error< def warn_arc_perform_selector_leaks : Warning< "performSelector may cause a leak because its selector is unknown">, InGroup>; +def warn_dealloc_in_category : Warning< +"decalloc is being overridden in category">, +InGroup; def err_gc_weak_property_strong_type : Error< "weak attribute declared on a __strong type property in GC mode">; def warn_receiver_is_weak : Warning < diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 9f50a207c1..d536f33c08 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -3213,6 +3213,14 @@ Decl *Sema::ActOnMethodDeclaration( ObjCMethod->addAttr( new (Context) ObjCRequiresSuperAttr(ObjCMethod->getLocation(), Context)); } + if (isa(ImpDecl)) { + ObjCMethodFamily family = ObjCMethod->getMethodFamily(); + if (family == OMF_dealloc && IMD && IMD->isOverriding()) { + Diag(ObjCMethod->getLocation(), diag::warn_dealloc_in_category) + << ObjCMethod->getDeclName(); + Diag(ImpDecl->getLocation(), diag::note_declared_at); + } + } } else { cast(ClassDecl)->addDecl(ObjCMethod); } diff --git a/test/SemaObjC/dealloc.m b/test/SemaObjC/dealloc.m index 59218d2d07..4e61424e68 100644 --- a/test/SemaObjC/dealloc.m +++ b/test/SemaObjC/dealloc.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -verify %s -// RUN: not %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -Wdealloc-in-category -verify %s +// RUN: not %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -Wdealloc-in-category -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s // rdar://11987838 @protocol NSObject @@ -23,3 +23,19 @@ @end +// rdar://15397430 +@interface Base +- (void)dealloc; +@end + +@interface Subclass : Base +@end + +@interface Subclass (CAT) +- (void)dealloc; +@end + +@implementation Subclass (CAT) // expected-note {{declared here}} +- (void)dealloc { // expected-warning {{decalloc is being overridden in category}} +} +@end -- 2.40.0