Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

Lambda Bug

Scott_Danahy
Beginner
387 Views
I seem to have encountered a fairly serious bug in the C++11 Lambda implementation. This can be reproduced with XE Composer 12.1 Update 10. The following code will crash:
#include
#include
class A
{
public:
A():name("Class A"){}
void F1(std::function callback)
{
auto f = [this,callback](void)
{
F2(callback);
};
f();
}
private:
void F2(std::function callback)
{
printf("%s\\n",name);
callback();
}
const char * name;
};
int main(void)
{
A a;
a.F1([](void)
{
printf("Called.\\n");
});
}
This issue is that when A::F2 is invoked the lambda-captured 'this' pointer is garbage. The bug seems to be related to capturing a std::function instance bound to a lambda alongside the 'this' pointer. If the std::function callback parameter is not captured then the code behaves correctly. A workaround is to define F1 such that the 'this' pointer is assigned to a local variable that is then captured:
//Works correctly
void F1(std::function callback)
{
A * thisptr=this;
auto fn2 = [thisptr,callback](void)
{
thisptr->F2(callback);
};
fn2();
}
The original code works correctly when compiled with the Microsoft compiler (v10).
Thanks,
Scott
0 Kudos
5 Replies
Judith_W_Intel
Employee
387 Views

This sounds like the same bug as described here:

http://software.intel.com/en-us/forums/showthread.php?t=104862&o=a&s=lr

0 Kudos
Scott_Danahy
Beginner
387 Views
Sounds like it. In my code the value of 'this' was also0xcdcdcdcd. Looks similar to this too:
0 Kudos
Scott_Danahy
Beginner
387 Views
Is there any update on this issue? Is it a confirmed bug in Update 10? Is it fixed in Composer 13?
0 Kudos
JenniferJ
Moderator
387 Views
Although it's not fixed yet in 13.0, but it's been actively investigated. When the fix is in the product, our report should show and we will let you know.

Jennifer
0 Kudos
Georg_Z_Intel
Employee
387 Views
Hello,

this problem has been fixed for the next update release, Intel Composer XE 2011 Update 12 and also will be fixed for the future Intel Composer XE 2013.

Best regards,

Georg Zitzlsberger
0 Kudos
Reply