| 1 |
// RUN: %clang_cc1 -fobjc-runtime-has-weak -fobjc-weak -fsyntax-only -verify %s |
| 2 |
|
| 3 |
__attribute__((objc_root_class)) |
| 4 |
@interface A |
| 5 |
@property (weak) id wa; // expected-note {{property declared here}} |
| 6 |
@property (weak) id wb; |
| 7 |
@property (weak) id wc; // expected-note {{property declared here}} |
| 8 |
@property (weak) id wd; |
| 9 |
@property (unsafe_unretained) id ua; |
| 10 |
@property (unsafe_unretained) id ub; // expected-note {{property declared here}} |
| 11 |
@property (unsafe_unretained) id uc; |
| 12 |
@property (unsafe_unretained) id ud; |
| 13 |
@property (strong) id sa; |
| 14 |
@property (strong) id sb; // expected-note {{property declared here}} |
| 15 |
@property (strong) id sc; |
| 16 |
@property (strong) id sd; |
| 17 |
@end |
| 18 |
|
| 19 |
@implementation A { |
| 20 |
id _wa; // expected-error {{existing instance variable '_wa' for __weak property 'wa' must be __weak}} |
| 21 |
__weak id _wb; |
| 22 |
__unsafe_unretained id _wc; // expected-error {{existing instance variable '_wc' for __weak property 'wc' must be __weak}} |
| 23 |
id _ua; |
| 24 |
__weak id _ub; // expected-error {{existing instance variable '_ub' for property 'ub' with unsafe_unretained attribute must be __unsafe_unretained}} |
| 25 |
__unsafe_unretained id _uc; |
| 26 |
id _sa; |
| 27 |
__weak id _sb; // expected-error {{existing instance variable '_sb' for strong property 'sb' may not be __weak}} |
| 28 |
__unsafe_unretained id _sc; |
| 29 |
} |
| 30 |
@synthesize wa = _wa; // expected-note {{property synthesized here}} |
| 31 |
@synthesize wb = _wb; |
| 32 |
@synthesize wc = _wc; // expected-note {{property synthesized here}} |
| 33 |
@synthesize wd = _wd; |
| 34 |
@synthesize ua = _ua; |
| 35 |
@synthesize ub = _ub; // expected-note {{property synthesized here}} |
| 36 |
@synthesize uc = _uc; |
| 37 |
@synthesize ud = _ud; |
| 38 |
@synthesize sa = _sa; |
| 39 |
@synthesize sb = _sb; // expected-note {{property synthesized here}} |
| 40 |
@synthesize sc = _sc; |
| 41 |
@synthesize sd = _sd; |
| 42 |
@end |
| 43 |
|
| 44 |
void test_goto(void) { |
| 45 |
goto after; // expected-error {{cannot jump from this goto statement to its label}} |
| 46 |
__weak id x; // expected-note {{jump bypasses initialization of __weak variable}}} |
| 47 |
after: |
| 48 |
return; |
| 49 |
} |
| 50 |
|
| 51 |
void test_weak_cast(id *value) { |
| 52 |
__weak id *a = (__weak id*) value; |
| 53 |
id *b = (__weak id*) value; // expected-error {{initializing 'id *' with an expression of type '__weak id *' changes retain/release properties of pointer}} |
| 54 |
__weak id *c = (id*) value; // expected-error {{initializing '__weak id *' with an expression of type 'id *' changes retain/release properties of pointer}} |
| 55 |
} |
| 56 |
|
| 57 |
void test_unsafe_unretained_cast(id *value) { |
| 58 |
__unsafe_unretained id *a = (__unsafe_unretained id*) value; |
| 59 |
id *b = (__unsafe_unretained id*) value; |
| 60 |
__unsafe_unretained id *c = (id*) value; |
| 61 |
} |
| 62 |
|
| 63 |
void test_cast_qualifier_inference(__weak id *value) { |
| 64 |
__weak id *a = (id*) value; |
| 65 |
__unsafe_unretained id *b = (id *)value; // expected-error {{initializing 'id *' with an expression of type '__weak id *' changes retain/release properties of pointer}} |
| 66 |
} |
| 67 |
|