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