]> granicus.if.org Git - clang/commitdiff
Check for duplicate declaration of a property in current and
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 10 Nov 2010 18:01:36 +0000 (18:01 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 10 Nov 2010 18:01:36 +0000 (18:01 +0000)
other class extensions. // rdar://7629420

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118689 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaObjCProperty.cpp
test/SemaObjC/duplicate-property-class-extension.m

index 37f9db1e5be765a95d32739e817b8a6756a3468a..e1c0f4af99e928dfa4af82d5292deada213cc729 100644 (file)
@@ -93,14 +93,22 @@ Sema::HandlePropertyInClassExtension(Scope *S, ObjCCategoryDecl *CDecl,
   // 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 @@ Sema::HandlePropertyInClassExtension(Scope *S, ObjCCategoryDecl *CDecl,
 
   // 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;
index e8a2389bbc0201cc0eef2930c2005e5107f60c46..bf48ed61d863b5c198713b8ac6d25122eea72dfd 100644 (file)
@@ -1,23 +1,24 @@
 // RUN: %clang_cc1  -fsyntax-only -verify %s
+// rdar://7629420
 
 @interface Foo 
-@property (readonly) char foo; // expected-note {{property declared here}}
+@property (readonly) char foo; 
 @property (readwrite) char bar; // expected-note {{property declared here}}
 @end
 
 @interface Foo ()
-@property (readwrite) char foo; // OK 
+@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 ()
-@property (readwrite) char foo;        //  OK again, make primary property readwrite for 2nd time!
-@property (readwrite) char NewProperty; // expected-error {{redeclaration of property in continuation class 'Foo' (attribute must be 'readwrite', while its primary must be 'readonly')}}
+@property (readwrite) char foo;         // expected-error {{property has a previous declaration}}
+@property (readwrite) char NewProperty; // expected-error {{property has a previous declaration}}
 @end
 
 @interface Foo ()
-@property (readonly) char foo; // expected-error {{redeclaration of property in continuation class 'Foo' (attribute must be 'readwrite', while its primary must be 'readonly')}}
-@property (readwrite) char NewProperty; // expected-error {{redeclaration of property in continuation class 'Foo' (attribute must be 'readwrite', while its primary must be 'readonly')}}
+@property (readonly) char foo; // expected-error {{property has a previous declaration}}
+@property (readwrite) char NewProperty; // expected-error {{property has a previous declaration}}
 @end