xref: /aosp_15_r20/external/clang/test/SemaObjC/super-dealloc-attribute.m (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li// RUN: %clang_cc1  -fsyntax-only -verify -Wno-objc-root-class %s
2*67e74705SXin Li// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify -Wno-objc-root-class %s
3*67e74705SXin Li// RUN: %clang_cc1  -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s
4*67e74705SXin Li// RUN: %clang_cc1 -x objective-c++ -fobjc-arc -fsyntax-only -verify -Wno-objc-root-class %s
5*67e74705SXin Li// rdar://6386358
6*67e74705SXin Li
7*67e74705SXin Li#if __has_attribute(objc_requires_super)
8*67e74705SXin Li#define  NS_REQUIRES_SUPER __attribute((objc_requires_super))
9*67e74705SXin Li#endif
10*67e74705SXin Li
11*67e74705SXin Li@protocol NSObject // expected-note {{protocol is declared here}}
12*67e74705SXin Li- MyDealloc NS_REQUIRES_SUPER; // expected-warning {{'objc_requires_super' attribute cannot be applied to methods in protocols}}
13*67e74705SXin Li@end
14*67e74705SXin Li
15*67e74705SXin Li@interface Root
16*67e74705SXin Li- MyDealloc __attribute((objc_requires_super));
17*67e74705SXin Li- (void)XXX __attribute((objc_requires_super));
18*67e74705SXin Li- (void) dealloc __attribute((objc_requires_super)); // expected-warning {{'objc_requires_super' attribute cannot be applied to dealloc}}
19*67e74705SXin Li- (void) MyDeallocMeth; // Method in root is not annotated.
20*67e74705SXin Li- (void) AnnotMyDeallocMeth __attribute((objc_requires_super));
21*67e74705SXin Li- (void) AnnotMyDeallocMethCAT NS_REQUIRES_SUPER;
22*67e74705SXin Li
23*67e74705SXin Li+ (void)registerClass:(id)name __attribute((objc_requires_super));
24*67e74705SXin Li@end
25*67e74705SXin Li
26*67e74705SXin Li@interface Baz : Root<NSObject>
27*67e74705SXin Li- MyDealloc;
28*67e74705SXin Li- (void) MyDeallocMeth __attribute((objc_requires_super)); // 'Baz' author has annotated method
29*67e74705SXin Li- (void) AnnotMyDeallocMeth; // Annotated in root but not here. Annotation is inherited though
30*67e74705SXin Li- (void) AnnotMeth __attribute((objc_requires_super)); // 'Baz' author has annotated method
31*67e74705SXin Li@end
32*67e74705SXin Li
33*67e74705SXin Li@implementation Baz
34*67e74705SXin Li-  MyDealloc {
35*67e74705SXin Li   [super MyDealloc];
36*67e74705SXin Li        return 0;
37*67e74705SXin Li}
38*67e74705SXin Li
39*67e74705SXin Li- (void)XXX {
40*67e74705SXin Li  [super MyDealloc];
41*67e74705SXin Li} // expected-warning {{method possibly missing a [super XXX] call}}
42*67e74705SXin Li
43*67e74705SXin Li- (void) MyDeallocMeth {}
44*67e74705SXin Li- (void) AnnotMyDeallocMeth{} // expected-warning {{method possibly missing a [super AnnotMyDeallocMeth] call}}
45*67e74705SXin Li- (void) AnnotMeth{};
46*67e74705SXin Li
47*67e74705SXin Li+ (void)registerClass:(id)name {} // expected-warning {{method possibly missing a [super registerClass:] call}}
48*67e74705SXin Li@end
49*67e74705SXin Li
50*67e74705SXin Li@interface Bar : Baz
51*67e74705SXin Li@end
52*67e74705SXin Li
53*67e74705SXin Li@implementation Bar
54*67e74705SXin Li- (void) MyDeallocMeth {} // expected-warning {{method possibly missing a [super MyDeallocMeth] call}}
55*67e74705SXin Li- (void) AnnotMyDeallocMeth{} // expected-warning {{method possibly missing a [super AnnotMyDeallocMeth] call}}
56*67e74705SXin Li- (void) AnnotMeth{};  // expected-warning {{method possibly missing a [super AnnotMeth] call}}
57*67e74705SXin Li@end
58*67e74705SXin Li
59*67e74705SXin Li@interface Bar(CAT)
60*67e74705SXin Li- (void) AnnotMyDeallocMethCAT; // Annotated in root but not here. Annotation is inherited though
61*67e74705SXin Li- (void) AnnotMethCAT __attribute((objc_requires_super));
62*67e74705SXin Li@end
63*67e74705SXin Li
64*67e74705SXin Li@implementation Bar(CAT)
65*67e74705SXin Li- (void) MyDeallocMeth {} // expected-warning {{method possibly missing a [super MyDeallocMeth] call}}
66*67e74705SXin Li- (void) AnnotMyDeallocMeth{} // expected-warning {{method possibly missing a [super AnnotMyDeallocMeth] call}}
67*67e74705SXin Li- (void) AnnotMeth{};  // expected-warning {{method possibly missing a [super AnnotMeth] call}}
68*67e74705SXin Li- (void) AnnotMyDeallocMethCAT{}; // expected-warning {{method possibly missing a [super AnnotMyDeallocMethCAT] call}}
69*67e74705SXin Li- (void) AnnotMethCAT {};
70*67e74705SXin Li@end
71*67e74705SXin Li
72*67e74705SXin Li
73*67e74705SXin Li@interface Valid : Baz
74*67e74705SXin Li@end
75*67e74705SXin Li
76*67e74705SXin Li@implementation Valid
77*67e74705SXin Li
78*67e74705SXin Li- (void)MyDeallocMeth {
79*67e74705SXin Li  [super MyDeallocMeth]; // no-warning
80*67e74705SXin Li}
81*67e74705SXin Li
82*67e74705SXin Li
83*67e74705SXin Li+ (void)registerClass:(id)name {
84*67e74705SXin Li  [super registerClass:name]; // no-warning
85*67e74705SXin Li}
86*67e74705SXin Li
87*67e74705SXin Li@end
88*67e74705SXin Li
89*67e74705SXin Li// rdar://14251387
90*67e74705SXin Li#define IBAction void)__attribute__((ibaction)
91*67e74705SXin Li
92*67e74705SXin Li@interface UIViewController @end
93*67e74705SXin Li
94*67e74705SXin Li@interface ViewController : UIViewController
95*67e74705SXin Li- (void) someMethodRequiringSuper NS_REQUIRES_SUPER;
96*67e74705SXin Li- (IBAction) someAction;
97*67e74705SXin Li- (IBAction) someActionRequiringSuper NS_REQUIRES_SUPER;
98*67e74705SXin Li@end
99*67e74705SXin Li
100*67e74705SXin Li
101*67e74705SXin Li@implementation ViewController
102*67e74705SXin Li- (void) someMethodRequiringSuper
103*67e74705SXin Li{
104*67e74705SXin Li}
105*67e74705SXin Li- (IBAction) someAction
106*67e74705SXin Li{
107*67e74705SXin Li}
108*67e74705SXin Li- (IBAction) someActionRequiringSuper
109*67e74705SXin Li{
110*67e74705SXin Li}
111*67e74705SXin Li@end
112*67e74705SXin Li
113*67e74705SXin Li// rdar://15385981
114*67e74705SXin Li@interface Barn
115*67e74705SXin Li- (void)openDoor __attribute__((objc_requires_super));
116*67e74705SXin Li@end
117*67e74705SXin Li
118*67e74705SXin Li@implementation Barn
119*67e74705SXin Li- (void) openDoor
120*67e74705SXin Li{
121*67e74705SXin Li    ;
122*67e74705SXin Li}
123*67e74705SXin Li@end
124*67e74705SXin Li
125*67e74705SXin Li@interface HorseBarn:Barn @end
126*67e74705SXin Li
127*67e74705SXin Li@implementation HorseBarn
128*67e74705SXin Li- (void) openDoor
129*67e74705SXin Li{
130*67e74705SXin Li    ;
131*67e74705SXin Li}	// expected-warning {{method possibly missing a [super openDoor] call}}
132*67e74705SXin Li@end
133