]> granicus.if.org Git - clang/commitdiff
Fix a bug in calculation of composite type
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 18 Apr 2011 21:16:59 +0000 (21:16 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 18 Apr 2011 21:16:59 +0000 (21:16 +0000)
of conditional expressions of objc pointer types
where one type is the immediate base type of the
other. // rdar://9296866

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

lib/AST/ASTContext.cpp
test/SemaObjC/conditional-expr-8.m [new file with mode: 0644]

index f723f2a8b7b139f26e53fb984a97fe9518e37a05..524a7563e64fb09ac3c358bcbd8da045dcfc38dd 100644 (file)
@@ -4963,10 +4963,10 @@ QualType ASTContext::areCommonBaseCompatible(
   const ObjCObjectType *RHS = Rptr->getObjectType();
   const ObjCInterfaceDecl* LDecl = LHS->getInterface();
   const ObjCInterfaceDecl* RDecl = RHS->getInterface();
-  if (!LDecl || !RDecl)
+  if (!LDecl || !RDecl || (LDecl == RDecl))
     return QualType();
   
-  while ((LDecl = LDecl->getSuperClass())) {
+  do {
     LHS = cast<ObjCInterfaceType>(getObjCInterfaceType(LDecl));
     if (canAssignObjCInterfaces(LHS, RHS)) {
       llvm::SmallVector<ObjCProtocolDecl *, 8> Protocols;
@@ -4978,7 +4978,7 @@ QualType ASTContext::areCommonBaseCompatible(
       Result = getObjCObjectPointerType(Result);
       return Result;
     }
-  }
+  } while ((LDecl = LDecl->getSuperClass()));
     
   return QualType();
 }
diff --git a/test/SemaObjC/conditional-expr-8.m b/test/SemaObjC/conditional-expr-8.m
new file mode 100644 (file)
index 0000000..6799983
--- /dev/null
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// rdar://9296866
+
+@interface NSResponder
+@end
+
+
+@interface NSView : NSResponder
+@end
+
+@interface WebView : NSView
+@end
+
+@protocol WebDocumentView
+@end
+
+@implementation NSView
+
+- (void) FUNC : (id)s {
+  WebView *m_webView;
+  NSView <WebDocumentView> *documentView;
+  NSView *coordinateView = s ?  documentView : m_webView;
+}
+@end
+