objective-c: Diagnose redeclaration of private

ivars in class extensions. // rdar://10309454

llvm-svn: 142664
This commit is contained in:
Fariborz Jahanian 2011-10-21 18:03:52 +00:00
parent f7a0062869
commit 2512747959
2 changed files with 55 additions and 0 deletions

View 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]);
}

View 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