xref: /llvm-project/clang/test/SemaObjCXX/warn-implicit-self-in-block.mm (revision 0f1c1be1968076d6f96f8a7bcc4a15cf195ecd97)
1// RUN: %clang_cc1 -x objective-c++ -std=c++11 -fobjc-arc -fblocks -Wimplicit-retain-self -verify %s
2
3typedef void (^BlockTy)();
4
5void noescapeFunc(__attribute__((noescape)) BlockTy);
6void escapeFunc(BlockTy);
7
8@interface Root @end
9
10@interface I : Root
11{
12  int _bar;
13}
14@end
15
16@implementation I
17  - (void)foo{
18      ^{
19           _bar = 3; // expected-warning {{block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior}}
20       }();
21  }
22
23  - (void)testNested{
24    noescapeFunc(^{
25      (void)_bar;
26      escapeFunc(^{
27        (void)_bar; // expected-warning {{block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior}}
28        noescapeFunc(^{
29          (void)_bar; // expected-warning {{block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior}}
30        });
31        (void)_bar; // expected-warning {{block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior}}
32      });
33      (void)_bar;
34    });
35  }
36
37  - (void)testLambdaInBlock{
38    noescapeFunc(^{ [&](){ (void)_bar; }(); });
39    escapeFunc(^{ [&](){ (void)_bar; }(); }); // expected-warning {{block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior}}
40  }
41
42  - (BlockTy)testDeclType{
43    return ^{ decltype(_bar) i = 12; (void)i; };
44  }
45@end
46