From: Fariborz Jahanian Date: Wed, 26 Jun 2013 22:10:27 +0000 (+0000) Subject: ObjectiveC: diagnose duplicate declaration of X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3b20f581de2ddd824ef86114ff65fcf37fe02973;p=clang ObjectiveC: diagnose duplicate declaration of 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 --- diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 8afff70daa..da98d4c8a0 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -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); diff --git a/test/SemaObjC/ivar-lookup.m b/test/SemaObjC/ivar-lookup.m index a8620caf21..938c8eb189 100644 --- a/test/SemaObjC/ivar-lookup.m +++ b/test/SemaObjC/ivar-lookup.m @@ -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