- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This sounds like the same bug as described here:
http://software.intel.com/en-us/forums/showthread.php?t=104862&o=a&s=lr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sounds like it. In my code the value of 'this' was also0xcdcdcdcd. Looks similar to this too:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is there any update on this issue? Is it a confirmed bug in Update 10? Is it fixed in Composer 13?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Jennifer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page