From bdaae392d4ede29c992db6c40c14860a0505415f Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 5 Oct 2010 21:02:11 +0000 Subject: Method declaration and its implementation must match in all their types. 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 | 9 +++----- test/SemaObjC/class-conforming-protocol-2.m | 8 +++---- test/SemaObjC/comptypes-a.m | 5 +++-- test/SemaObjC/method-conflict-1.m | 35 +++++++++++++++++++++++++++++ test/SemaObjC/method-conflict.m | 4 ++-- 5 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 test/SemaObjC/method-conflict-1.m diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 98c676b5cf..89ae18fc39 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -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) diff --git a/test/SemaObjC/class-conforming-protocol-2.m b/test/SemaObjC/class-conforming-protocol-2.m index fcf9146a11..32305d14e1 100644 --- a/test/SemaObjC/class-conforming-protocol-2.m +++ b/test/SemaObjC/class-conforming-protocol-2.m @@ -3,8 +3,8 @@ @protocol NSWindowDelegate @end @interface NSWindow -- (void)setDelegate:(id )anObject; -- (id ) delegate; +- (void)setDelegate:(id )anObject; // expected-note {{previous definition is here}} +- (id ) delegate; // expected-note {{previous definition is here}} @end @protocol IBStringsTableWindowDelegate @@ -14,9 +14,9 @@ @end @implementation IBStringsTableWindow -- (void)setDelegate:(id )delegate { +- (void)setDelegate:(id )delegate { // expected-warning {{conflicting parameter types in implementation of 'setDelegate:'}} } -- (id )delegate { +- (id )delegate { // expected-warning {{conflicting return type in implementation of 'delegate':}} return 0; } @end diff --git a/test/SemaObjC/comptypes-a.m b/test/SemaObjC/comptypes-a.m index d48dfe4074..d7dddaad52 100644 --- a/test/SemaObjC/comptypes-a.m +++ b/test/SemaObjC/comptypes-a.m @@ -18,7 +18,8 @@ NSInteger codeAssistantCaseCompareItems(id a, id a, id) a // expected-warning {{conflicting parameter types in implementation of 'compareThis:withThat:': 'int' vs 'id'}} - withThat:(id)b { + withThat:(id)b { // expected-warning {{conflicting parameter types in implementation of 'compareThis:withThat:': 'id' vs 'id'}} return self; } diff --git a/test/SemaObjC/method-conflict-1.m b/test/SemaObjC/method-conflict-1.m new file mode 100644 index 0000000000..871eb9d049 --- /dev/null +++ b/test/SemaObjC/method-conflict-1.m @@ -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 { +} +- (void)myMethod:(id )object; // expected-note {{previous definition is here}} +- (void)myMethod1:(id )object; // expected-note {{previous definition is here}} +@end + +@implementation MyOtherClass +- (void)myMethod:(MyClass *)object { // expected-warning {{conflicting parameter types in implementation of 'myMethod:': 'id' vs 'MyClass *'}} +} +- (void)myMethod1:(MyClass *)object { // expected-warning {{conflicting parameter types in implementation of 'myMethod1:': 'id' vs 'MyClass *'}} +} +@end diff --git a/test/SemaObjC/method-conflict.m b/test/SemaObjC/method-conflict.m index 5dc886fb7f..ecdf1d88ca 100644 --- a/test/SemaObjC/method-conflict.m +++ b/test/SemaObjC/method-conflict.m @@ -40,7 +40,7 @@ typedef NSUInteger XDSourceLanguage; @end @class XDSCOperation; @interface XDSCClassFormatter : NSObject { } -+ (NSUInteger) compartmentsForClassifier: (id ) classifier withSpecification: (XDSCDisplaySpecification *) displaySpec; ++ (NSUInteger) compartmentsForClassifier: (id ) 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 ) classifier withSpecification: (XDSCDisplaySpecification *) displaySpec { ++ (NSUInteger) compartmentsForClassifier: (id ) classifier withSpecification: (XDSCDisplaySpecification *) displaySpec { // expected-warning {{conflicting parameter types in implementation of 'compartmentsForClassifier:withSpecification:'}} return 0; } @end -- cgit v1.2.3-18-g5258