warn-retain-block-property.m
2.45 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
// RUN: not %clang_cc1 -fsyntax-only -fblocks -fobjc-arc -Wno-objc-root-class %s 2>&1 | FileCheck --check-prefix=CHECK-ARC %s
// rdar://9829425
// RUN: not %clang_cc1 -fsyntax-only -fblocks -Wno-objc-root-class %s 2>&1 | FileCheck %s
// rdar://11761511
extern void doSomething();
@interface Test
{
@public
void (^aBlock)(void);
}
@property (retain) void (^aBlock)(void);
@property (weak, retain) void (^aBlockW)(void);
@property (strong, retain) void (^aBlockS)(void); // OK
@property (readonly, retain) void (^aBlockR)(void); // OK
@property (copy, retain) void (^aBlockC)(void);
@property (assign, retain) void (^aBlockA)(void);
@end
@implementation Test
@synthesize aBlock;
@dynamic aBlockW, aBlockS, aBlockR, aBlockC, aBlockA;
@end
int main() {
Test *t;
t.aBlock = ^{ doSomething(); };
t.aBlockW = ^{ doSomething(); };
t.aBlockS = ^{ doSomething(); };
}
// CHECK-ARC: 14:1: warning: retain'ed block property does not copy the block - use copy attribute instead
// CHECK-ARC: @property (retain) void (^aBlock)(void);
// CHECK-ARC: ^
// CHECK-ARC: 15:1: error: property attributes 'retain' and 'weak' are mutually exclusive
// CHECK-ARC: @property (weak, retain) void (^aBlockW)(void);
// CHECK-ARC: ^
// CHECK-ARC: 18:1: error: property attributes 'copy' and 'retain' are mutually exclusive
// CHECK-ARC: @property (copy, retain) void (^aBlockC)(void);
// CHECK-ARC: ^
// CHECK-ARC: 19:1: error: property attributes 'assign' and 'retain' are mutually exclusive
// CHECK-ARC: @property (assign, retain) void (^aBlockA)(void);
// CHECK-ARC: ^
// CHECK-ARC: 30:13: warning: assigning block literal to a weak property; object will be released after assignment
// CHECK-ARC: t.aBlockW = ^{ doSomething(); };
// CHECK-ARC: ^ ~~~~~~~~~~~~~~~~~~~
// CHECK-ARC: 2 warnings and 3 errors generated.
// CHECK: 14:1: warning: retain'ed block property does not copy the block - use copy attribute instead
// CHECK: @property (retain) void (^aBlock)(void);
// CHECK: ^
// CHECK: 15:1: error: property attributes 'retain' and 'weak' are mutually exclusive
// CHECK: @property (weak, retain) void (^aBlockW)(void);
// CHECK: ^
// CHECK: 18:1: error: property attributes 'copy' and 'retain' are mutually exclusive
// CHECK: @property (copy, retain) void (^aBlockC)(void);
// CHECK: ^
// CHECK: 19:1: error: property attributes 'assign' and 'retain' are mutually exclusive
// CHECK: @property (assign, retain) void (^aBlockA)(void);
// CHECK: ^
// CHECK: 1 warning and 3 errors generated.