| 1 |
// RUN: %clang_cc1 -x objective-c -verify -fobjc-arc %s |
| 2 |
|
| 3 |
@interface NSObject |
| 4 |
|
| 5 |
+ (instancetype)new; |
| 6 |
+ (instancetype)alloc; |
| 7 |
|
| 8 |
- (void)declaredInSuper; |
| 9 |
|
| 10 |
@end |
| 11 |
|
| 12 |
@interface NSObject (Category) |
| 13 |
|
| 14 |
- (void)declaredInSuperCategory; |
| 15 |
|
| 16 |
@end |
| 17 |
|
| 18 |
@interface Sub: NSObject |
| 19 |
|
| 20 |
- (instancetype)init __attribute__((unavailable)); // expected-note 4 {{'init' has been explicitly marked unavailable here}} |
| 21 |
|
| 22 |
- (void)notImplemented __attribute__((unavailable)); |
| 23 |
|
| 24 |
- (void)declaredInSuper __attribute__((unavailable)); |
| 25 |
- (void)declaredInSuperCategory __attribute__((unavailable)); |
| 26 |
|
| 27 |
@end |
| 28 |
|
| 29 |
@implementation Sub |
| 30 |
|
| 31 |
+ (Sub *)create { |
| 32 |
return [[self alloc] init]; |
| 33 |
} |
| 34 |
|
| 35 |
+ (Sub *)create2 { |
| 36 |
return [self new]; |
| 37 |
} |
| 38 |
|
| 39 |
+ (Sub *)create3 { |
| 40 |
return [Sub new]; |
| 41 |
} |
| 42 |
|
| 43 |
- (instancetype) init { |
| 44 |
return self; |
| 45 |
} |
| 46 |
|
| 47 |
- (void)reportUseOfUnimplemented { |
| 48 |
[self notImplemented]; |
| 49 |
} |
| 50 |
|
| 51 |
- (void)allowSuperCallUsingSelf { |
| 52 |
[self declaredInSuper]; |
| 53 |
[[Sub alloc] declaredInSuper]; |
| 54 |
[self declaredInSuperCategory]; |
| 55 |
[[Sub alloc] declaredInSuperCategory]; |
| 56 |
} |
| 57 |
|
| 58 |
@end |
| 59 |
|
| 60 |
@interface SubClassContext: Sub |
| 61 |
@end |
| 62 |
|
| 63 |
@implementation SubClassContext |
| 64 |
|
| 65 |
- (void)subClassContext { |
| 66 |
(void)[[Sub alloc] init]; // expected-error {{'init' is unavailable}} |
| 67 |
(void)[Sub new]; // expected-error {{'new' is unavailable}} |
| 68 |
} |
| 69 |
|
| 70 |
@end |
| 71 |
|
| 72 |
void unrelatedContext(void) { |
| 73 |
(void)[[Sub alloc] init]; // expected-error {{'init' is unavailable}} |
| 74 |
(void)[Sub new]; // expected-error {{'new' is unavailable}} |
| 75 |
} |
| 76 |
|
| 77 |
@interface X @end |
| 78 |
|
| 79 |
@interface X (Foo) |
| 80 |
-(void)meth __attribute__((unavailable)); |
| 81 |
@end |
| 82 |
|
| 83 |
@implementation X (Foo) |
| 84 |
-(void)meth {} |
| 85 |
-(void)call_it { [self meth]; } |
| 86 |
@end |