aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2009-05-14 23:52:54 +0000
committerFariborz Jahanian <fjahanian@apple.com>2009-05-14 23:52:54 +0000
commit2574a68e5cca0171f1e8c09373cb2f7e612ab77e (patch)
tree6cacccd32b8026d8f50e01e8348690156537c849
parente7a18c88b77523cf1085d239fd373770ba5791f1 (diff)
Don't warn if result/argument type of an implemented
method is a qualified id which conforms to the matching type of its method declaration. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71817 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/Sema.h1
-rw-r--r--lib/Sema/SemaDeclObjC.cpp7
-rw-r--r--lib/Sema/SemaExprObjC.cpp9
-rw-r--r--test/SemaObjC/class-conforming-protocol-2.m22
-rw-r--r--test/SemaObjC/method-conflict.m5
5 files changed, 39 insertions, 5 deletions
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 43d3816275..87c01075a8 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -1082,6 +1082,7 @@ public:
bool &IncompleteImpl);
void WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethod,
ObjCMethodDecl *IntfMethod);
+ bool QualifiedIdConformsQualifiedId(QualType LHS, QualType RHS);
NamespaceDecl *GetStdNamespace();
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index d854f0b50c..3c209440b0 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -775,7 +775,9 @@ void Sema::WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
void Sema::WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethodDecl,
ObjCMethodDecl *IntfMethodDecl) {
if (!Context.typesAreCompatible(IntfMethodDecl->getResultType(),
- ImpMethodDecl->getResultType())) {
+ ImpMethodDecl->getResultType()) &&
+ !QualifiedIdConformsQualifiedId(IntfMethodDecl->getResultType(),
+ ImpMethodDecl->getResultType())) {
Diag(ImpMethodDecl->getLocation(), diag::warn_conflicting_ret_types)
<< ImpMethodDecl->getDeclName() << IntfMethodDecl->getResultType()
<< ImpMethodDecl->getResultType();
@@ -785,7 +787,8 @@ void Sema::WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethodDecl,
for (ObjCMethodDecl::param_iterator IM = ImpMethodDecl->param_begin(),
IF = IntfMethodDecl->param_begin(), EM = ImpMethodDecl->param_end();
IM != EM; ++IM, ++IF) {
- if (Context.typesAreCompatible((*IF)->getType(), (*IM)->getType()))
+ if (Context.typesAreCompatible((*IF)->getType(), (*IM)->getType()) ||
+ QualifiedIdConformsQualifiedId((*IF)->getType(), (*IM)->getType()))
continue;
Diag((*IM)->getLocation(), diag::warn_conflicting_param_types)
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index 0073fd9f28..f8475a6727 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -697,6 +697,15 @@ static bool ClassImplementsProtocol(ObjCProtocolDecl *lProto,
return false;
}
+/// QualifiedIdConformsQualifiedId - compare id<p,...> with id<p1,...>
+/// return true if lhs's protocols conform to rhs's protocol; false
+/// otherwise.
+bool Sema::QualifiedIdConformsQualifiedId(QualType lhs, QualType rhs) {
+ if (lhs->isObjCQualifiedIdType() && rhs->isObjCQualifiedIdType())
+ return ObjCQualifiedIdTypesAreCompatible(lhs, rhs, false);
+ return false;
+}
+
/// ObjCQualifiedIdTypesAreCompatible - We know that one of lhs/rhs is an
/// ObjCQualifiedIDType.
/// FIXME: Move to ASTContext::typesAreCompatible() and friends.
diff --git a/test/SemaObjC/class-conforming-protocol-2.m b/test/SemaObjC/class-conforming-protocol-2.m
new file mode 100644
index 0000000000..7b218bdbd8
--- /dev/null
+++ b/test/SemaObjC/class-conforming-protocol-2.m
@@ -0,0 +1,22 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+@protocol NSWindowDelegate @end
+
+@interface NSWindow
+- (void)setDelegate:(id <NSWindowDelegate>)anObject;
+- (id <NSWindowDelegate>) delegate;
+@end
+
+@protocol IBStringsTableWindowDelegate <NSWindowDelegate>
+@end
+
+@interface IBStringsTableWindow : NSWindow {}
+@end
+
+@implementation IBStringsTableWindow
+- (void)setDelegate:(id <IBStringsTableWindowDelegate>)delegate {
+}
+- (id <IBStringsTableWindowDelegate>)delegate {
+ return 0;
+}
+@end
diff --git a/test/SemaObjC/method-conflict.m b/test/SemaObjC/method-conflict.m
index 1524fbae56..7a9b9f0bee 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 <XDUMLClassifier>) classifier withSpecification: (XDSCDisplaySpecification *) displaySpec; // expected-note {{previous definition is here}}
++ (NSUInteger) compartmentsForClassifier: (id <XDUMLClassifier>) classifier withSpecification: (XDSCDisplaySpecification *) displaySpec;
@end
@class NSString;
@implementation XDSCClassFormatter
@@ -48,7 +48,6 @@ typedef NSUInteger XDSourceLanguage;
+ appendVisibility: (id <XDUMLNamedElement>) element withSpecification: (XDSCDisplaySpecification *) displaySpec to: (NSMutableAttributedString *) attributedString
{
}
-// GCC doesn't currently warn about this.
-+ (NSUInteger) compartmentsForClassifier: (id <XDSCClassifier>) classifier withSpecification: (XDSCDisplaySpecification *) displaySpec { // expected-warning {{conflicting parameter types in implementation of 'compartmentsForClassifier:withSpecification:': 'id<XDUMLClassifier>' vs 'id<XDSCClassifier>'}}
++ (NSUInteger) compartmentsForClassifier: (id <XDSCClassifier>) classifier withSpecification: (XDSCDisplaySpecification *) displaySpec {
}
@end