Erik Pilkington | 4257857 | 2018-09-10 22:20:09 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-apple-macosx-10.9 -Wunguarded-availability -fblocks -fsyntax-only -verify %s |
| 2 | |
| 3 | __attribute__((objc_root_class)) |
| 4 | @interface NSObject |
| 5 | +(instancetype)new; |
| 6 | -(instancetype)init; |
| 7 | @end |
| 8 | |
| 9 | @interface MyObject : NSObject |
| 10 | -(instancetype)init __attribute__((unavailable)); // expected-note{{'init' has been explicitly marked unavailable here}} |
| 11 | @end |
| 12 | |
| 13 | void usemyobject() { |
| 14 | [MyObject new]; // expected-error{{'new' is unavailable}} |
| 15 | } |
| 16 | |
| 17 | @interface MyOtherObject : NSObject |
| 18 | +(instancetype)init __attribute__((unavailable)); |
| 19 | +(instancetype)new; |
| 20 | @end |
| 21 | |
| 22 | void usemyotherobject() { |
| 23 | [MyOtherObject new]; // no error; new is overrideen. |
| 24 | } |
| 25 | |
| 26 | @interface NotGoodOverride : NSObject |
| 27 | +(instancetype)init __attribute__((unavailable)); |
| 28 | -(instancetype)new; |
| 29 | +(instancetype)new: (int)x; |
| 30 | @end |
| 31 | |
| 32 | void usenotgoodoverride() { |
| 33 | [NotGoodOverride new]; // no error |
| 34 | } |
| 35 | |
| 36 | @interface NotNSObject |
| 37 | +(instancetype)new; |
| 38 | -(instancetype)init; |
| 39 | @end |
| 40 | |
| 41 | @interface NotMyObject : NotNSObject |
| 42 | -(instancetype)init __attribute__((unavailable)); |
| 43 | @end |
| 44 | |
| 45 | void usenotmyobject() { |
| 46 | [NotMyObject new]; // no error; this isn't NSObject |
| 47 | } |
| 48 | |
| 49 | @interface FromSelf : NSObject |
Alex Lorenz | 194d00e | 2019-01-17 18:12:45 +0000 | [diff] [blame] | 50 | -(instancetype)init __attribute__((unavailable)); |
Erik Pilkington | 4257857 | 2018-09-10 22:20:09 +0000 | [diff] [blame] | 51 | +(FromSelf*)another_one; |
| 52 | @end |
| 53 | |
| 54 | @implementation FromSelf |
| 55 | +(FromSelf*)another_one { |
Alex Lorenz | 194d00e | 2019-01-17 18:12:45 +0000 | [diff] [blame] | 56 | [self new]; |
Erik Pilkington | 4257857 | 2018-09-10 22:20:09 +0000 | [diff] [blame] | 57 | } |
| 58 | @end |
Erik Pilkington | 3062887 | 2019-02-04 23:30:57 +0000 | [diff] [blame] | 59 | |
| 60 | @interface NoInit : NSObject |
| 61 | -(instancetype)init __attribute__((unavailable)); // expected-note {{'init' has been explicitly marked unavailable here}} |
| 62 | @end |
| 63 | |
| 64 | @interface NoInitSub : NoInit @end |
| 65 | |
| 66 | @implementation NoInitSub |
| 67 | -(void)meth:(Class)c { |
| 68 | [c new]; // No error; unknown interface. |
| 69 | [NoInitSub new]; // expected-error {{'new' is unavailable}} |
| 70 | } |
| 71 | @end |