aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2007-12-21 17:34:43 +0000
committerFariborz Jahanian <fjahanian@apple.com>2007-12-21 17:34:43 +0000
commitb145e7dedebe2ac3c6e8233bece6ffc3f67b3a66 (patch)
tree9885b53ab7443f7173bc10cb396b194dcceee8e4
parent88d752103b5f46ee47d9af48c2c6b8ff013aaf5e (diff)
Patch to compare to objective-c static types where one or the other
(but not both) may be a protocol qualified static type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45283 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--AST/ASTContext.cpp17
-rw-r--r--test/Sema/objc-comptypes-4.m25
2 files changed, 41 insertions, 1 deletions
diff --git a/AST/ASTContext.cpp b/AST/ASTContext.cpp
index 5ec5131074..cd7b3cd73b 100644
--- a/AST/ASTContext.cpp
+++ b/AST/ASTContext.cpp
@@ -1225,12 +1225,27 @@ bool ASTContext::builtinTypesAreCompatible(QualType lhs, QualType rhs) {
return lBuiltin->getKind() == rBuiltin->getKind();
}
-
+/// objcTypesAreCompatible - This routine is called when two types
+/// are of different class; one is interface type or is
+/// a qualified interface type and the other type is of a different class.
+/// Example, II or II<P>.
bool ASTContext::objcTypesAreCompatible(QualType lhs, QualType rhs) {
if (lhs->isObjcInterfaceType() && isObjcIdType(rhs))
return true;
else if (isObjcIdType(lhs) && rhs->isObjcInterfaceType())
return true;
+ if (ObjcInterfaceType *lhsIT =
+ dyn_cast<ObjcInterfaceType>(lhs.getCanonicalType().getTypePtr())) {
+ ObjcQualifiedInterfaceType *rhsQI =
+ dyn_cast<ObjcQualifiedInterfaceType>(rhs.getCanonicalType().getTypePtr());
+ return rhsQI && (lhsIT->getDecl() == rhsQI->getDecl());
+ }
+ else if (ObjcInterfaceType *rhsIT =
+ dyn_cast<ObjcInterfaceType>(rhs.getCanonicalType().getTypePtr())) {
+ ObjcQualifiedInterfaceType *lhsQI =
+ dyn_cast<ObjcQualifiedInterfaceType>(lhs.getCanonicalType().getTypePtr());
+ return lhsQI && (rhsIT->getDecl() == lhsQI->getDecl());
+ }
return false;
}
diff --git a/test/Sema/objc-comptypes-4.m b/test/Sema/objc-comptypes-4.m
new file mode 100644
index 0000000000..bda9050164
--- /dev/null
+++ b/test/Sema/objc-comptypes-4.m
@@ -0,0 +1,25 @@
+// RUN: clang -fsyntax-only -verify %s
+
+extern void foo();
+
+@protocol MyProtocol @end
+
+@interface MyClass @end
+
+int main()
+{
+ MyClass <MyProtocol> *obj_p;
+ MyClass *obj_cp;
+
+ obj_cp = obj_p;
+ obj_p = obj_cp;
+
+ if (obj_cp == obj_p)
+ foo();
+
+ if (obj_p == obj_cp)
+ foo();
+
+}
+
+