From: Fariborz Jahanian Date: Fri, 21 Oct 2011 18:03:52 +0000 (+0000) Subject: objective-c: Diagnose redeclaration of private X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3ff86f79090a1f9317b2d9ac1a95a696701feb71;p=clang objective-c: Diagnose redeclaration of private ivars in class extensions. // rdar://10309454 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142664 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index f554cffba9..289ec1a6f6 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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]); } diff --git a/test/SemaObjC/ivar-lookup.m b/test/SemaObjC/ivar-lookup.m index 2b14bff85d..c781a56d76 100644 --- a/test/SemaObjC/ivar-lookup.m +++ b/test/SemaObjC/ivar-lookup.m @@ -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