File: objc-super-self.m

package info (click to toggle)
llvm-toolchain-11 1%3A11.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 995,808 kB
  • sloc: cpp: 4,767,656; ansic: 760,916; asm: 477,436; python: 170,940; objc: 69,804; lisp: 29,914; sh: 23,855; f90: 18,173; pascal: 7,551; perl: 7,471; ml: 5,603; awk: 3,489; makefile: 2,573; xml: 915; cs: 573; fortran: 503; javascript: 452
file content (86 lines) | stat: -rw-r--r-- 2,388 bytes parent folder | download | duplicates (23)
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