Alex Lorenz | 4e3c0bd | 2019-01-09 22:31:37 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -x objective-c -verify -fobjc-arc %s |
| 2 | |
| 3 | @interface NSObject |
| 4 | |
| 5 | + (instancetype)new; |
| 6 | + (instancetype)alloc; |
| 7 | |
Alex Lorenz | 194d00e | 2019-01-17 18:12:45 +0000 | [diff] [blame] | 8 | - (void)declaredInSuper; |
| 9 | |
| 10 | @end |
| 11 | |
| 12 | @interface NSObject (Category) |
| 13 | |
| 14 | - (void)declaredInSuperCategory; |
| 15 | |
Alex Lorenz | 4e3c0bd | 2019-01-09 22:31:37 +0000 | [diff] [blame] | 16 | @end |
| 17 | |
| 18 | @interface Sub: NSObject |
| 19 | |
| 20 | - (instancetype)init __attribute__((unavailable)); // expected-note 4 {{'init' has been explicitly marked unavailable here}} |
| 21 | |
Alex Lorenz | 194d00e | 2019-01-17 18:12:45 +0000 | [diff] [blame] | 22 | - (void)notImplemented __attribute__((unavailable)); |
| 23 | |
| 24 | - (void)declaredInSuper __attribute__((unavailable)); |
| 25 | - (void)declaredInSuperCategory __attribute__((unavailable)); |
Alex Lorenz | 4e3c0bd | 2019-01-09 22:31:37 +0000 | [diff] [blame] | 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 { |
Alex Lorenz | 194d00e | 2019-01-17 18:12:45 +0000 | [diff] [blame] | 48 | [self notImplemented]; |
| 49 | } |
| 50 | |
| 51 | - (void)allowSuperCallUsingSelf { |
| 52 | [self declaredInSuper]; |
| 53 | [[Sub alloc] declaredInSuper]; |
| 54 | [self declaredInSuperCategory]; |
| 55 | [[Sub alloc] declaredInSuperCategory]; |
Alex Lorenz | 4e3c0bd | 2019-01-09 22:31:37 +0000 | [diff] [blame] | 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() { |
| 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 |