forked from OSchip/llvm-project
objc/c++: Issue diagnostic when free-standing ivar is accessed
in class method instead of crash. // rdar://10593227 llvm-svn: 146998
This commit is contained in:
parent
b95c102c2f
commit
028b9e1d0a
|
@ -2010,6 +2010,12 @@ Sema::LookupInObjCMethod(LookupResult &Lookup, Scope *S,
|
|||
Diag(Loc, diag::warn_ivar_use_hidden) << IV->getDeclName();
|
||||
}
|
||||
}
|
||||
} else if (Lookup.isSingleResult() &&
|
||||
Lookup.getFoundDecl()->isDefinedOutsideFunctionOrMethod()) {
|
||||
// If accessing a stand-alone ivar in a class method, this is an error.
|
||||
if (const ObjCIvarDecl *IV = dyn_cast<ObjCIvarDecl>(Lookup.getFoundDecl()))
|
||||
return ExprError(Diag(Loc, diag::error_ivar_use_in_class_method)
|
||||
<< IV->getDeclName());
|
||||
}
|
||||
|
||||
if (Lookup.empty() && II && AllowBuiltinCreation) {
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
// RUN: %clang_cc1 -x objective-c -fsyntax-only -verify %s
|
||||
// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify %s
|
||||
// rdar://10593227
|
||||
|
||||
@class UIWindow;
|
||||
|
||||
@interface CNAppDelegate
|
||||
|
||||
@property (strong, nonatomic) UIWindow *window;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface CNAppDelegate ()
|
||||
@property (nonatomic,retain) id foo;
|
||||
@end
|
||||
|
||||
@implementation CNAppDelegate
|
||||
@synthesize foo;
|
||||
@synthesize window = _window;
|
||||
|
||||
+(void)myClassMethod;
|
||||
{
|
||||
foo = 0; // expected-error {{instance variable 'foo' accessed in class method}}
|
||||
}
|
||||
@end
|
Loading…
Reference in New Issue