1*67e74705SXin Li// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -Wdirect-ivar-access -verify -Wno-objc-root-class %s 2*67e74705SXin Li// rdar://6505197 3*67e74705SXin Li 4*67e74705SXin Li__attribute__((objc_root_class)) @interface MyObject { 5*67e74705SXin Li@public 6*67e74705SXin Li id _myMaster; 7*67e74705SXin Li id _isTickledPink; // expected-error {{existing instance variable '_isTickledPink' for property 'isTickledPink'}} 8*67e74705SXin Li int _myIntProp; 9*67e74705SXin Li} 10*67e74705SXin Li@property(retain) id myMaster; 11*67e74705SXin Li@property(assign) id isTickledPink; // expected-note {{property declared here}} 12*67e74705SXin Li@property int myIntProp; 13*67e74705SXin Li@end 14*67e74705SXin Li 15*67e74705SXin Li@implementation MyObject 16*67e74705SXin Li 17*67e74705SXin Li@synthesize myMaster = _myMaster; 18*67e74705SXin Li@synthesize isTickledPink = _isTickledPink; // expected-note {{property synthesized here}} 19*67e74705SXin Li@synthesize myIntProp = _myIntProp; 20*67e74705SXin Li 21*67e74705SXin Li- (void) doSomething { 22*67e74705SXin Li _myMaster = _isTickledPink; // expected-warning {{instance variable '_myMaster' is being directly accessed}} \ 23*67e74705SXin Li // expected-warning {{instance variable '_isTickledPink' is being directly accessed}} 24*67e74705SXin Li} 25*67e74705SXin Li 26*67e74705SXin Li- (id) init { 27*67e74705SXin Li _myMaster=0; 28*67e74705SXin Li return _myMaster; 29*67e74705SXin Li} 30*67e74705SXin Li- (void) dealloc { _myMaster = 0; } 31*67e74705SXin Li@end 32*67e74705SXin Li 33*67e74705SXin LiMyObject * foo () 34*67e74705SXin Li{ 35*67e74705SXin Li MyObject* p=0; 36*67e74705SXin Li p.isTickledPink = p.myMaster; // ok 37*67e74705SXin Li p->_isTickledPink = (*p)._myMaster; // expected-warning {{instance variable '_isTickledPink' is being directly accessed}} \ 38*67e74705SXin Li // expected-warning {{instance variable '_myMaster' is being directly accessed}} 39*67e74705SXin Li if (p->_myIntProp) // expected-warning {{instance variable '_myIntProp' is being directly accessed}} 40*67e74705SXin Li p->_myIntProp = 0; // expected-warning {{instance variable '_myIntProp' is being directly accessed}} 41*67e74705SXin Li return p->_isTickledPink; // expected-warning {{instance variable '_isTickledPink' is being directly accessed}} 42*67e74705SXin Li} 43*67e74705SXin Li 44*67e74705SXin Li@interface ITest32 { 45*67e74705SXin Li@public 46*67e74705SXin Li id ivar; 47*67e74705SXin Li} 48*67e74705SXin Li@end 49*67e74705SXin Li 50*67e74705SXin Liid Test32(__weak ITest32 *x) { 51*67e74705SXin Li __weak ITest32 *y; 52*67e74705SXin Li x->ivar = 0; // expected-error {{dereferencing a __weak pointer is not allowed}} 53*67e74705SXin Li return y ? y->ivar // expected-error {{dereferencing a __weak pointer is not allowed}} 54*67e74705SXin Li : (*x).ivar; // expected-error {{dereferencing a __weak pointer is not allowed}} 55*67e74705SXin Li} 56*67e74705SXin Li 57*67e74705SXin Li// rdar://13142820 58*67e74705SXin Li@protocol PROTOCOL 59*67e74705SXin Li@property (copy, nonatomic) id property_in_protocol; 60*67e74705SXin Li@end 61*67e74705SXin Li 62*67e74705SXin Li__attribute__((objc_root_class)) @interface INTF <PROTOCOL> 63*67e74705SXin Li@property (copy, nonatomic) id foo; 64*67e74705SXin Li- (id) foo; 65*67e74705SXin Li@end 66*67e74705SXin Li 67*67e74705SXin Li@interface INTF() 68*67e74705SXin Li@property (copy, nonatomic) id foo1; 69*67e74705SXin Li- (id) foo1; 70*67e74705SXin Li@end 71*67e74705SXin Li 72*67e74705SXin Li@implementation INTF 73*67e74705SXin Li- (id) foo { return _foo; } 74*67e74705SXin Li- (id) property_in_protocol { return _property_in_protocol; } // expected-warning {{instance variable '_property_in_protocol' is being directly accessed}} 75*67e74705SXin Li- (id) foo1 { return _foo1; } 76*67e74705SXin Li@synthesize property_in_protocol = _property_in_protocol; 77*67e74705SXin Li@end 78*67e74705SXin Li 79