1 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fobjc-runtime=macosx-10.13.0 -fblocks -fobjc-arc -Wno-strict-prototypes %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
4 #define EXT_RET __attribute__((objc_externally_retained))
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)(void); // expected-warning{{'objc_externally_retained' can only be applied to}}
14 EXT_RET int (^d)(void) = ^{return 0;};
15 EXT_RET ObjCTy *e = 0;
16 EXT_RET __strong ObjCTy *f = 0;
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}}
23 void test2(ObjCTy *a);
25 void test2(ObjCTy *a) EXT_RET {
26 a = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
29 EXT_RET ObjCTy *test3; // expected-warning{{'objc_externally_retained' can only be applied to}}
31 @interface X // expected-warning{{defined without specifying a base class}} expected-note{{add a super class}}
32 -(void)m: (ObjCTy *) p;
35 -(void)m: (ObjCTy *) p EXT_RET {
36 p = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
41 __attribute__((objc_externally_retained(0))) ObjCTy *a; // expected-error{{'objc_externally_retained' attribute takes no arguments}}
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}}
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}}
55 __attribute__((objc_root_class)) @interface Y @end
58 - (void)test7:(__strong ObjCTy *)first
59 withThird:(ObjCTy *)second EXT_RET {
61 second = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
65 void (^blk)(ObjCTy *, ObjCTy *) =
66 ^(__strong ObjCTy *first, ObjCTy *second) EXT_RET {
68 second = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
71 void (^blk2)(ObjCTy *, ObjCTy *) =
72 ^(__strong ObjCTy *first, ObjCTy *second) __attribute__((objc_externally_retained)) {
74 second = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
77 void test8(EXT_RET ObjCTy *x) {} // expected-warning{{'objc_externally_retained' attribute only applies to variables}}
79 #pragma clang attribute ext_ret.push(__attribute__((objc_externally_retained)), apply_to=any(function, block, objc_method))
80 void test9(ObjCTy *first, __strong ObjCTy *second) {
81 first = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
84 void (^test10)(ObjCTy *first, ObjCTy *second) = ^(ObjCTy *first, __strong ObjCTy *second) {
85 first = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
88 __attribute__((objc_root_class)) @interface Test11 @end
89 @implementation Test11
90 -(void)meth: (ObjCTy *)first withSecond:(__strong ObjCTy *)second {
91 first = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
94 +(void)othermeth: (ObjCTy *)first withSecond:(__strong ObjCTy *)second {
95 first = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
102 void inline_member(ObjCTy *first, __strong ObjCTy *second) {
103 first = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
106 static void static_inline_member(ObjCTy *first, __strong ObjCTy *second) {
107 first = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
113 void test13(ObjCTy *first, __weak ObjCTy *second, __unsafe_unretained ObjCTy *third, __strong ObjCTy *fourth) {
114 first = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
120 #pragma clang attribute ext_ret.pop
122 __attribute__((objc_externally_retained))