Debian Codegraph @

clang/test/Analysis/symbol-reaper-lambda.cpp

raw
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s
2 // expected-no-diagnostics
3
4 template <typename... Ts>
5 void escape(Ts&...);
6 struct Dummy {};
7
8 int strange(Dummy param) {
9 Dummy local_pre_lambda;
10 int ref_captured = 0;
11
12 // LambdaExpr is modeled as lazyCompoundVal of tempRegion, that contains
13 // all captures. In this instance, this region contains a pointer/reference
14 // to ref_captured variable.
15 auto fn = [&] {
16 escape(param, local_pre_lambda);
17 return ref_captured; // no-warning: The value is not garbage.
18 };
19
20 int local_defined_after_lambda; // Unused, but necessary! Important that it's before the call.
21
22 // The ref_captured binding should not be pruned at this point, as it is still
23 // accessed via reference captured in operator() of fn.
24 return fn();
25 }
26