1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
// RUN: %check_clang_tidy %s objc-super-self %t
@interface NSObject
- (instancetype)init;
- (instancetype)self;
@end
@interface NSObjectDerivedClass : NSObject
@end
@implementation NSObjectDerivedClass
- (instancetype)init {
return [super self];
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious invocation of 'self' in initializer; did you mean to invoke a superclass initializer? [objc-super-self]
// CHECK-FIXES: return [super init];
}
- (instancetype)initWithObject:(NSObject *)obj {
self = [super self];
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious invocation of 'self' in initializer; did you mean to invoke a superclass initializer? [objc-super-self]
// CHECK-FIXES: self = [super init];
if (self) {
// ...
}
return self;
}
#define INITIALIZE() [super self]
- (instancetype)initWithObject:(NSObject *)objc a:(int)a {
return INITIALIZE();
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious invocation of 'self' in initializer; did you mean to invoke a superclass initializer? [objc-super-self]
// CHECK-FIXES: return INITIALIZE();
}
#define INITIALIZER_IMPL() return [super self]
- (instancetype)initWithObject:(NSObject *)objc b:(int)b {
INITIALIZER_IMPL();
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: suspicious invocation of 'self' in initializer; did you mean to invoke a superclass initializer? [objc-super-self]
// CHECK-FIXES: INITIALIZER_IMPL();
}
#define INITIALIZER_METHOD self
- (instancetype)initWithObject:(NSObject *)objc c:(int)c {
return [super INITIALIZER_METHOD];
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious invocation of 'self' in initializer; did you mean to invoke a superclass initializer? [objc-super-self]
// CHECK-FIXES: return [super INITIALIZER_METHOD];
}
#define RECEIVER super
- (instancetype)initWithObject:(NSObject *)objc d:(int)d {
return [RECEIVER self];
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious invocation of 'self' in initializer; did you mean to invoke a superclass initializer? [objc-super-self]
// CHECK-FIXES: return [RECEIVER self];
}
- (instancetype)foo {
return [super self];
}
- (instancetype)bar {
return [self self];
}
@end
@interface RootClass
- (instancetype)init;
- (instancetype)self;
@end
@interface NotNSObjectDerivedClass : RootClass
@end
@implementation NotNSObjectDerivedClass
- (instancetype)init {
return [super self];
}
@end
|