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 |
50 | -(instancetype)init __attribute__((unavailable)); |
51 | +(FromSelf*)another_one; |
52 | @end |
53 | |
54 | @implementation FromSelf |
55 | +(FromSelf*)another_one { |
56 | [self new]; |
57 | } |
58 | @end |
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 |
72 | |