[cfe-commits] r142664 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaObjC/ivar-lookup.m
Fariborz Jahanian
fjahanian at apple.com
Fri Oct 21 11:03:53 PDT 2011
Author: fjahanian
Date: Fri Oct 21 13:03:52 2011
New Revision: 142664
URL: http://llvm.org/viewvc/llvm-project?rev=142664&view=rev
Log:
objective-c: Diagnose redeclaration of private
ivars in class extensions. // rdar://10309454
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaObjC/ivar-lookup.m
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=142664&r1=142663&r2=142664&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Oct 21 13:03:52 2011
@@ -9317,7 +9317,29 @@
// 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]);
}
Modified: cfe/trunk/test/SemaObjC/ivar-lookup.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/ivar-lookup.m?rev=142664&r1=142663&r2=142664&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/ivar-lookup.m (original)
+++ cfe/trunk/test/SemaObjC/ivar-lookup.m Fri Oct 21 13:03:52 2011
@@ -47,3 +47,36 @@
// expected-error{{instance variable 'b' accessed in class method}}
}
@end
+
+// rdar://10309454
+ at interface Radar10309454
+{
+ int IVAR; // expected-note 4 {{previous definition is here}}
+}
+ at end
+
+ at interface Radar10309454()
+{
+ int IVAR; // expected-error {{instance variable is already declared}}
+ int PIVAR; // expected-note {{previous definition is here}}
+}
+ at end
+
+ at interface Radar10309454()
+{
+ int IVAR; // expected-error {{instance variable is already declared}}
+}
+ at end
+
+ at interface Radar10309454()
+{
+ int IVAR; // expected-error {{instance variable is already declared}}
+ int PIVAR; // expected-error {{instance variable is already declared}}
+}
+ at end
+
+ at implementation Radar10309454
+{
+ int IVAR; // expected-error {{instance variable is already declared}}
+}
+ at end
More information about the cfe-commits
mailing list