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