[cfe-commits] r49320 - in /cfe/trunk: lib/AST/ASTContext.cpp test/Sema/objc-comptypes-5.m

Chris Lattner sabre at nondot.org
Sun Apr 6 23:06:57 PDT 2008


Author: lattner
Date: Mon Apr  7 01:06:56 2008
New Revision: 49320

URL: http://llvm.org/viewvc/llvm-project?rev=49320&view=rev
Log:
MyOtherClass<MyProtocol>* is compatible with MyClass*
if MyClass is a superclass of MyOtherClass, there is no need for
an exact interface match.

Modified:
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/test/Sema/objc-comptypes-5.m

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=49320&r1=49319&r2=49320&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon Apr  7 01:06:56 2008
@@ -1441,7 +1441,8 @@
                                     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.

Modified: cfe/trunk/test/Sema/objc-comptypes-5.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/objc-comptypes-5.m?rev=49320&r1=49319&r2=49320&view=diff

==============================================================================
--- cfe/trunk/test/Sema/objc-comptypes-5.m (original)
+++ cfe/trunk/test/Sema/objc-comptypes-5.m Mon Apr  7 01:06:56 2008
@@ -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 @@
   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 @@
   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;
 }





More information about the cfe-commits mailing list