]> granicus.if.org Git - clang/commitdiff
Patch for diagnosing type mismatch between
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 5 Dec 2008 01:35:25 +0000 (01:35 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 5 Dec 2008 01:35:25 +0000 (01:35 +0000)
methods in class and its implementation.
This is work in progress.

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

lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/comptypes-a.m
test/SemaObjC/method-def-1.m

index b3afd78fc7adc9d5a6a79ff39c6776f426c39393..9da662e4766ffece69aa5fffb6ccedde1fcf2f72 100644 (file)
@@ -643,6 +643,34 @@ void Sema::ImplMethodsVsClassMethods(ObjCImplementationDecl* IMPDecl,
        E = IDecl->instmeth_end(); I != E; ++I)
     if (!(*I)->isSynthesized() && !InsMap.count((*I)->getSelector()))
       WarnUndefinedMethod(IMPDecl->getLocation(), *I, IncompleteImpl);
+    else if (!(*I)->isSynthesized()){
+      bool err = false;
+      ObjCMethodDecl *ImpMethodDecl = 
+        IMPDecl->getInstanceMethod((*I)->getSelector());
+      ObjCMethodDecl *IntfMethodDecl = 
+        IDecl->getInstanceMethod((*I)->getSelector());
+      QualType ImpMethodQType = 
+        Context.getCanonicalType(ImpMethodDecl->getResultType());
+      QualType IntfMethodQType = 
+        Context.getCanonicalType(IntfMethodDecl->getResultType());
+      if (!Context.typesAreCompatible(IntfMethodQType, ImpMethodQType))
+        err = true;
+      else for (ObjCMethodDecl::param_iterator IM=ImpMethodDecl->param_begin(),
+                IF=IntfMethodDecl->param_begin(),
+                EM=ImpMethodDecl->param_end(); IM!=EM; ++IM, IF++) {
+        ImpMethodQType = Context.getCanonicalType((*IM)->getType());
+        IntfMethodQType = Context.getCanonicalType((*IF)->getType());
+        if (!Context.typesAreCompatible(IntfMethodQType, ImpMethodQType)) {
+          err = true;
+          break;
+        }
+      }
+      if (err) {
+        Diag(ImpMethodDecl->getLocation(), diag::err_conflicting_types) 
+          << ImpMethodDecl->getDeclName();
+        Diag(IntfMethodDecl->getLocation(), diag::note_previous_definition);
+      }
+    }
       
   llvm::DenseSet<Selector> ClsMap;
   // Check and see if class methods in class interface have been
index bd8a7490c413e68f33f51c65f56070a5f2bfd3f4..f00369f5cac5ebc870f6a476532ac456dff1a6f7 100644 (file)
@@ -15,25 +15,15 @@ NSInteger codeAssistantCaseCompareItems(id<PBXCompletionItem> a, id<PBXCompletio
 {
 }
 
-#if 0
-FIXME: clang needs to compare each method prototype with its definition (see below).
-
-GCC produces the following correct warnning:
-[snaroff:llvm/tools/clang] snarofflocal% cc -c test/Sema/objc-types-compatible.m 
-test/Sema/objc-types-compatible.m: In function ‘-[TedWantsToVerifyObjCDoesTheRightThing compareThis:withThat:]’:
-test/Sema/objc-types-compatible.m:26: warning: conflicting types for ‘-(id)compareThis:(id <PBXCompletionItem>)a withThat:(id <PBXCompletionItem>)b’
-test/Sema/objc-types-compatible.m:20: warning: previous declaration of ‘-(id)compareThis:(int)a withThat:(id)b’
-#endif
-
 @interface TedWantsToVerifyObjCDoesTheRightThing
 
-- compareThis:(int)a withThat:(id)b;
+- compareThis:(int)a withThat:(id)b;  // expected-note {{previous definition is here}}
 
 @end
 
 @implementation TedWantsToVerifyObjCDoesTheRightThing
 
-- compareThis:(id<PBXCompletionItem>)a withThat:(id<PBXCompletionItem>)b {
+- compareThis:(id<PBXCompletionItem>)a withThat:(id<PBXCompletionItem>)b { // expected-error {{conflicting types for 'compareThis:withThat:'}}
   return self;
 }
 
index c1cd6294b7e33152e4701ee58c326e7c8bfdd031..7948eed580e7cffbb3dcbc6379e7d86dd023b8aa 100644 (file)
@@ -16,6 +16,6 @@
 
 @implementation MyClass
 - (void)myMethod { }
-- (void)myMethod2 { }
+- (vid)myMethod2 { }   // expected-error {{expected a type}}
 @end