brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 7f2ef52 Raw
72 lines · plain
1// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.osx.cocoa.DirectIvarAssignment -verify -fblocks %s2 3typedef signed char BOOL;4@protocol NSObject  - (BOOL)isEqual:(id)object; @end5@interface NSObject <NSObject> {}6+(id)alloc;7-(id)init;8-(id)autorelease;9-(id)copy;10-(id)retain;11@end12 13@interface MyClass;14@end15@interface TestProperty :NSObject {16  MyClass *_Z;17  id _nonSynth;18}19 20  @property (assign, nonatomic) MyClass* A; // explicitly synthesized, not implemented, non-default ivar name21 22  @property (assign) MyClass* X;  // automatically synthesized, not implemented23 24  @property (assign, nonatomic) MyClass* Y; // automatically synthesized, implemented25 26  @property (assign, nonatomic) MyClass* Z; // non-synthesized ivar, implemented setter27  @property (readonly) id nonSynth;  // non-synthesized, explicitly implemented to return ivar with expected name28  29  - (id) initWithPtr:(MyClass*) value;30  - (id) myInitWithPtr:(MyClass*) value;31  - (void) someMethod: (MyClass*)In;32@end33 34@implementation TestProperty35  @synthesize A = __A;36  37  - (id) initWithPtr: (MyClass*) value {38    _Y = value; // no-warning39    return self;40  }41 42  - (id) copyWithPtrY: (TestProperty*) value {43    TestProperty *another = [[TestProperty alloc] init];44    another->_Y = value->_Y; // no-warning45    return another;46  }47 48  - (id) myInitWithPtr: (MyClass*) value {49    _Y = value; // no-warning50    return self;51  }52  53  - (void) setY:(MyClass*) NewValue {54    _Y = NewValue; // no-warning55  }56 57  - (void) setZ:(MyClass*) NewValue {58    _Z = NewValue; // no-warning59  }60 61  - (id)nonSynth {62      return _nonSynth;63  }64 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}}71  }72@end