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