[cfe-commits] r118689 - in /cfe/trunk: lib/Sema/SemaObjCProperty.cpp test/SemaObjC/duplicate-property-class-extension.m

Fariborz Jahanian fjahanian at apple.com
Wed Nov 10 10:01:36 PST 2010


Author: fjahanian
Date: Wed Nov 10 12:01:36 2010
New Revision: 118689

URL: http://llvm.org/viewvc/llvm-project?rev=118689&view=rev
Log:
Check for duplicate declaration of a property in current and
other class extensions. // rdar://7629420

Modified:
    cfe/trunk/lib/Sema/SemaObjCProperty.cpp
    cfe/trunk/test/SemaObjC/duplicate-property-class-extension.m

Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=118689&r1=118688&r2=118689&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Wed Nov 10 12:01:36 2010
@@ -93,14 +93,22 @@
   // Diagnose if this property is already in continuation class.
   DeclContext *DC = cast<DeclContext>(CDecl);
   IdentifierInfo *PropertyId = FD.D.getIdentifier();
-
-  if (ObjCPropertyDecl *prevDecl =
-        ObjCPropertyDecl::findPropertyDecl(DC, PropertyId)) {
-    Diag(AtLoc, diag::err_duplicate_property);
-    Diag(prevDecl->getLocation(), diag::note_property_declare);
-    return 0;
-  }
-
+  ObjCInterfaceDecl *CCPrimary = CDecl->getClassInterface();
+  
+  if (CCPrimary)
+    // Check for duplicate declaration of this property in current and
+    // other class extensions.
+    for (const ObjCCategoryDecl *ClsExtDecl = 
+         CCPrimary->getFirstClassExtension();
+         ClsExtDecl; ClsExtDecl = ClsExtDecl->getNextClassExtension()) {
+      if (ObjCPropertyDecl *prevDecl =
+          ObjCPropertyDecl::findPropertyDecl(ClsExtDecl, PropertyId)) {
+        Diag(AtLoc, diag::err_duplicate_property);
+        Diag(prevDecl->getLocation(), diag::note_property_declare);
+        return 0;
+      }
+    }
+  
   // Create a new ObjCPropertyDecl with the DeclContext being
   // the class extension.
   ObjCPropertyDecl *PDecl =
@@ -115,7 +123,6 @@
 
   // We need to look in the @interface to see if the @property was
   // already declared.
-  ObjCInterfaceDecl *CCPrimary = CDecl->getClassInterface();
   if (!CCPrimary) {
     Diag(CDecl->getLocation(), diag::err_continuation_class);
     *isOverridingProperty = true;

Modified: cfe/trunk/test/SemaObjC/duplicate-property-class-extension.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/duplicate-property-class-extension.m?rev=118689&r1=118688&r2=118689&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/duplicate-property-class-extension.m (original)
+++ cfe/trunk/test/SemaObjC/duplicate-property-class-extension.m Wed Nov 10 12:01:36 2010
@@ -1,23 +1,24 @@
 // RUN: %clang_cc1  -fsyntax-only -verify %s
+// rdar://7629420
 
 @interface Foo 
- at property (readonly) char foo; // expected-note {{property declared here}}
+ at property (readonly) char foo; 
 @property (readwrite) char bar; // expected-note {{property declared here}}
 @end
 
 @interface Foo ()
- at property (readwrite) char foo; // OK 
+ at property (readwrite) char foo; // expected-note 2 {{property declared here}} 
 @property (readwrite) char NewProperty; // expected-note 2 {{property declared here}} 
 @property (readwrite) char bar; // expected-error{{illegal redeclaration of 'readwrite' property in continuation class 'Foo' (perhaps you intended this to be a 'readwrite' redeclaration of a 'readonly' public property?)}}
 @end
 
 @interface Foo ()
- at property (readwrite) char foo;	//  OK again, make primary property readwrite for 2nd time!
- at property (readwrite) char NewProperty; // expected-error {{redeclaration of property in continuation class 'Foo' (attribute must be 'readwrite', while its primary must be 'readonly')}}
+ at property (readwrite) char foo;	 // expected-error {{property has a previous declaration}}
+ at property (readwrite) char NewProperty; // expected-error {{property has a previous declaration}}
 @end
 
 @interface Foo ()
- at property (readonly) char foo; // expected-error {{redeclaration of property in continuation class 'Foo' (attribute must be 'readwrite', while its primary must be 'readonly')}}
- at property (readwrite) char NewProperty; // expected-error {{redeclaration of property in continuation class 'Foo' (attribute must be 'readwrite', while its primary must be 'readonly')}}
+ at property (readonly) char foo; // expected-error {{property has a previous declaration}}
+ at property (readwrite) char NewProperty; // expected-error {{property has a previous declaration}}
 @end
 





More information about the cfe-commits mailing list