From: Fariborz Jahanian Date: Tue, 12 Jul 2011 22:05:16 +0000 (+0000) Subject: objc++: Some level of covariance is allowed in ObjC properties. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c286f3835eb6001c61664cef5d610dfaf80a6e9b;p=clang objc++: Some level of covariance is allowed in ObjC properties. 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 --- diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index 6d8158661d..1526f36ba2 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -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 { diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index c844adea3e..71b76c9d32 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -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(); } diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp index c830c3e166..27f25c27ad 100644 --- a/lib/Sema/SemaObjCProperty.cpp +++ b/lib/Sema/SemaObjCProperty.cpp @@ -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 index 0000000000..059793cf5c --- /dev/null +++ b/test/SemaObjCXX/property-type-mismatch.mm @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// rdar://9740328 + +@protocol P1; + +@interface NSObject +@end + +@interface A : NSObject +@property (assign) NSObject *prop; +@end + +@protocol P2 +@end + +@interface B : A +@property (assign) NSObject *prop; +@end +