]> granicus.if.org Git - clang/commitdiff
Objective-C: check that when a category method is being implemented,
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 23 Oct 2012 23:06:22 +0000 (23:06 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 23 Oct 2012 23:06:22 +0000 (23:06 +0000)
method type in cateogry matches the implementation.
// rdar://12519216

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166518 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/method-typecheck-1.m

index a4fec7aebf651a0a3768c5b2f389d7e6234d09f3..c4e91e85015f36506b30925abc7f2f57c49099e3 100644 (file)
@@ -1709,14 +1709,26 @@ void Sema::MatchAllMethodDeclarations(const SelectorSet &InsMap,
   }
   
   if (ObjCInterfaceDecl *I = dyn_cast<ObjCInterfaceDecl> (CDecl)) {
-    // Also methods in class extensions need be looked at next.
-    for (const ObjCCategoryDecl *ClsExtDecl = I->getFirstClassExtension(); 
-         ClsExtDecl; ClsExtDecl = ClsExtDecl->getNextClassExtension())
-      MatchAllMethodDeclarations(InsMap, ClsMap, InsMapSeen, ClsMapSeen,
-                                 IMPDecl,
-                                 const_cast<ObjCCategoryDecl *>(ClsExtDecl), 
-                                 IncompleteImpl, false, 
-                                 WarnCategoryMethodImpl);
+    // when checking that methods in implementation match their declaration,
+    // i.e. when WarnCategoryMethodImpl is false, check declarations in class
+    // extension; as well as those in categories.
+    if (!WarnCategoryMethodImpl)
+      for (const ObjCCategoryDecl *CDeclChain = I->getCategoryList();
+           CDeclChain; CDeclChain = CDeclChain->getNextClassCategory())
+        MatchAllMethodDeclarations(InsMap, ClsMap, InsMapSeen, ClsMapSeen,
+                                   IMPDecl,
+                                   const_cast<ObjCCategoryDecl *>(CDeclChain),
+                                   IncompleteImpl, false,
+                                   WarnCategoryMethodImpl);
+    else 
+      // Also methods in class extensions need be looked at next.
+      for (const ObjCCategoryDecl *ClsExtDecl = I->getFirstClassExtension(); 
+           ClsExtDecl; ClsExtDecl = ClsExtDecl->getNextClassExtension())
+        MatchAllMethodDeclarations(InsMap, ClsMap, InsMapSeen, ClsMapSeen,
+                                   IMPDecl,
+                                   const_cast<ObjCCategoryDecl *>(ClsExtDecl), 
+                                   IncompleteImpl, false, 
+                                   WarnCategoryMethodImpl);
     
     // Check for any implementation of a methods declared in protocol.
     for (ObjCInterfaceDecl::all_protocol_iterator
index ee068d0bfccf82a9dfc2f70deff216430a8817e3..2d4e868cdf8251d1f4901343c8849481c3e8d5cd 100644 (file)
 (float) x { return 0; }        //  expected-warning {{conflicting parameter types in implementation of 'setCat:': 'int' vs 'float'}}
 + (int) cCat: (int) x { return 0; }    //  expected-warning {{conflicting return type in implementation of 'cCat:': 'void' vs 'int'}}
 @end
+
+// rdar://12519216
+// test that when implementation implements method in a category, types match.
+@interface testObject {}
+@end
+
+@interface testObject(Category)
+- (float)returnCGFloat; // expected-note {{previous definition is here}}
+@end
+
+@implementation testObject
+- (double)returnCGFloat { // expected-warning {{conflicting return type in implementation of 'returnCGFloat': 'float' vs 'double'}}
+  return 0.0;
+}
+@end