From: Fariborz Jahanian Date: Fri, 5 Dec 2008 01:35:25 +0000 (+0000) Subject: Patch for diagnosing type mismatch between X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=de7394157c3f83af55053128178aa71bdb08101c;p=clang Patch for diagnosing type mismatch between 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 --- diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index b3afd78fc7..9da662e476 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -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 ClsMap; // Check and see if class methods in class interface have been diff --git a/test/SemaObjC/comptypes-a.m b/test/SemaObjC/comptypes-a.m index bd8a7490c4..f00369f5ca 100644 --- a/test/SemaObjC/comptypes-a.m +++ b/test/SemaObjC/comptypes-a.m @@ -15,25 +15,15 @@ NSInteger codeAssistantCaseCompareItems(id a, id)a withThat:(id )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)a withThat:(id)b { +- compareThis:(id)a withThat:(id)b { // expected-error {{conflicting types for 'compareThis:withThat:'}} return self; } diff --git a/test/SemaObjC/method-def-1.m b/test/SemaObjC/method-def-1.m index c1cd6294b7..7948eed580 100644 --- a/test/SemaObjC/method-def-1.m +++ b/test/SemaObjC/method-def-1.m @@ -16,6 +16,6 @@ @implementation MyClass - (void)myMethod { } -- (void)myMethod2 { } +- (vid)myMethod2 { } // expected-error {{expected a type}} @end