r185025 - ObjectiveC: diagnose duplicate declaration of
Fariborz Jahanian
fjahanian at apple.com
Wed Jun 26 15:10:28 PDT 2013
Author: fjahanian
Date: Wed Jun 26 17:10:27 2013
New Revision: 185025
URL: http://llvm.org/viewvc/llvm-project?rev=185025&view=rev
Log:
ObjectiveC: diagnose duplicate declaration of
private ivars in class extensions and class
@implementation. // rdar://14278560
Modified:
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/SemaObjC/ivar-lookup.m
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=185025&r1=185024&r2=185025&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Wed Jun 26 17:10:27 2013
@@ -1140,6 +1140,19 @@ void Sema::CheckImplementationIvars(ObjC
Diag(ClsIvar->getLocation(), diag::note_previous_definition);
continue;
}
+ // Check class extensions (unnamed categories) for duplicate ivars.
+ for (ObjCInterfaceDecl::visible_extensions_iterator
+ Ext = IDecl->visible_extensions_begin(),
+ ExtEnd = IDecl->visible_extensions_end();
+ Ext != ExtEnd; ++Ext) {
+ ObjCCategoryDecl *CDecl = *Ext;
+ if (const ObjCIvarDecl *ClsExtIvar =
+ CDecl->getIvarDecl(ImplIvar->getIdentifier())) {
+ Diag(ImplIvar->getLocation(), diag::err_duplicate_ivar_declaration);
+ Diag(ClsExtIvar->getLocation(), diag::note_previous_definition);
+ continue;
+ }
+ }
// Instance ivar to Implementation's DeclContext.
ImplIvar->setLexicalDeclContext(ImpDecl);
IDecl->makeDeclVisibleInContext(ImplIvar);
Modified: cfe/trunk/test/SemaObjC/ivar-lookup.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/ivar-lookup.m?rev=185025&r1=185024&r2=185025&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/ivar-lookup.m (original)
+++ cfe/trunk/test/SemaObjC/ivar-lookup.m Wed Jun 26 17:10:27 2013
@@ -111,3 +111,46 @@ extern struct foo x;
}
@end
+// rdar://14278560
+ at class NSString, NSData, NSNumber;
+
+ at interface NSObject
+{
+ Class isa;
+}
+ at end
+
+ at interface Foo
+{
+ int a;
+ NSString* b;
+ NSData* c;
+}
+ at end
+
+ at interface Bar : Foo
+ at end
+
+ at interface Bar () {
+ NSString *q_strong;
+ NSNumber *r_strong;
+ int d; // expected-note {{previous definition is here}}
+ NSString *e_strong; // expected-note {{previous definition is here}}
+ NSData *f_weak; // expected-note {{previous definition is here}}
+ int g; // expected-note 2 {{previous definition is here}}
+}
+ at end
+
+ at interface Bar () {
+ int g; // expected-note {{previous definition is here}} \
+ // expected-error {{instance variable is already declared}}
+}
+ at end
+
+ at implementation Bar {
+ int d; // expected-error {{instance variable is already declared}}
+ NSString *e_strong; // expected-error {{instance variable is already declared}}
+ NSData *f_weak; // expected-error {{instance variable is already declared}}
+ NSData *g; // expected-error 2 {{instance variable is already declared}}
+}
+ at end
More information about the cfe-commits
mailing list