зеркало из https://github.com/microsoft/clang.git
Allow shadowin of 'self' in objc methods in
cases where stand-alone ivar can be looked up in shadowed object. To fix gcc compatibility breakage. // rdar://9284603 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129576 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
a391a4642c
Коммит
eefa76e29e
|
@ -2089,11 +2089,21 @@ Sema::LookupInObjCMethod(LookupResult &Lookup, Scope *S,
|
||||||
if (const DeclRefExpr *DE = dyn_cast<DeclRefExpr>(base)) {
|
if (const DeclRefExpr *DE = dyn_cast<DeclRefExpr>(base)) {
|
||||||
const NamedDecl *ND = DE->getDecl();
|
const NamedDecl *ND = DE->getDecl();
|
||||||
if (!isa<ImplicitParamDecl>(ND)) {
|
if (!isa<ImplicitParamDecl>(ND)) {
|
||||||
|
// relax the rule such that it is allowed to have a shadow 'self'
|
||||||
|
// where stand-alone ivar can be found in this 'self' object.
|
||||||
|
// This is to match gcc's behavior.
|
||||||
|
ObjCInterfaceDecl *selfIFace = 0;
|
||||||
|
if (const ObjCObjectPointerType *OPT =
|
||||||
|
base->getType()->getAsObjCInterfacePointerType())
|
||||||
|
selfIFace = OPT->getInterfaceDecl();
|
||||||
|
if (!selfIFace ||
|
||||||
|
!selfIFace->lookupInstanceVariable(IV->getIdentifier())) {
|
||||||
Diag(Loc, diag::error_implicit_ivar_access)
|
Diag(Loc, diag::error_implicit_ivar_access)
|
||||||
<< IV->getDeclName();
|
<< IV->getDeclName();
|
||||||
Diag(ND->getLocation(), diag::note_declared_at);
|
Diag(ND->getLocation(), diag::note_declared_at);
|
||||||
return ExprError();
|
return ExprError();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Owned(new (Context)
|
return Owned(new (Context)
|
||||||
ObjCIvarRefExpr(IV, IV->getType(), Loc,
|
ObjCIvarRefExpr(IV, IV->getType(), Loc,
|
||||||
|
|
|
@ -16,3 +16,36 @@
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
// rdar://9284603
|
||||||
|
@interface ShadowSelf
|
||||||
|
{
|
||||||
|
int _anIvar;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface C {
|
||||||
|
int _cIvar;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation ShadowSelf
|
||||||
|
- (void)doSomething {
|
||||||
|
__typeof(self) newSelf = self;
|
||||||
|
{
|
||||||
|
__typeof(self) self = newSelf;
|
||||||
|
(void)_anIvar;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
C* self; // expected-note {{declared here}}
|
||||||
|
(void) _anIvar; // expected-error {{instance variable '_anIvar' cannot be accessed because 'self' has been redeclared}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
- (void)doAThing {
|
||||||
|
^{
|
||||||
|
id self; // expected-note {{declared here}}
|
||||||
|
(void)_anIvar; // expected-error {{instance variable '_anIvar' cannot be accessed because 'self' has been redeclared}}
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче