r201446 - [Objective-C Sema]. Warn when an indirectly overridden property

Fariborz Jahanian fjahanian at apple.com
Fri Feb 14 16:04:36 PST 2014


Author: fjahanian
Date: Fri Feb 14 18:04:36 2014
New Revision: 201446

URL: http://llvm.org/viewvc/llvm-project?rev=201446&view=rev
Log:
[Objective-C Sema]. Warn when an indirectly overridden property
mismatches the one declared in current class; in addition to
those that are directly overridden. 
// rdar://15967517

Modified:
    cfe/trunk/lib/Sema/SemaObjCProperty.cpp
    cfe/trunk/test/SemaObjC/property-inherited.m

Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=201446&r1=201445&r2=201446&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Fri Feb 14 18:04:36 2014
@@ -204,7 +204,8 @@ Decl *Sema::ActOnProperty(Scope *S, Sour
   if (ObjCInterfaceDecl *IFace = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) {
     // For a class, compare the property against a property in our superclass.
     bool FoundInSuper = false;
-    if (ObjCInterfaceDecl *Super = IFace->getSuperClass()) {
+    ObjCInterfaceDecl *CurrentInterfaceDecl = IFace;
+    while (ObjCInterfaceDecl *Super = CurrentInterfaceDecl->getSuperClass()) {
       DeclContext::lookup_result R = Super->lookup(Res->getDeclName());
       for (unsigned I = 0, N = R.size(); I != N; ++I) {
         if (ObjCPropertyDecl *SuperProp = dyn_cast<ObjCPropertyDecl>(R[I])) {
@@ -213,12 +214,17 @@ Decl *Sema::ActOnProperty(Scope *S, Sour
           break;
         }
       }
+      if (FoundInSuper)
+        break;
+      else
+        CurrentInterfaceDecl = Super;
     }
 
     if (FoundInSuper) {
       // Also compare the property against a property in our protocols.
-      for (ObjCInterfaceDecl::protocol_iterator P = IFace->protocol_begin(),
-                                             PEnd = IFace->protocol_end();
+      for (ObjCInterfaceDecl::protocol_iterator
+            P = CurrentInterfaceDecl->protocol_begin(),
+            PEnd = CurrentInterfaceDecl->protocol_end();
            P != PEnd; ++P) {
         CheckPropertyAgainstProtocol(*this, Res, *P, KnownProtos);
       }

Modified: cfe/trunk/test/SemaObjC/property-inherited.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-inherited.m?rev=201446&r1=201445&r2=201446&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/property-inherited.m (original)
+++ cfe/trunk/test/SemaObjC/property-inherited.m Fri Feb 14 18:04:36 2014
@@ -44,3 +44,29 @@
 @property(assign) Data *p_base;	
 @property(assign) NSData *p_data;	// expected-warning{{property type 'NSData *' is incompatible with type 'NSMutableData *' inherited from 'Base'}}
 @end
+
+// rdar://15967517
+ at protocol P1
+ at property (nonatomic) void* selected;
+ at end
+
+ at protocol P2
+ at property (nonatomic) void* selected; // expected-note {{property declared here}}
+ at end
+
+ at interface MKAnnotationView <P1>
+ at property (nonatomic) void* selected; // expected-note {{property declared here}}
+ at property (nonatomic) char selected2;
+ at end
+
+ at interface Parent : MKAnnotationView <P2>
+ at property (nonatomic) void* selected1; // expected-note {{property declared here}}
+ at property (nonatomic) char selected2;
+ at end
+
+ at interface Child : Parent
+ at property (nonatomic) char selected; // expected-warning {{property type 'char' is incompatible with type 'void *' inherited from 'MKAnnotationView'}} \
+				     // expected-warning {{property type 'char' is incompatible with type 'void *' inherited from 'P2'}}
+ at property (nonatomic) char selected1; // expected-warning {{property type 'char' is incompatible with type 'void *' inherited from 'Parent'}}
+ at property (nonatomic) char selected2;
+ at end





More information about the cfe-commits mailing list