Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
7725 Discussions

Bug in lambdas ICC Update 10 on Windows

Dix_Lorenz
Beginner
175 Views
Hi all,
the following code crashes with the new compiler update (actually, it also crashed in Update 9). InDoSomethingWithAnInt "this" has a Value of "0xcdcdcdcd"...
(sorry for the formatting, no idea how to do it better in here)

#include "stdafx.h"

#include

#include

#include

#include

#include

using namespace std;

namespace NS1 {

class Dispatcher {

public:

void Dispatch(function inFunction);

};

void Dispatcher::Dispatch(function inFunction)

{

inFunction();

}

}

class SomeClass {

public:

void Pass(int i) { cout << i << endl; }

};

namespace N2 {

class Interior {

public:

Interior() : mSomeClass(new SomeClass) {}

void DoSomething();

void DoSomethingWithAnInt(int i);

private:

unique_ptr mSomeClass;

};

void Interior::DoSomething()

{

NS1::Dispatcher theDispatcher;

vector v;

for (int i = 0; i < 10; ++i)

v.push_back(i);

theDispatcher.Dispatch([=](){

for_each(v.begin(), v.end(), [=](int i){

DoSomethingWithAnInt(i);

});

});

}

void Interior::DoSomethingWithAnInt(int i)

{

mSomeClass->Pass(i);

}

}

int _tmain(int argc, _TCHAR* argv[])

{

cout << "Hello World." << endl;

N2::Interior theInterior;

theInterior.DoSomething();

return 0;

}

0 Kudos
3 Replies
Om_S_Intel
Employee
175 Views
I could not compile the test case. Could you please help me with stdafx.h and any other file that is required to compile it?
Georg_Z_Intel
Employee
175 Views
Hello,

Thank you for reporting this finding. I was able to reproduce it and filed a defect ticket for engineering (DPD200285602). As soon as I learn more I'll let you know.

As workaround I only can offer you to use capture by reference (theDispatcher.Dispatch([&](){...); at least it would fit to your example.

Best regards,

Georg Zitzlsberger
Georg_Z_Intel
Employee
175 Views
Hello,

this problem has been fixed for the next update release, Intel Composer XE 2011 Update 12.

Best regards,

Georg Zitzlsberger
Reply