]> granicus.if.org Git - clang/commitdiff
Method declaration and its implementation must match in all their types.
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 5 Oct 2010 21:02:11 +0000 (21:02 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 5 Oct 2010 21:02:11 +0000 (21:02 +0000)
Previously, compiler warned only if it was unsafe if types
did not match. Fixes // rdar: //7933061

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

lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/class-conforming-protocol-2.m
test/SemaObjC/comptypes-a.m
test/SemaObjC/method-conflict-1.m [new file with mode: 0644]
test/SemaObjC/method-conflict.m

index 98c676b5cf97758d17e5d6b2ff60d655ed8aea9e..89ae18fc39fe2dc90477dd6146c466c7b497172c 100644 (file)
@@ -751,10 +751,8 @@ void Sema::WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
 
 void Sema::WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethodDecl,
                                        ObjCMethodDecl *IntfMethodDecl) {
-  if (!Context.typesAreCompatible(IntfMethodDecl->getResultType(),
-                                  ImpMethodDecl->getResultType()) &&
-      !Context.QualifiedIdConformsQualifiedId(IntfMethodDecl->getResultType(),
-                                              ImpMethodDecl->getResultType())) {
+  if (!Context.hasSameType(IntfMethodDecl->getResultType(),
+                           ImpMethodDecl->getResultType())) {
     Diag(ImpMethodDecl->getLocation(), diag::warn_conflicting_ret_types)
       << ImpMethodDecl->getDeclName() << IntfMethodDecl->getResultType()
       << ImpMethodDecl->getResultType();
@@ -766,8 +764,7 @@ void Sema::WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethodDecl,
        IM != EM; ++IM, ++IF) {
     QualType ParmDeclTy = (*IF)->getType().getUnqualifiedType();
     QualType ParmImpTy = (*IM)->getType().getUnqualifiedType();
-    if (Context.typesAreCompatible(ParmDeclTy, ParmImpTy) ||
-        Context.QualifiedIdConformsQualifiedId(ParmDeclTy, ParmImpTy))
+    if (Context.hasSameType(ParmDeclTy, ParmImpTy))
       continue;
 
     Diag((*IM)->getLocation(), diag::warn_conflicting_param_types)
index fcf9146a110fad8ba35e02bebf5f4259d1bdb952..32305d14e148d08f49594d4e56a30bedec6c4aec 100644 (file)
@@ -3,8 +3,8 @@
 @protocol NSWindowDelegate @end
 
 @interface NSWindow
-- (void)setDelegate:(id <NSWindowDelegate>)anObject;
-- (id <NSWindowDelegate>) delegate;
+- (void)setDelegate:(id <NSWindowDelegate>)anObject; // expected-note {{previous definition is here}}
+- (id <NSWindowDelegate>) delegate; // expected-note {{previous definition is here}}
 @end
 
 @protocol IBStringsTableWindowDelegate <NSWindowDelegate>
@@ -14,9 +14,9 @@
 @end
 
 @implementation IBStringsTableWindow
-- (void)setDelegate:(id <IBStringsTableWindowDelegate>)delegate {
+- (void)setDelegate:(id <IBStringsTableWindowDelegate>)delegate { // expected-warning {{conflicting parameter types in implementation of 'setDelegate:'}}
 }
-- (id <IBStringsTableWindowDelegate>)delegate {
+- (id <IBStringsTableWindowDelegate>)delegate { // expected-warning {{conflicting return type in implementation of 'delegate':}}
         return 0;
 }
 @end
index d48dfe4074fc7d3e02251845cf06e6adf5605edd..d7dddaad52dd61bd9a51964d1e05a81a1ea6a6b8 100644 (file)
@@ -18,7 +18,8 @@ NSInteger codeAssistantCaseCompareItems(id<PBXCompletionItem> a, id<PBXCompletio
 
 @interface TedWantsToVerifyObjCDoesTheRightThing
 
-- compareThis:(int)a withThat:(id)b;  // expected-note {{previous definition is here}}
+- compareThis:(int)a withThat:(id)b;  // expected-note {{previous definition is here}} \
+                                     // expected-note {{previous definition is here}}
 
 @end
 
@@ -26,7 +27,7 @@ NSInteger codeAssistantCaseCompareItems(id<PBXCompletionItem> a, id<PBXCompletio
 
 - compareThis:(id<PBXCompletionItem>)
     a // expected-warning {{conflicting parameter types in implementation of 'compareThis:withThat:': 'int' vs 'id<PBXCompletionItem>'}}
-     withThat:(id<PBXCompletionItem>)b {
+     withThat:(id<PBXCompletionItem>)b { // expected-warning {{conflicting parameter types in implementation of 'compareThis:withThat:': 'id' vs 'id<PBXCompletionItem>'}}
   return self;
 }
 
diff --git a/test/SemaObjC/method-conflict-1.m b/test/SemaObjC/method-conflict-1.m
new file mode 100644 (file)
index 0000000..871eb9d
--- /dev/null
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// rdar://7933061
+
+@interface NSObject @end
+
+@interface NSArray : NSObject @end
+
+@interface MyClass : NSObject {
+}
+- (void)myMethod:(NSArray *)object; // expected-note {{previous definition is here}}
+- (void)myMethod1:(NSObject *)object; // expected-note {{previous definition is here}}
+@end
+
+@implementation MyClass
+- (void)myMethod:(NSObject *)object { // expected-warning {{conflicting parameter types in implementation of 'myMethod:': 'NSArray *' vs 'NSObject *'}}
+}
+- (void)myMethod1:(NSArray *)object { // expected-warning {{conflicting parameter types in implementation of 'myMethod1:': 'NSObject *' vs 'NSArray *'}}
+}
+@end
+
+
+@protocol MyProtocol @end
+
+@interface MyOtherClass : NSObject <MyProtocol> {
+}
+- (void)myMethod:(id <MyProtocol>)object; // expected-note {{previous definition is here}}
+- (void)myMethod1:(id <MyProtocol>)object; // expected-note {{previous definition is here}}
+@end
+
+@implementation MyOtherClass
+- (void)myMethod:(MyClass *)object { // expected-warning {{conflicting parameter types in implementation of 'myMethod:': 'id<MyProtocol>' vs 'MyClass *'}}
+}
+- (void)myMethod1:(MyClass<MyProtocol> *)object { // expected-warning {{conflicting parameter types in implementation of 'myMethod1:': 'id<MyProtocol>' vs 'MyClass<MyProtocol> *'}}
+}
+@end
index 5dc886fb7fd245e5abacaf5239df8e42b900b269..ecdf1d88caba8a214550909c42c6ef4393520d72 100644 (file)
@@ -40,7 +40,7 @@ typedef NSUInteger XDSourceLanguage;
 @end  @class XDSCOperation;
 @interface XDSCClassFormatter : NSObject {
 }
-+ (NSUInteger) compartmentsForClassifier: (id <XDUMLClassifier>) classifier withSpecification: (XDSCDisplaySpecification *) displaySpec; 
++ (NSUInteger) compartmentsForClassifier: (id <XDUMLClassifier>) classifier withSpecification: (XDSCDisplaySpecification *) displaySpec;  // expected-note {{previous definition is here}}
 @end  
 @class NSString;
 @implementation XDSCClassFormatter       
@@ -49,7 +49,7 @@ typedef NSUInteger XDSourceLanguage;
 {
   return 0;
 }
-+ (NSUInteger) compartmentsForClassifier: (id <XDSCClassifier>) classifier withSpecification: (XDSCDisplaySpecification *) displaySpec {
++ (NSUInteger) compartmentsForClassifier: (id <XDSCClassifier>) classifier withSpecification: (XDSCDisplaySpecification *) displaySpec { // expected-warning {{conflicting parameter types in implementation of 'compartmentsForClassifier:withSpecification:'}}
   return 0;
 }
 @end