brintos

brintos / llvm-project-archived public Read only

0
0
Text · 798 B · c63562b Raw
27 lines · cpp
1// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s2// expected-no-diagnostics3 4template <typename... Ts>5void escape(Ts&...);6struct Dummy {};7 8int strange(Dummy param) {9  Dummy local_pre_lambda;10  int ref_captured = 0;11 12  // LambdaExpr is modeled as lazyCompoundVal of tempRegion, that contains13  // all captures. In this instance, this region contains a pointer/reference14  // 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 still23  // accessed via reference captured in operator() of fn.24  return fn();25}26 27