]> granicus.if.org Git - clang/commitdiff
objc++: Some level of covariance is allowed in ObjC properties.
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 12 Jul 2011 22:05:16 +0000 (22:05 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 12 Jul 2011 22:05:16 +0000 (22:05 +0000)
Make it also available in ObjC++ propeties. // rdar://9740328

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

include/clang/AST/ASTContext.h
lib/AST/ASTContext.cpp
lib/Sema/SemaObjCProperty.cpp
test/SemaObjCXX/property-type-mismatch.mm [new file with mode: 0644]

index 6d8158661dbd5801ccdcd633bbe60df2d91d5a23..1526f36ba2fb4f6ac95aee7843a50ee7a25b9ba9 100644 (file)
@@ -1417,6 +1417,7 @@ public:
   bool typesAreCompatible(QualType T1, QualType T2, 
                           bool CompareUnqualified = false); // C99 6.2.7p1
 
+  bool propertyTypesAreCompatible(QualType, QualType); 
   bool typesAreBlockPointerCompatible(QualType, QualType); 
 
   bool isObjCIdType(QualType T) const {
index c844adea3e95673f7735f3478971986ff5db1601..71b76c9d3285cc2d91e9cfcceec05bf1a42a1ddf 100644 (file)
@@ -5441,6 +5441,10 @@ bool ASTContext::typesAreCompatible(QualType LHS, QualType RHS,
   return !mergeTypes(LHS, RHS, false, CompareUnqualified).isNull();
 }
 
+bool ASTContext::propertyTypesAreCompatible(QualType LHS, QualType RHS) {
+  return !mergeTypes(LHS, RHS, false, false).isNull();
+}
+
 bool ASTContext::typesAreBlockPointerCompatible(QualType LHS, QualType RHS) {
   return !mergeTypes(LHS, RHS, true).isNull();
 }
index c830c3e166261f2b4899d11020f22a471c5d29d5..27f25c27ad254247d9e39c645757717ba46e714d 100644 (file)
@@ -909,7 +909,7 @@ Sema::DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
   QualType RHSType =
     Context.getCanonicalType(Property->getType());
 
-  if (!Context.typesAreCompatible(LHSType, RHSType)) {
+  if (!Context.propertyTypesAreCompatible(LHSType, RHSType)) {
     // FIXME: Incorporate this test with typesAreCompatible.
     if (LHSType->isObjCQualifiedIdType() && RHSType->isObjCQualifiedIdType())
       if (Context.ObjCQualifiedIdTypesAreCompatible(LHSType, RHSType, false))
diff --git a/test/SemaObjCXX/property-type-mismatch.mm b/test/SemaObjCXX/property-type-mismatch.mm
new file mode 100644 (file)
index 0000000..059793c
--- /dev/null
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// rdar://9740328
+
+@protocol P1;
+
+@interface NSObject
+@end
+
+@interface A : NSObject
+@property (assign) NSObject<P1> *prop;
+@end
+
+@protocol P2 <P1>
+@end
+
+@interface B : A
+@property (assign) NSObject<P2> *prop;
+@end
+