]> granicus.if.org Git - clang/commitdiff
MyOtherClass<MyProtocol>* is compatible with MyClass*
authorChris Lattner <sabre@nondot.org>
Mon, 7 Apr 2008 06:06:56 +0000 (06:06 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 7 Apr 2008 06:06:56 +0000 (06:06 +0000)
if MyClass is a superclass of MyOtherClass, there is no need for
an exact interface match.

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

lib/AST/ASTContext.cpp
test/Sema/objc-comptypes-5.m

index 355308a40cac09226e270a7cc80417f99f38a224..c071e5ebd62a2fad67aa56f3ef95b37f5327e8f7 100644 (file)
@@ -1441,7 +1441,8 @@ static bool areCompatObjCInterfaces(const ObjCInterfaceType *LHS,
                                     const ObjCInterfaceType *RHS) {
   // II is compatible with II<P> if the base is the same.  Otherwise, no two
   // qualified interface types are the same.
-  if (LHS->getDecl() != RHS->getDecl()) return false;
+  if (!LHS->getDecl()->isSuperClassOf(RHS->getDecl()))
+    return false;
   
   // If the base decls match and one is a qualified interface and one isn't,
   // then they are compatible.
index e594a6e35dbe1c880bc3a1f8a108b31558686895..7101e9604384d7a6b453bce4e04b3a29821c0030 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: clang -fsyntax-only -verify %s
+// RUN: clang -fsyntax-only -pedantic -verify %s
 
 #define nil (void *)0;
 
@@ -23,6 +23,7 @@ int main()
   id <MyProtocol> obj_id_p = nil;
   MyClass *obj_c_cat_p = nil;
   MyOtherClass *obj_c_super_p = nil;
+  MyOtherClass<MyProtocol> *obj_c_super_p_q = nil;
 
   obj_c_cat_p = obj_id_p;   // expected-error {{incompatible type assigning 'id<MyProtocol>', expected 'MyClass *'}}
   obj_c_super_p = obj_id_p;  // expected-error {{incompatible type assigning 'id<MyProtocol>', expected 'MyOtherClass *'}}
@@ -34,5 +35,8 @@ int main()
   if (obj_id_p == obj_c_cat_p)  foo(); /* Ok */
   if (obj_id_p == obj_c_super_p)  foo(); /* Ok */
 
+  obj_c_cat_p = obj_c_super_p; // ok.
+  obj_c_cat_p = obj_c_super_p_q; // ok.
+  
   return 0;
 }