From 627788c29976fbeb4ad47bcfcb3576889070e357 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 12 Apr 2011 16:34:14 +0000 Subject: [PATCH] Fix a regression where the initializer implements the initialized's protocol and yet clang warns. objective-c issue, // rdar://9267196 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129363 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/DeclObjC.h | 21 ---------- lib/AST/ASTContext.cpp | 8 ++-- .../unqualified-to-qualified-class-warn.m | 41 +++++++++++++++++++ 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index 241d76c448..84e7a63b02 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -629,27 +629,6 @@ public: return false; } - /// getImmSubClassOf - Returns Immediate sub-class of the specified interface class - /// if 'Super' is a superclass of this class. null if no such super class. - /// So in this example if 'this' is 'BClass' and 'Super' is 'AClass' then 'BClass' - /// is returned. - /// \code - /// @interface BClass : AClass - /// @end - /// \endcode - - ObjCInterfaceDecl *getImmSubClassOf(const ObjCInterfaceDecl *Super) { - ObjCInterfaceDecl *ImmSubClass = this; - ObjCInterfaceDecl *I = this->getSuperClass(); - while (I != NULL) { - if (Super == I) - return ImmSubClass; - ImmSubClass = I; - I = I->getSuperClass(); - } - return NULL; - } - ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName, ObjCInterfaceDecl *&ClassDeclared); ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName) { diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 420fcd398d..7317928d97 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -4987,15 +4987,15 @@ bool ASTContext::canAssignObjCInterfaces(const ObjCObjectType *LHS, // OK, if LHS is a superclass of RHS *and* // this superclass is assignment compatible with LHS. // false otherwise. - ObjCInterfaceDecl *SuperClass = - RHS->getInterface()->getImmSubClassOf(LHS->getInterface()); - if (SuperClass) { + bool IsSuperClass = + LHS->getInterface()->isSuperClassOf(RHS->getInterface()); + if (IsSuperClass) { // OK if conversion of LHS to SuperClass results in narrowing of types // ; i.e., SuperClass may implement at least one of the protocols // in LHS's protocol list. Example, SuperObj = lhs is ok. // But not SuperObj = lhs. llvm::SmallPtrSet SuperClassInheritedProtocols; - CollectInheritedProtocols(SuperClass, SuperClassInheritedProtocols); + CollectInheritedProtocols(RHS->getInterface(), SuperClassInheritedProtocols); // If super class has no protocols, it is not a match. if (SuperClassInheritedProtocols.empty()) return false; diff --git a/test/SemaObjC/unqualified-to-qualified-class-warn.m b/test/SemaObjC/unqualified-to-qualified-class-warn.m index 5bbbfd9fcc..e6fa13850f 100644 --- a/test/SemaObjC/unqualified-to-qualified-class-warn.m +++ b/test/SemaObjC/unqualified-to-qualified-class-warn.m @@ -29,3 +29,44 @@ int main () { functionTakingAClassConformingToAProtocol(bobject); // Shouldn't warn - does implement Fooable return 0; } + +// rdar://9267196 +@interface NSObject @end + +@protocol MyProtocol +@end + +@interface MyClass : NSObject +{ +} +@end + +@implementation MyClass +@end + +@interface MySubclass : MyClass +{ +} +@end + +@interface MyTestClass : NSObject +{ +@private + NSObject *someObj; +} + +@property (nonatomic, assign) NSObject *someObj; + +@end + +@implementation MyTestClass + +@synthesize someObj; + +- (void)someMethod +{ + MySubclass *foo; + [self setSomeObj:foo]; // no warning here! +} + +@end -- 2.40.0