File: super-self.m

package info (click to toggle)
llvm-toolchain-17 1%3A17.0.6-22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,799,624 kB
  • sloc: cpp: 6,428,607; ansic: 1,383,196; asm: 793,408; python: 223,504; objc: 75,364; f90: 60,502; lisp: 33,869; pascal: 15,282; sh: 9,684; perl: 7,453; ml: 4,937; awk: 3,523; makefile: 2,889; javascript: 2,149; xml: 888; fortran: 619; cs: 573
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