aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2011-10-21 18:03:52 +0000
committerFariborz Jahanian <fjahanian@apple.com>2011-10-21 18:03:52 +0000
commit3ff86f79090a1f9317b2d9ac1a95a696701feb71 (patch)
treea88d6a2b19c5c59ad536f4b2c8b90eb16ba5b044
parent381509ea9965ab6bde9b36b4131ad08bf851d9b4 (diff)
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
-rw-r--r--lib/Sema/SemaDecl.cpp22
-rw-r--r--test/SemaObjC/ivar-lookup.m33
2 files changed, 55 insertions, 0 deletions
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