2017-03-04 02:02:02 +08:00
|
|
|
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.osx.cocoa.DirectIvarAssignment -verify -fblocks %s
|
2012-10-16 06:48:14 +08:00
|
|
|
|
|
|
|
typedef signed char BOOL;
|
|
|
|
@protocol NSObject - (BOOL)isEqual:(id)object; @end
|
|
|
|
@interface NSObject <NSObject> {}
|
|
|
|
+(id)alloc;
|
|
|
|
-(id)init;
|
|
|
|
-(id)autorelease;
|
|
|
|
-(id)copy;
|
|
|
|
-(id)retain;
|
|
|
|
@end
|
2012-09-28 03:45:15 +08:00
|
|
|
|
|
|
|
@interface MyClass;
|
|
|
|
@end
|
2012-10-16 06:48:14 +08:00
|
|
|
@interface TestProperty :NSObject {
|
2012-09-28 03:45:15 +08:00
|
|
|
MyClass *_Z;
|
|
|
|
id _nonSynth;
|
|
|
|
}
|
|
|
|
|
2018-04-06 23:14:32 +08:00
|
|
|
@property (assign, nonatomic) MyClass* A; // explicitly synthesized, not implemented, non-default ivar name
|
2012-09-28 03:45:15 +08:00
|
|
|
|
|
|
|
@property (assign) MyClass* X; // automatically synthesized, not implemented
|
|
|
|
|
|
|
|
@property (assign, nonatomic) MyClass* Y; // automatically synthesized, implemented
|
|
|
|
|
2013-12-05 12:47:09 +08:00
|
|
|
@property (assign, nonatomic) MyClass* Z; // non-synthesized ivar, implemented setter
|
|
|
|
@property (readonly) id nonSynth; // non-synthesized, explicitly implemented to return ivar with expected name
|
2012-09-28 03:45:15 +08:00
|
|
|
|
|
|
|
- (id) initWithPtr:(MyClass*) value;
|
|
|
|
- (id) myInitWithPtr:(MyClass*) value;
|
|
|
|
- (void) someMethod: (MyClass*)In;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TestProperty
|
|
|
|
@synthesize A = __A;
|
|
|
|
|
|
|
|
- (id) initWithPtr: (MyClass*) value {
|
|
|
|
_Y = value; // no-warning
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2012-10-16 06:48:14 +08:00
|
|
|
- (id) copyWithPtrY: (TestProperty*) value {
|
|
|
|
TestProperty *another = [[TestProperty alloc] init];
|
|
|
|
another->_Y = value->_Y; // no-warning
|
|
|
|
return another;
|
|
|
|
}
|
|
|
|
|
2012-09-28 03:45:15 +08:00
|
|
|
- (id) myInitWithPtr: (MyClass*) value {
|
|
|
|
_Y = value; // no-warning
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setY:(MyClass*) NewValue {
|
|
|
|
_Y = NewValue; // no-warning
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setZ:(MyClass*) NewValue {
|
|
|
|
_Z = NewValue; // no-warning
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)nonSynth {
|
|
|
|
return _nonSynth;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) someMethod: (MyClass*)In {
|
2012-09-28 05:57:17 +08:00
|
|
|
(__A) = In; // expected-warning {{Direct assignment to an instance variable backing a property; use the setter instead}}
|
2012-09-28 03:45:15 +08:00
|
|
|
_X = In; // expected-warning {{Direct assignment to an instance variable backing a property; use the setter instead}}
|
|
|
|
_Y = In; // expected-warning {{Direct assignment to an instance variable backing a property; use the setter instead}}
|
|
|
|
_Z = In; // expected-warning {{Direct assignment to an instance variable backing a property; use the setter instead}}
|
|
|
|
_nonSynth = 0; // expected-warning {{Direct assignment to an instance variable backing a property; use the setter instead}}
|
|
|
|
}
|
|
|
|
@end
|