r196531 - ObjectiveC: Don't warn when method implemented in

Fariborz Jahanian fjahanian at apple.com
Thu Dec 5 12:52:31 PST 2013


Author: fjahanian
Date: Thu Dec  5 14:52:31 2013
New Revision: 196531

URL: http://llvm.org/viewvc/llvm-project?rev=196531&view=rev
Log:
ObjectiveC: Don't warn when method implemented in
category is declared in category's primary
class's super class. Because the super class is
expected to implemented the method. // rdar://15580969

Modified:
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/test/SemaObjC/incomplete-implementation.m

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=196531&r1=196530&r2=196531&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Thu Dec  5 14:52:31 2013
@@ -1867,27 +1867,39 @@ void Sema::MatchAllMethodDeclarations(co
 /// warns each time an exact match is found. 
 void Sema::CheckCategoryVsClassMethodMatches(
                                   ObjCCategoryImplDecl *CatIMPDecl) {
+  // Get category's primary class.
+  ObjCCategoryDecl *CatDecl = CatIMPDecl->getCategoryDecl();
+  if (!CatDecl)
+    return;
+  ObjCInterfaceDecl *IDecl = CatDecl->getClassInterface();
+  if (!IDecl)
+    return;
+  ObjCInterfaceDecl *SuperIDecl = IDecl->getSuperClass();
   SelectorSet InsMap, ClsMap;
   
   for (ObjCImplementationDecl::instmeth_iterator
        I = CatIMPDecl->instmeth_begin(), 
-       E = CatIMPDecl->instmeth_end(); I!=E; ++I)
-    InsMap.insert((*I)->getSelector());
+       E = CatIMPDecl->instmeth_end(); I!=E; ++I) {
+    Selector Sel = (*I)->getSelector();
+    // When checking for methods implemented in the category, skip over
+    // those declared in category class's super class. This is because
+    // the super class must implement the method.
+    if (SuperIDecl && SuperIDecl->lookupMethod(Sel, true))
+      continue;
+    InsMap.insert(Sel);
+  }
   
   for (ObjCImplementationDecl::classmeth_iterator
        I = CatIMPDecl->classmeth_begin(),
-       E = CatIMPDecl->classmeth_end(); I != E; ++I)
-    ClsMap.insert((*I)->getSelector());
+       E = CatIMPDecl->classmeth_end(); I != E; ++I) {
+    Selector Sel = (*I)->getSelector();
+    if (SuperIDecl && SuperIDecl->lookupMethod(Sel, false))
+      continue;
+    ClsMap.insert(Sel);
+  }
   if (InsMap.empty() && ClsMap.empty())
     return;
   
-  // Get category's primary class.
-  ObjCCategoryDecl *CatDecl = CatIMPDecl->getCategoryDecl();
-  if (!CatDecl)
-    return;
-  ObjCInterfaceDecl *IDecl = CatDecl->getClassInterface();
-  if (!IDecl)
-    return;
   SelectorSet InsMapSeen, ClsMapSeen;
   bool IncompleteImpl = false;
   MatchAllMethodDeclarations(InsMap, ClsMap, InsMapSeen, ClsMapSeen,

Modified: cfe/trunk/test/SemaObjC/incomplete-implementation.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/incomplete-implementation.m?rev=196531&r1=196530&r2=196531&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/incomplete-implementation.m (original)
+++ cfe/trunk/test/SemaObjC/incomplete-implementation.m Thu Dec  5 14:52:31 2013
@@ -39,3 +39,29 @@ __attribute__((visibility("default")))
 
 @end
 
+// rdar://15580969
+typedef char BOOL;
+
+ at protocol NSObject
+- (BOOL)isEqual:(id)object;
+ at end
+
+ at interface NSObject <NSObject>
+ at end
+
+ at protocol NSApplicationDelegate <NSObject>
+- (void)ImpleThisMethod; // expected-note {{method 'ImpleThisMethod' declared here}}
+ at end
+
+ at interface AppDelegate : NSObject <NSApplicationDelegate>
+ at end
+
+ at implementation AppDelegate (MRRCategory)
+
+- (BOOL)isEqual:(id)object
+{
+    return __objc_no;
+}
+
+- (void)ImpleThisMethod {} // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
+ at end





More information about the cfe-commits mailing list