Some lambda problem

Some lambda problem

Hi,this is on Windows, compiler update 9. Deep in my code there is this snippet:

if (!theCellsToPrepare.empty()) {

   thePrepareGroup.DispatchAsync([=]() {

      for_each(theCellsToPrepare.begin(), theCellsToPrepare.end(), [=](DLGLTableCell inCell) {

         auto theCellCache = CalcCache(inCell, true);
This is inside a class method, "CalcCache" is another method in the class; that call crashes because "this" is "0xcdcdcdcd". I am 100% sure "this" has not been freed by then, it is still a live object and in any case, a pointer to it wouldn't change it's value anyway. Somehow "this" doesn't get copied correctly into the lambda. It's not the lamda inside the lambda, explicitely using "this->CalcCache" also didn't help. This worked:
if (!theCellsToPrepare.empty()) {

   auto *theInterior = this; // BUGBUGCOMPILER, shouldn't be necessary

   thePrepareGroup.DispatchAsync([=]() {

      for_each(theCellsToPrepare.begin(), theCellsToPrepare.end(), [=](DLGLTableCell inCell) {

         auto theCellCache = theInterior->CalcCache(inCell, true);
I am just starting with using lambdas, so I might be wrong. But since the lambdas do capture everything by value, this "fix" should not make any difference whatsoever. Also the original code works on clang (tip of trunk) without any problems. So I believe there is a compiler bug hidden somewhere in there; I haven't tried to create a simple testcase for it, so this is more of an "FYI, there is a bug somewhere" than anything.

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hello,

I just got aware that this is a duplicate to another
thread for which we've already been further. Hence I'm going to close
this thread and like to forward you to
http://software.intel.com/en-us/forums/showthread.php?t=104862
for the latest status.

Best regards,

Georg Zitzlsberger

Login to leave a comment.