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