<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - False "Value stored is never read" due to reference captured in lambda"
   href="http://llvm.org/bugs/show_bug.cgi?id=22834">22834</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>False "Value stored is never read" due to reference captured in lambda
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.5
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Static Analyzer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>kremenek@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>atwyman@dropbox.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=14004" name="attach_14004" title="Runnable example">attachment 14004</a> <a href="attachment.cgi?id=14004&action=edit" title="Runnable example">[details]</a></span>
Runnable example

If a value is captured in a lambda, then modified later in the code, the
analyzer thinks the value is never used, and flags it as a dead store, even if
the lambda is run locally to use the value.  Here's a simple example, where
f1() prints "0" rather than "1" as a result of the indicated line.

    bool b = true;
    auto f1 = [&b] () {
        cout << b << endl;
    };
    b = false; // warning on this line
    f1();

/ws/art_hack/ArtCppHack/ArtCppHack/main.cpp:12:5: warning: Value stored to 'b'
is never read
    b = false;
    ^   ~~~~~
1 warning generated.

We're generally able to work around this by adding something like "(void)b;" to
make the variable appear to be used, but it would be nice not to have to.

I'm using the analyzer integrated in Xcode 6.1.1.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>