[cfe-commits] r60573 - in /cfe/trunk: lib/Sema/SemaDeclObjC.cpp test/SemaObjC/comptypes-a.m test/SemaObjC/method-def-1.m
Fariborz Jahanian
fjahanian at apple.com
Thu Dec 4 17:35:25 PST 2008
Author: fjahanian
Date: Thu Dec 4 19:35:25 2008
New Revision: 60573
URL: http://llvm.org/viewvc/llvm-project?rev=60573&view=rev
Log:
Patch for diagnosing type mismatch between
methods in class and its implementation.
This is work in progress.
Modified:
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/SemaObjC/comptypes-a.m
cfe/trunk/test/SemaObjC/method-def-1.m
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=60573&r1=60572&r2=60573&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Thu Dec 4 19:35:25 2008
@@ -643,6 +643,34 @@
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
Modified: cfe/trunk/test/SemaObjC/comptypes-a.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/comptypes-a.m?rev=60573&r1=60572&r2=60573&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/comptypes-a.m (original)
+++ cfe/trunk/test/SemaObjC/comptypes-a.m Thu Dec 4 19:35:25 2008
@@ -15,25 +15,15 @@
{
}
-#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;
}
Modified: cfe/trunk/test/SemaObjC/method-def-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/method-def-1.m?rev=60573&r1=60572&r2=60573&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/method-def-1.m (original)
+++ cfe/trunk/test/SemaObjC/method-def-1.m Thu Dec 4 19:35:25 2008
@@ -16,6 +16,6 @@
@implementation MyClass
- (void)myMethod { }
-- (void)myMethod2 { }
+- (vid)myMethod2 { } // expected-error {{expected a type}}
@end
More information about the cfe-commits
mailing list