[cfe-commits] r65949 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.def lib/Sema/SemaDeclObjC.cpp lib/Sema/SemaExprObjC.cpp test/SemaObjC/property-inherited.m
Steve Naroff
snaroff at apple.com
Tue Mar 3 07:43:36 PST 2009
Author: snaroff
Date: Tue Mar 3 09:43:24 2009
New Revision: 65949
URL: http://llvm.org/viewvc/llvm-project?rev=65949&view=rev
Log:
Fix <rdar://problem/6497242> Inherited overridden protocol declared objects don't work.
Change Sema::DiagnosePropertyMismatch() to check for type compatibility (rather than type equivalence, which is too strict).
Added:
cfe/trunk/test/SemaObjC/property-inherited.m
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/lib/Sema/SemaExprObjC.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def?rev=65949&r1=65948&r2=65949&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def Tue Mar 3 09:43:24 2009
@@ -144,8 +144,8 @@
"'readwrite' of property inherited from %1")
DIAG(warn_property_attribute, WARNING,
"property %0 '%1' attribute does not match the property inherited from %2")
-DIAG(warn_property_type, WARNING,
- "property type %0 does not match property type inherited from %1")
+DIAG(warn_property_types_are_incompatible, WARNING,
+ "property type %0 is incompatible with type %1 inherited from %2")
DIAG(err_undef_interface, ERROR,
"cannot find interface declaration for %0")
DIAG(warn_dup_category_def, WARNING,
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=65949&r1=65948&r2=65949&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Tue Mar 3 09:43:24 2009
@@ -320,12 +320,20 @@
if (Property->getGetterName() != SuperProperty->getGetterName())
Diag(Property->getLocation(), diag::warn_property_attribute)
<< Property->getDeclName() << "getter" << inheritedName;
-
- if (Context.getCanonicalType(Property->getType()) !=
- Context.getCanonicalType(SuperProperty->getType()))
- Diag(Property->getLocation(), diag::warn_property_type)
- << Property->getType() << inheritedName;
-
+
+ QualType LHSType =
+ Context.getCanonicalType(SuperProperty->getType());
+ QualType RHSType =
+ Context.getCanonicalType(Property->getType());
+
+ if (!Context.typesAreCompatible(LHSType, RHSType)) {
+ // FIXME: Incorporate this test with typesAreCompatible.
+ if (LHSType->isObjCQualifiedIdType() && RHSType->isObjCQualifiedIdType())
+ if (ObjCQualifiedIdTypesAreCompatible(LHSType, RHSType, false))
+ return;
+ Diag(Property->getLocation(), diag::warn_property_types_are_incompatible)
+ << Property->getType() << SuperProperty->getType() << inheritedName;
+ }
}
/// ComparePropertiesInBaseAndSuper - This routine compares property
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=65949&r1=65948&r2=65949&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Tue Mar 3 09:43:24 2009
@@ -540,6 +540,7 @@
/// ObjCQualifiedIdTypesAreCompatible - We know that one of lhs/rhs is an
/// ObjCQualifiedIDType.
+/// FIXME: Move to ASTContext::typesAreCompatible() and friends.
bool Sema::ObjCQualifiedIdTypesAreCompatible(QualType lhs, QualType rhs,
bool compare) {
// Allow id<P..> and an 'id' or void* type in all cases.
Added: cfe/trunk/test/SemaObjC/property-inherited.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-inherited.m?rev=65949&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/property-inherited.m (added)
+++ cfe/trunk/test/SemaObjC/property-inherited.m Tue Mar 3 09:43:24 2009
@@ -0,0 +1,44 @@
+// RUN: clang %s -fsyntax-only -verify
+
+// <rdar://problem/6497242> Inherited overridden protocol declared objects don't work
+
+ at protocol NSObject @end
+ at interface NSObject @end
+
+ at protocol FooDelegate<NSObject>
+ at optional
+- (void)fooTask;
+ at end
+
+ at protocol BarDelegate<NSObject, FooDelegate>
+ at optional
+- (void)barTask;
+ at end
+
+ at interface Foo : NSObject {
+ id _delegate;
+}
+ at property(nonatomic, assign) id<FooDelegate> delegate;
+ at property(nonatomic, assign) id<BarDelegate> delegate2;
+ at end
+ at interface Bar : Foo {
+}
+ at property(nonatomic, assign) id<BarDelegate> delegate;
+ at property(nonatomic, assign) id<FooDelegate> delegate2; // expected-warning{{property type 'id<FooDelegate>' is incompatible with type 'id<BarDelegate>' inherited from 'Foo'}}
+ at end
+
+ at interface NSData @end
+
+ at interface NSMutableData : NSData @end
+
+ at interface Base : NSData
+ at property(assign) id ref;
+ at property(assign) Base *p_base;
+ at property(assign) NSMutableData *p_data;
+ at end
+
+ at interface Data : Base
+ at property(assign) NSData *ref;
+ at property(assign) Data *p_base;
+ at property(assign) NSData *p_data; // expected-warning{{property type 'NSData *' is incompatible with type 'NSMutableData *' inherited from 'Base'}}
+ at end
More information about the cfe-commits
mailing list