[LLVMbugs] [Bug 18780] New: Lambda inside lambda doesn't capture the variable

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Feb 9 01:23:01 PST 2014


            Bug ID: 18780
           Summary: Lambda inside lambda doesn't capture the variable
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: abyss.7 at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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;
  a.a = 1;

  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

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140209/0faedfd4/attachment.html>

More information about the llvm-bugs mailing list