| 1 |
// RUN: not %clang_cc1 -fsyntax-only -fblocks -fobjc-arc -Wno-objc-root-class %s 2>&1 | FileCheck --check-prefix=CHECK-ARC %s |
| 2 |
// RUN: not %clang_cc1 -fsyntax-only -fblocks -Wno-objc-root-class %s 2>&1 | FileCheck %s |
| 3 |
|
| 4 |
extern void doSomething(void); |
| 5 |
|
| 6 |
@interface Test |
| 7 |
{ |
| 8 |
@public |
| 9 |
void (^aBlock)(void); |
| 10 |
} |
| 11 |
@property (retain) void (^aBlock)(void); |
| 12 |
@property (weak, retain) void (^aBlockW)(void); |
| 13 |
@property (strong, retain) void (^aBlockS)(void); // OK |
| 14 |
@property (readonly, retain) void (^aBlockR)(void); // OK |
| 15 |
@property (copy, retain) void (^aBlockC)(void); |
| 16 |
@property (assign, retain) void (^aBlockA)(void); |
| 17 |
@end |
| 18 |
|
| 19 |
@implementation Test |
| 20 |
@synthesize aBlock; |
| 21 |
@dynamic aBlockW, aBlockS, aBlockR, aBlockC, aBlockA; |
| 22 |
@end |
| 23 |
|
| 24 |
int main(void) { |
| 25 |
Test *t; |
| 26 |
t.aBlock = ^{ doSomething(); }; |
| 27 |
t.aBlockW = ^{ doSomething(); }; |
| 28 |
t.aBlockS = ^{ doSomething(); }; |
| 29 |
} |
| 30 |
|
| 31 |
// CHECK-ARC: 11:1: warning: retain'ed block property does not copy the block - use copy attribute instead |
| 32 |
// CHECK-ARC: @property (retain) void (^aBlock)(void); |
| 33 |
// CHECK-ARC: ^ |
| 34 |
// CHECK-ARC: 12:1: error: property attributes 'retain' and 'weak' are mutually exclusive |
| 35 |
// CHECK-ARC: @property (weak, retain) void (^aBlockW)(void); |
| 36 |
// CHECK-ARC: ^ |
| 37 |
// CHECK-ARC: 15:1: error: property attributes 'copy' and 'retain' are mutually exclusive |
| 38 |
// CHECK-ARC: @property (copy, retain) void (^aBlockC)(void); |
| 39 |
// CHECK-ARC: ^ |
| 40 |
// CHECK-ARC: 16:1: error: property attributes 'assign' and 'retain' are mutually exclusive |
| 41 |
// CHECK-ARC: @property (assign, retain) void (^aBlockA)(void); |
| 42 |
// CHECK-ARC: ^ |
| 43 |
// CHECK-ARC: 27:13: warning: assigning block literal to a weak property; object will be released after assignment |
| 44 |
// CHECK-ARC: t.aBlockW = ^{ doSomething(); }; |
| 45 |
// CHECK-ARC: ^ ~~~~~~~~~~~~~~~~~~~ |
| 46 |
// CHECK-ARC: 2 warnings and 3 errors generated. |
| 47 |
|
| 48 |
// CHECK: 11:1: warning: retain'ed block property does not copy the block - use copy attribute instead |
| 49 |
// CHECK: @property (retain) void (^aBlock)(void); |
| 50 |
// CHECK: ^ |
| 51 |
// CHECK: 12:1: error: property attributes 'retain' and 'weak' are mutually exclusive |
| 52 |
// CHECK: @property (weak, retain) void (^aBlockW)(void); |
| 53 |
// CHECK: ^ |
| 54 |
// CHECK: 15:1: error: property attributes 'copy' and 'retain' are mutually exclusive |
| 55 |
// CHECK: @property (copy, retain) void (^aBlockC)(void); |
| 56 |
// CHECK: ^ |
| 57 |
// CHECK: 16:1: error: property attributes 'assign' and 'retain' are mutually exclusive |
| 58 |
// CHECK: @property (assign, retain) void (^aBlockA)(void); |
| 59 |
// CHECK: ^ |
| 60 |
// CHECK: 1 warning and 3 errors generated. |