forked from OSchip/llvm-project
ObjectiveC: diagnose duplicate declaration of
private ivars in class extensions and class @implementation. // rdar://14278560 llvm-svn: 185025
This commit is contained in:
parent
ff7fceed7d
commit
e23f26bf94
|
@ -1140,6 +1140,19 @@ void Sema::CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
|
|||
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);
|
||||
|
|
|
@ -111,3 +111,46 @@ extern struct foo x;
|
|||
}
|
||||
@end
|
||||
|
||||
// rdar://14278560
|
||||
@class NSString, NSData, NSNumber;
|
||||
|
||||
@interface NSObject
|
||||
{
|
||||
Class isa;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface Foo
|
||||
{
|
||||
int a;
|
||||
NSString* b;
|
||||
NSData* c;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface Bar : Foo
|
||||
@end
|
||||
|
||||
@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}}
|
||||
}
|
||||
@end
|
||||
|
||||
@interface Bar () {
|
||||
int g; // expected-note {{previous definition is here}} \
|
||||
// expected-error {{instance variable is already declared}}
|
||||
}
|
||||
@end
|
||||
|
||||
@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}}
|
||||
}
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue