diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2011-10-21 18:03:52 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2011-10-21 18:03:52 +0000 |
commit | 251274795944e169e89b5483dd32f6382550616e (patch) | |
tree | 583e6478fea378004606f5a39384466d6c285853 /clang | |
parent | f7a006286905f8daca7aa96d086b448ea2f55f32 (diff) | |
download | bcm5719-llvm-251274795944e169e89b5483dd32f6382550616e.tar.gz bcm5719-llvm-251274795944e169e89b5483dd32f6382550616e.zip |
objective-c: Diagnose redeclaration of private
ivars in class extensions. // rdar://10309454
llvm-svn: 142664
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 22 | ||||
-rw-r--r-- | clang/test/SemaObjC/ivar-lookup.m | 33 |
2 files changed, 55 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index f554cffba9b..289ec1a6f6f 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/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/clang/test/SemaObjC/ivar-lookup.m b/clang/test/SemaObjC/ivar-lookup.m index 2b14bff85d8..c781a56d76c 100644 --- a/clang/test/SemaObjC/ivar-lookup.m +++ b/clang/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 |