1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -fblocks -Wno-objc-root-class -analyze -analyzer-checker=core,deadcode,debug.ExprInspection -analyzer-config inline-lambdas=true -verify %s
3 int clang_analyzer_eval(int);
9 @interface Sub : Super {
17 - (void)callMethodOnSuperInCXXLambda; {
35 - (void)callMethodOnSelfInCXXLambda; {
42 clang_analyzer_eval(_ivar1 == 8); // expected-warning{{TRUE}}
43 clang_analyzer_eval(_ivar2 == 7); // expected-warning{{TRUE}}
51 void castToBlockNoDeadStore() {
52 int v = getValue(); // no-warning
54 (void)(void(^)())[v]() { // This capture should count as a use, so no dead store warning above.
58 void takesBlock(void(^block)());
60 void passToFunctionTakingBlockNoDeadStore() {
61 int v = 7; // no-warning
62 int x = 8; // no-warning
63 takesBlock([&v, x]() {
68 void castToBlockAndInline() {
69 int result = ((int(^)(int))[](int p) {
73 clang_analyzer_eval(result == 7); // expected-warning{{TRUE}}
76 void castToBlockWithCaptureAndInline() {
79 auto lambda = [y]{ return y; };
80 int(^block)() = lambda;
83 clang_analyzer_eval(result == 7); // expected-warning{{TRUE}}
86 void castMutableLambdaToBlock() {
89 auto lambda = [x]() mutable {
94 // The block should copy the lambda before capturing.
95 int(^block)() = lambda;
98 clang_analyzer_eval(r1 == 1); // expected-warning{{TRUE}}
101 clang_analyzer_eval(r2 == 2); // expected-warning{{TRUE}}
103 // Because block copied the lambda, r3 should be 1.
105 clang_analyzer_eval(r3 == 1); // expected-warning{{TRUE}}
107 // Aliasing the block shouldn't copy the lambda.
108 int(^blockAlias)() = block;
110 int r4 = blockAlias();
111 clang_analyzer_eval(r4 == 3); // expected-warning{{TRUE}}
114 clang_analyzer_eval(r5 == 4); // expected-warning{{TRUE}}
116 // Another copy of lambda
117 int(^blockSecondCopy)() = lambda;
118 int r6 = blockSecondCopy();
119 clang_analyzer_eval(r6 == 2); // expected-warning{{TRUE}}
122 void castLambdaInLocalBlock() {
123 // Make sure we don't emit a spurious diagnostic about the address of a block
124 // escaping in the implicit conversion operator method for lambda-to-block
126 auto lambda = []{ }; // no-warning
128 void(^block)() = lambda;