1 | // RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fobjc-runtime=macosx-10.13.0 -fblocks -fobjc-arc %s -verify |
2 | // RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fobjc-runtime=macosx-10.13.0 -fblocks -fobjc-arc -xobjective-c++ %s -verify |
3 | |
4 | #define EXT_RET __attribute__((objc_externally_retained)) |
5 | |
6 | @interface ObjCTy |
7 | @end |
8 | |
9 | void test1() { |
10 | EXT_RET int a; // expected-warning{{'objc_externally_retained' can only be applied to}} |
11 | EXT_RET __weak ObjCTy *b; // expected-warning{{'objc_externally_retained' can only be applied to}} |
12 | EXT_RET __weak int (^c)(); // expected-warning{{'objc_externally_retained' can only be applied to}} |
13 | |
14 | EXT_RET int (^d)() = ^{return 0;}; |
15 | EXT_RET ObjCTy *e = 0; |
16 | EXT_RET __strong ObjCTy *f = 0; |
17 | |
18 | e = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}} |
19 | f = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}} |
20 | d = ^{ return 0; }; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}} |
21 | } |
22 | |
23 | void test2(ObjCTy *a); |
24 | |
25 | void test2(ObjCTy *a) EXT_RET { |
26 | a = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}} |
27 | } |
28 | |
29 | EXT_RET ObjCTy *test3; // expected-warning{{'objc_externally_retained' can only be applied to}} |
30 | |
31 | @interface X // expected-warning{{defined without specifying a base class}} expected-note{{add a super class}} |
32 | -(void)m: (ObjCTy *) p; |
33 | @end |
34 | @implementation X |
35 | -(void)m: (ObjCTy *) p EXT_RET { |
36 | p = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}} |
37 | } |
38 | @end |
39 | |
40 | void test4() { |
41 | __attribute__((objc_externally_retained(0))) ObjCTy *a; // expected-error{{'objc_externally_retained' attribute takes no arguments}} |
42 | } |
43 | |
44 | void test5(ObjCTy *first, __strong ObjCTy *second) EXT_RET { |
45 | first = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}} |
46 | second = 0; // fine |
47 | } |
48 | |
49 | void test6(ObjCTy *first, |
50 | __strong ObjCTy *second) EXT_RET { |
51 | first = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}} |
52 | second = 0; |
53 | } |
54 | |
55 | __attribute__((objc_root_class)) @interface Y @end |
56 | |
57 | @implementation Y |
58 | - (void)test7:(__strong ObjCTy *)first |
59 | withThird:(ObjCTy *)second EXT_RET { |
60 | first = 0; |
61 | second = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}} |
62 | } |
63 | @end |
64 | |
65 | void (^blk)(ObjCTy *, ObjCTy *) = |
66 | ^(__strong ObjCTy *first, ObjCTy *second) EXT_RET { |
67 | first = 0; |
68 | second = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}} |
69 | }; |
70 | |
71 | void test8(EXT_RET ObjCTy *x) {} // expected-warning{{'objc_externally_retained' attribute only applies to variables}} |
72 | |
73 | #pragma clang attribute ext_ret.push(__attribute__((objc_externally_retained)), apply_to=any(function, block, objc_method)) |
74 | void test9(ObjCTy *first, __strong ObjCTy *second) { |
75 | first = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}} |
76 | second = 0; |
77 | } |
78 | void (^test10)(ObjCTy *first, ObjCTy *second) = ^(ObjCTy *first, __strong ObjCTy *second) { |
79 | first = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}} |
80 | second = 0; |
81 | }; |
82 | __attribute__((objc_root_class)) @interface Test11 @end |
83 | @implementation Test11 |
84 | -(void)meth: (ObjCTy *)first withSecond:(__strong ObjCTy *)second { |
85 | first = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}} |
86 | second = 0; |
87 | } |
88 | +(void)othermeth: (ObjCTy *)first withSecond:(__strong ObjCTy *)second { |
89 | first = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}} |
90 | second = 0; |
91 | } |
92 | @end |
93 | |
94 | #if __cplusplus |
95 | class Test12 { |
96 | void inline_member(ObjCTy *first, __strong ObjCTy *second) { |
97 | first = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}} |
98 | second = 0; |
99 | } |
100 | static void static_inline_member(ObjCTy *first, __strong ObjCTy *second) { |
101 | first = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}} |
102 | second = 0; |
103 | } |
104 | }; |
105 | #endif |
106 | |
107 | void test13(ObjCTy *first, __weak ObjCTy *second, __unsafe_unretained ObjCTy *third, __strong ObjCTy *fourth) { |
108 | first = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}} |
109 | second = 0; |
110 | third = 0; |
111 | fourth = 0; |
112 | } |
113 | |
114 | #pragma clang attribute ext_ret.pop |
115 | |