http://llvm.org/bugs/show_bug.cgi?id=18780
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: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected]
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;
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs