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 9void 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 23void test2(ObjCTy *a); 24 25void test2(ObjCTy *a) EXT_RET { 26 a = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}} 27} 28 29EXT_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 40void test4() { 41 __attribute__((objc_externally_retained(0))) ObjCTy *a; // expected-error{{'objc_externally_retained' attribute takes no arguments}} 42} 43 44void 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 49void 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 65void (^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 71void (^blk2)(ObjCTy *, ObjCTy *) = 72 ^(__strong ObjCTy *first, ObjCTy *second) __attribute__((objc_externally_retained)) { 73 first = 0; 74 second = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}} 75}; 76 77void test8(EXT_RET ObjCTy *x) {} // expected-warning{{'objc_externally_retained' attribute only applies to variables}} 78 79#pragma clang attribute ext_ret.push(__attribute__((objc_externally_retained)), apply_to=any(function, block, objc_method)) 80void test9(ObjCTy *first, __strong ObjCTy *second) { 81 first = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}} 82 second = 0; 83} 84void (^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}} 86 second = 0; 87}; 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}} 92 second = 0; 93} 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}} 96 second = 0; 97} 98@end 99 100#if __cplusplus 101class Test12 { 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}} 104 second = 0; 105 } 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}} 108 second = 0; 109 } 110}; 111#endif 112 113void 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}} 115 second = 0; 116 third = 0; 117 fourth = 0; 118} 119 120#pragma clang attribute ext_ret.pop 121 122__attribute__((objc_externally_retained)) 123void unprototyped(); 124