]> granicus.if.org Git - clang/commitdiff
objective-c: Diagnose redeclaration of private
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 21 Oct 2011 18:03:52 +0000 (18:03 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 21 Oct 2011 18:03:52 +0000 (18:03 +0000)
ivars in class extensions. // rdar://10309454

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

lib/Sema/SemaDecl.cpp
test/SemaObjC/ivar-lookup.m

index f554cffba9ba187ce2f0b50c60d2b94f47ce8b34..289ec1a6f6fb22725402e137d59fd3d8ea353825 100644 (file)
@@ -9317,7 +9317,29 @@ void Sema::ActOnFields(Scope* S,
       // FIXME. Class extension does not have a LocEnd field.
       // CDecl->setLocEnd(RBrac);
       // Add ivar's to class extension's DeclContext.
+      // Diagnose redeclaration of private ivars.
+      ObjCInterfaceDecl *IDecl = CDecl->getClassInterface();
       for (unsigned i = 0, e = RecFields.size(); i != e; ++i) {
+        if (IDecl) {
+          if (const ObjCIvarDecl *ClsIvar = 
+              IDecl->getIvarDecl(ClsFields[i]->getIdentifier())) {
+            Diag(ClsFields[i]->getLocation(), 
+                 diag::err_duplicate_ivar_declaration); 
+            Diag(ClsIvar->getLocation(), diag::note_previous_definition);
+            continue;
+          }
+          for (const ObjCCategoryDecl *ClsExtDecl = 
+                IDecl->getFirstClassExtension();
+               ClsExtDecl; ClsExtDecl = ClsExtDecl->getNextClassExtension()) {
+            if (const ObjCIvarDecl *ClsExtIvar = 
+                ClsExtDecl->getIvarDecl(ClsFields[i]->getIdentifier())) {
+              Diag(ClsFields[i]->getLocation(), 
+                   diag::err_duplicate_ivar_declaration); 
+              Diag(ClsExtIvar->getLocation(), diag::note_previous_definition);
+              continue;
+            }
+          }
+        }
         ClsFields[i]->setLexicalDeclContext(CDecl);
         CDecl->addDecl(ClsFields[i]);
       }
index 2b14bff85d841e72f3efe891846cb73215fc03e6..c781a56d76c170f5d10b4d21bf74e933c62a710e 100644 (file)
@@ -47,3 +47,36 @@ extern struct foo x;
   // expected-error{{instance variable 'b' accessed in class method}}
 }
 @end
+
+// rdar://10309454
+@interface Radar10309454
+{
+  int IVAR; // expected-note 4 {{previous definition is here}}
+}
+@end
+
+@interface Radar10309454()
+{
+  int IVAR; // expected-error {{instance variable is already declared}}
+  int PIVAR; // expected-note {{previous definition is here}}
+}
+@end
+
+@interface Radar10309454()
+{
+  int IVAR; // expected-error {{instance variable is already declared}}
+}
+@end
+
+@interface Radar10309454()
+{
+  int IVAR; // expected-error {{instance variable is already declared}}
+  int PIVAR; // expected-error {{instance variable is already declared}}
+}
+@end
+
+@implementation Radar10309454
+{
+  int IVAR; // expected-error {{instance variable is already declared}}
+}
+@end