title: Why can't clang tidy detect dead code in lambda function?
body: <p>Clang tidy can't detect dead code when I use a lambda function; but, if I replace the lambda with a normal function, Clang tidy pin-points the error like the message below:</p>
  <blockquote>
  <p>warning GC1A2668F: Value stored to 'ret' is never read [clang-analyzer-deadcode.DeadStores]</p>
  </blockquote>
  <p>Is there any way to enforce clang tidy to check dead code even in a lambda function?</p>
  <p>Here is my code.(<em>waring: code is meaningless and just for dead code testing</em>). You can use the <code>USE_LAMBDA</code> define in order to switch back and forth between lambda and normal function.</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  
  using namespace std;
  
  int GetRet()
  {
      return 5;
  }
  
  #define USE_LAMBDA 1
  
  #if USE_LAMBDA
  int main()
  {
      int ary[10]{};
  
      for_each(begin(ary), end(ary), [](int a)
      {
              int ret = GetRet();
  
              if (a &gt; 5 &amp;&amp; ret &lt; 1)
              {
                  ret = 6;
              }
      });
      
      return 0;
  }
  
  #else
  
  void Check(int a)
  {
      int ret = GetRet();
  
      if (a &gt; 5 &amp;&amp; ret &lt; 1)
      {
          ret = 6;
      }
  }
  
  int main()
  {
      int ary[10]{};
  
      for_each(begin(ary), end(ary), Check);
  
      return 0;
  }
  #endif
  </code></pre>