blob: 35f6dac9bf42e006b76b9607312a6e457f1c972a [file] [log] [blame]
Fariborz Jahanian84101132012-09-07 23:46:23 +00001// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
2// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify -Wno-objc-root-class %s
3// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s
4// RUN: %clang_cc1 -x objective-c++ -fobjc-arc -fsyntax-only -verify -Wno-objc-root-class %s
Fariborz Jahanian84101132012-09-07 23:46:23 +00005// rdar://6386358
Fariborz Jahanian6f938602012-09-10 18:04:25 +00006
7#if __has_attribute(objc_requires_super)
8#define NS_REQUIRES_SUPER __attribute((objc_requires_super))
9#endif
10
Fariborz Jahanian84101132012-09-07 23:46:23 +000011@protocol NSObject // expected-note {{protocol is declared here}}
Fariborz Jahanian6f938602012-09-10 18:04:25 +000012- MyDealloc NS_REQUIRES_SUPER; // expected-warning {{'objc_requires_super' attribute cannot be applied to methods in protocols}}
Fariborz Jahanian84101132012-09-07 23:46:23 +000013@end
14
15@interface Root
16- MyDealloc __attribute((objc_requires_super));
17- (void)XXX __attribute((objc_requires_super));
18- (void) dealloc __attribute((objc_requires_super)); // expected-warning {{'objc_requires_super' attribute cannot be applied to dealloc}}
Fariborz Jahanian6f938602012-09-10 18:04:25 +000019- (void) MyDeallocMeth; // Method in root is not annotated.
20- (void) AnnotMyDeallocMeth __attribute((objc_requires_super));
21- (void) AnnotMyDeallocMethCAT NS_REQUIRES_SUPER;
Jordan Rose535a5d02012-10-19 16:05:26 +000022
23+ (void)registerClass:(id)name __attribute((objc_requires_super));
Fariborz Jahanian84101132012-09-07 23:46:23 +000024@end
25
26@interface Baz : Root<NSObject>
27- MyDealloc;
Fariborz Jahanian6f938602012-09-10 18:04:25 +000028- (void) MyDeallocMeth __attribute((objc_requires_super)); // 'Baz' author has annotated method
29- (void) AnnotMyDeallocMeth; // Annotated in root but not here. Annotation is inherited though
30- (void) AnnotMeth __attribute((objc_requires_super)); // 'Baz' author has annotated method
Fariborz Jahanian84101132012-09-07 23:46:23 +000031@end
32
33@implementation Baz
34- MyDealloc {
35 [super MyDealloc];
36 return 0;
37}
38
39- (void)XXX {
40 [super MyDealloc];
Fariborz Jahanian9f559832012-09-10 16:51:09 +000041} // expected-warning {{method possibly missing a [super XXX] call}}
Fariborz Jahanian6f938602012-09-10 18:04:25 +000042
43- (void) MyDeallocMeth {} // No warning here.
44- (void) AnnotMyDeallocMeth{} // expected-warning {{method possibly missing a [super AnnotMyDeallocMeth] call}}
45- (void) AnnotMeth{}; // No warning here. Annotation is in its class.
Jordan Rose535a5d02012-10-19 16:05:26 +000046
47+ (void)registerClass:(id)name {} // expected-warning {{method possibly missing a [super registerClass:] call}}
Fariborz Jahanian84101132012-09-07 23:46:23 +000048@end
49
Fariborz Jahanian6f938602012-09-10 18:04:25 +000050@interface Bar : Baz
51@end
52
53@implementation Bar
54- (void) MyDeallocMeth {} // expected-warning {{method possibly missing a [super MyDeallocMeth] call}}
55- (void) AnnotMyDeallocMeth{} // expected-warning {{method possibly missing a [super AnnotMyDeallocMeth] call}}
56- (void) AnnotMeth{}; // expected-warning {{method possibly missing a [super AnnotMeth] call}}
57@end
58
59@interface Bar(CAT)
60- (void) AnnotMyDeallocMethCAT; // Annotated in root but not here. Annotation is inherited though
61- (void) AnnotMethCAT __attribute((objc_requires_super));
62@end
63
64@implementation Bar(CAT)
65- (void) MyDeallocMeth {} // expected-warning {{method possibly missing a [super MyDeallocMeth] call}}
66- (void) AnnotMyDeallocMeth{} // expected-warning {{method possibly missing a [super AnnotMyDeallocMeth] call}}
67- (void) AnnotMeth{}; // expected-warning {{method possibly missing a [super AnnotMeth] call}}
68- (void) AnnotMyDeallocMethCAT{}; // expected-warning {{method possibly missing a [super AnnotMyDeallocMethCAT] call}}
69- (void) AnnotMethCAT {};
70@end
Jordan Rose535a5d02012-10-19 16:05:26 +000071
72
73@interface Valid : Baz
74@end
75
76@implementation Valid
77
78- (void)MyDeallocMeth {
79 [super MyDeallocMeth]; // no-warning
80}
81
82
83+ (void)registerClass:(id)name {
84 [super registerClass:name]; // no-warning
85}
86
87@end