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.

llvm-svn: 71817
This commit is contained in:
Fariborz Jahanian 2009-05-14 23:52:54 +00:00
parent 0555e5fbce
commit 0c20bddc41
5 changed files with 39 additions and 5 deletions

View File

@ -1082,6 +1082,7 @@ public:
bool &IncompleteImpl);
void WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethod,
ObjCMethodDecl *IntfMethod);
bool QualifiedIdConformsQualifiedId(QualType LHS, QualType RHS);
NamespaceDecl *GetStdNamespace();

View File

@ -775,6 +775,8 @@ void Sema::WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
void Sema::WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethodDecl,
ObjCMethodDecl *IntfMethodDecl) {
if (!Context.typesAreCompatible(IntfMethodDecl->getResultType(),
ImpMethodDecl->getResultType()) &&
!QualifiedIdConformsQualifiedId(IntfMethodDecl->getResultType(),
ImpMethodDecl->getResultType())) {
Diag(ImpMethodDecl->getLocation(), diag::warn_conflicting_ret_types)
<< ImpMethodDecl->getDeclName() << IntfMethodDecl->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)

View File

@ -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.

View File

@ -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

View File

@ -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