1 // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.osx.cocoa.DirectIvarAssignment -verify -fblocks %s
3 typedef signed char BOOL;
4 @protocol NSObject - (BOOL)isEqual:(id)object; @end
5 @interface NSObject <NSObject> {}
15 @interface TestProperty :NSObject {
20 @property (assign, nonatomic) MyClass* A; // explicitly synthesized, not implemented, non-default ivar name
22 @property (assign) MyClass* X; // automatically synthesized, not implemented
24 @property (assign, nonatomic) MyClass* Y; // automatically synthesized, implemented
26 @property (assign, nonatomic) MyClass* Z; // non-synthesized ivar, implemented setter
27 @property (readonly) id nonSynth; // non-synthesized, explicitly implemented to return ivar with expected name
29 - (id) initWithPtr:(MyClass*) value;
30 - (id) myInitWithPtr:(MyClass*) value;
31 - (void) someMethod: (MyClass*)In;
34 @implementation TestProperty
37 - (id) initWithPtr: (MyClass*) value {
38 _Y = value; // no-warning
42 - (id) copyWithPtrY: (TestProperty*) value {
43 TestProperty *another = [[TestProperty alloc] init];
44 another->_Y = value->_Y; // no-warning
48 - (id) myInitWithPtr: (MyClass*) value {
49 _Y = value; // no-warning
53 - (void) setY:(MyClass*) NewValue {
54 _Y = NewValue; // no-warning
57 - (void) setZ:(MyClass*) NewValue {
58 _Z = NewValue; // no-warning
65 - (void) someMethod: (MyClass*)In {
66 (__A) = In; // expected-warning {{Direct assignment to an instance variable backing a property; use the setter instead}}
67 _X = In; // expected-warning {{Direct assignment to an instance variable backing a property; use the setter instead}}
68 _Y = In; // expected-warning {{Direct assignment to an instance variable backing a property; use the setter instead}}
69 _Z = In; // expected-warning {{Direct assignment to an instance variable backing a property; use the setter instead}}
70 _nonSynth = 0; // expected-warning {{Direct assignment to an instance variable backing a property; use the setter instead}}