]> granicus.if.org Git - clang/commitdiff
ObjectiveC: diagnose duplicate declaration of
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 26 Jun 2013 22:10:27 +0000 (22:10 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 26 Jun 2013 22:10:27 +0000 (22:10 +0000)
private ivars in class extensions and class
@implementation. // rdar://14278560

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

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

index 8afff70daa05f5c68f6fbc3df19fa8462110d91c..da98d4c8a0f1ef6b02925b6149a0b835a03b92af 100644 (file)
@@ -1140,6 +1140,19 @@ void Sema::CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
         Diag(ClsIvar->getLocation(), diag::note_previous_definition);
         continue;
       }
+      // Check class extensions (unnamed categories) for duplicate ivars.
+      for (ObjCInterfaceDecl::visible_extensions_iterator
+           Ext = IDecl->visible_extensions_begin(),
+           ExtEnd = IDecl->visible_extensions_end();
+         Ext != ExtEnd; ++Ext) {
+        ObjCCategoryDecl *CDecl = *Ext;
+        if (const ObjCIvarDecl *ClsExtIvar = 
+            CDecl->getIvarDecl(ImplIvar->getIdentifier())) {
+          Diag(ImplIvar->getLocation(), diag::err_duplicate_ivar_declaration); 
+          Diag(ClsExtIvar->getLocation(), diag::note_previous_definition);
+          continue;
+        }
+      }
       // Instance ivar to Implementation's DeclContext.
       ImplIvar->setLexicalDeclContext(ImpDecl);
       IDecl->makeDeclVisibleInContext(ImplIvar);
index a8620caf21edb2c71ad987d4d1a8948460cd9581..938c8eb189a5babd13035620631a174eea43541f 100644 (file)
@@ -111,3 +111,46 @@ extern struct foo x;
 }
 @end
 
+// rdar://14278560
+@class NSString, NSData, NSNumber;
+
+@interface NSObject
+{
+  Class isa;
+}
+@end
+
+@interface Foo
+{
+  int a;
+  NSString* b;
+  NSData* c;
+}
+@end
+
+@interface Bar : Foo
+@end
+
+@interface Bar () {
+       NSString *q_strong;
+       NSNumber *r_strong;
+       int d; // expected-note {{previous definition is here}}
+       NSString *e_strong; // expected-note {{previous definition is here}}
+       NSData *f_weak; // expected-note {{previous definition is here}}
+       int g; // expected-note 2 {{previous definition is here}}
+}
+@end
+
+@interface Bar () {
+       int g; // expected-note {{previous definition is here}} \
+               // expected-error {{instance variable is already declared}}
+}
+@end
+
+@implementation Bar {
+       int d; // expected-error {{instance variable is already declared}}
+       NSString *e_strong; // expected-error {{instance variable is already declared}}
+       NSData *f_weak; // expected-error {{instance variable is already declared}}
+       NSData *g; // expected-error 2 {{instance variable is already declared}}
+}
+@end