[cfe-commits] r135001 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp lib/Sema/SemaObjCProperty.cpp test/SemaObjCXX/property-type-mismatch.mm

Eli Friedman eli.friedman at gmail.com
Tue Jul 12 15:27:14 PDT 2011


On Tue, Jul 12, 2011 at 3:05 PM, Fariborz Jahanian <fjahanian at apple.com> wrote:
> Author: fjahanian
> Date: Tue Jul 12 17:05:16 2011
> New Revision: 135001
>
> URL: http://llvm.org/viewvc/llvm-project?rev=135001&view=rev
> Log:
> objc++: Some level of covariance is allowed in ObjC properties.
> Make it also available in ObjC++ propeties. // rdar://9740328
>
> Added:
>    cfe/trunk/test/SemaObjCXX/property-type-mismatch.mm
> Modified:
>    cfe/trunk/include/clang/AST/ASTContext.h
>    cfe/trunk/lib/AST/ASTContext.cpp
>    cfe/trunk/lib/Sema/SemaObjCProperty.cpp
>
> Modified: cfe/trunk/include/clang/AST/ASTContext.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=135001&r1=135000&r2=135001&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/AST/ASTContext.h (original)
> +++ cfe/trunk/include/clang/AST/ASTContext.h Tue Jul 12 17:05:16 2011
> @@ -1417,6 +1417,7 @@
>   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 {
>
> Modified: cfe/trunk/lib/AST/ASTContext.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=135001&r1=135000&r2=135001&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/ASTContext.cpp (original)
> +++ cfe/trunk/lib/AST/ASTContext.cpp Tue Jul 12 17:05:16 2011
> @@ -5441,6 +5441,10 @@
>   return !mergeTypes(LHS, RHS, false, CompareUnqualified).isNull();
>  }
>
> +bool ASTContext::propertyTypesAreCompatible(QualType LHS, QualType RHS) {
> +  return !mergeTypes(LHS, RHS, false, false).isNull();
> +}

Using mergeTypes in C++ is generally a bad idea... it's fundamentally
implementing C semantics that don't make sense in C++, and it has
assertions which are easy to trigger in C++.

-Eli

>  bool ASTContext::typesAreBlockPointerCompatible(QualType LHS, QualType RHS) {
>   return !mergeTypes(LHS, RHS, true).isNull();
>  }
>
> Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=135001&r1=135000&r2=135001&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Tue Jul 12 17:05:16 2011
> @@ -909,7 +909,7 @@
>   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))
>
> Added: cfe/trunk/test/SemaObjCXX/property-type-mismatch.mm
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/property-type-mismatch.mm?rev=135001&view=auto
> ==============================================================================
> --- cfe/trunk/test/SemaObjCXX/property-type-mismatch.mm (added)
> +++ cfe/trunk/test/SemaObjCXX/property-type-mismatch.mm Tue Jul 12 17:05:16 2011
> @@ -0,0 +1,19 @@
> +// RUN: %clang_cc1 -fsyntax-only -verify %s
> +// rdar://9740328
> +
> + at protocol P1;
> +
> + at interface NSObject
> + at end
> +
> + at interface A : NSObject
> + at property (assign) NSObject<P1> *prop;
> + at end
> +
> + at protocol P2 <P1>
> + at end
> +
> + at interface B : A
> + at property (assign) NSObject<P2> *prop;
> + at end
> +
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>




More information about the cfe-commits mailing list