<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 "undefined or garbage value returned" from C++14 lambda capture"
   href="http://llvm.org/bugs/show_bug.cgi?id=22833">22833</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>False "undefined or garbage value returned" from C++14 lambda capture
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </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=14003" name="attach_14003" title="Runnable example">attachment 14003</a> <a href="attachment.cgi?id=14003&action=edit" title="Runnable example">[details]</a></span>
Runnable example

Giving a lambda capture parameter an explicit value (new feature in C++14)
causes the analyzer to believe that value is undefined.  The simplest code
snippet which exhibits the problem:


    auto f1 = [a=1] () {
        return a;
    };
    const function<int()> f2 = f1;

/ws/art_hack/ArtCppHack/ArtCppHack/main.cpp:24:9: warning: Undefined or garbage
value returned to caller
        return a;
        ^~~~~~~~
1 warning generated.


Creating the std::function is required to get the analyzer to analyze the
return path in a way which triggers the warning.  Calling the lambda locally
instead doesn't cause the warning.  Passing it to a template function which
calls it does trigger the warning.  It doesn't seem to matter what the type of
the captured variable is, or what the expression assigned to it is.  The
constant int above is the simplest example, but our real code is capturing a
shared_ptr, and gets the warning on the return value from its operator->.

I'd love to hear if there's a workaround for this I can use cleanly in my code,
short of using "#ifdef __clang_analyzer__" to compile out the whole body.

The code compiles and runs correctly, so it's only the analyzer which is
confused.  I'm using the analyzer integrated into Xcode 6.1.1.  A colleague
confirmed the same bug in Xcode 6.3b2.</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>