<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 --- - Lambda inside lambda doesn't capture the variable"
   href="http://llvm.org/bugs/show_bug.cgi?id=18780">18780</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Lambda inside lambda doesn't capture the variable
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux
          </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>C++11
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>abyss.7@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Here is a sample code:

#include <functional>
#include <iostream>

struct A {
  int a = 0;
  std::function<void()> on_run;
};

int main() {
  auto on_create = [](A* a) {
    std::cout << a << " " << a->a << std::endl;
    a->on_run = [&a]() {
      std::cout << a << " " << a->a << std::endl;
    };
  };

  A a;
  on_create(&a);
  a.a = 1;
  a.on_run();

  return 0;
}

The compilation command-line:

clang++ -std=c++11 test.cc -o test

Everything goes ok, except, that the possible output from `./test` is:

0x7fff6d180ac0 0
0x7fff6d180ac8 28930064

It looks like the second output has arbitrary values, since sometimes it even
segfaults.</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>