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