Add PR check to suggest alternatives to using undef (#118506)
[llvm-project.git] / clang / test / SemaObjC / arc-unsafe-assigns.m
blob8989fac7c2481f71a65ddbcf8fa717c818904a2a
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s
3 @interface Foo {
4   __unsafe_unretained id unsafe_ivar;
7 @property (assign,nonatomic) id unsafe_prop;
9 - (id)init;
10 + (id)new;
11 + (id)alloc;
13 -(void)Meth;
14 @end
16 @implementation Foo
17 @synthesize unsafe_prop;
18 -(id)init { return self; }
19 +(id)new { return 0; }
20 +(id)alloc { return 0; }
22 -(void)Meth {
23   self.unsafe_prop = [Foo new]; // expected-warning {{assigning retained object to unsafe property}}
24   self->unsafe_ivar = [Foo new]; // expected-warning {{assigning retained object to unsafe_unretained}}
25   self.unsafe_prop = [[Foo alloc] init]; // expected-warning {{assigning retained object to unsafe property}}
26   self->unsafe_ivar = [[Foo alloc] init]; // expected-warning {{assigning retained object to unsafe_unretained}}
28   __unsafe_unretained id unsafe_var;
29   unsafe_var = [Foo new]; // expected-warning {{assigning retained object to unsafe_unretained}}
30   unsafe_var = [[Foo alloc] init]; // expected-warning {{assigning retained object to unsafe_unretained}}
32 @end
34 void bar(Foo *f) {
35   f.unsafe_prop = [Foo new]; // expected-warning {{assigning retained object to unsafe property}}
37   __unsafe_unretained id unsafe_var;
38   unsafe_var = [Foo new]; // expected-warning {{assigning retained object to unsafe_unretained}}
39   unsafe_var = [[Foo alloc] init]; // expected-warning {{assigning retained object to unsafe_unretained}}