Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
7679 Discussions

## Lmbda-related error

Valued Contributor I
148 Views

[bash]struct X
{
X() {}
X(X const& obj) {}
~X() {}
void operator = (X const&) {}
void exec() const {}
};

template
void exec(T f)
{
f();
}

int main()
{
X t;
exec([=](){t.exec();});
}

[/bash]

In Win32 configuration compiles successfully, but in x64 configuration I get the following error:

Compiling with Intel C++ Compiler 11.1.071 [IA-32]... (Intel C++ Environment)

.\\lambda_bug.cpp(55): error: class "X" has no suitable copy constructor
X t;
^
detected during implicit generation of "__lambda1::(const X &)" at line 56

9 Replies
New Contributor II
148 Views

Looks like you are using Composer Update3.

Please check whether works . For me, its working on Intel64 though withC++ Pro 11.1.054 . I did not check for Composer. If still does not work, it should be compiler bug, and should be escalated.

Valued Contributor I
148 Views

Of course I set Enable C++0x Support = Yes (/Qstd=c++0x) before working with lambdas. And yes, it's Parallel Studio SP1.

Black Belt
148 Views

Also error message is wrong

\lambda_bug.cpp(55): error: class "X" has no suitable copy constructor
X t;
^
detected during implicit generation of "__lambda1::(const X &)" at line 56

... "__lambda1::(const volatile X &)" at line 56

The incorrect error message had me blank staring at code for several hours.

Jim Dempsey

Black Belt
148 Views

Jennifer,

I added to my copy constructor a defensive validator and code to correct the errant input arg should it fail verification (and verify assumed corrected reference, _ASSERT if uncorrectable).

T(const volatile T& ref);

The compiler is calling

T(volatile T& ref);

The code I added can be conditionalized in or out. Excepting for line breaks and (conditionalize out code). The new copy of the code "should" compile the same as yesterdays code. But it does not.

My guess is the compiler is using Lambda functions and a reference to a token is getting screwed-up. The junk being used for the token is flipping the choice of copy constructors.

Jim Dempsey

Employee
148 Views
I can reproduce the problem with Intel Parallel Composer both update 3 and update 5. Curiously, there is no problem with 11.1 pro. You're likely right, Jim, but let me investigate further to confirm the problem, and I'llupdate this thread on my status.
Employee
148 Views
Ok, so it turns out I can reproduce this with 11.1 pro, but only with the 32-bit hosted compiler targeting Intel 64 architecture. Really odd issue, but I've reported this to our front-end team, and I will keep you up to date on their status here. How blocked are you guys on this issue? I've got it set with a customer impact of High (which is to quickly summarize "I can survive for now, but fix asap please"), but I can bump it up to Showstopper (i.e. "I can't do anything with your compiler until this is fixed") if necessary.
Black Belt
148 Views

Brandon,

It is not a show stopper for me since I've written code to on-the-fly fix the error (when error present). A little slower execution. I've just downloaded the Parallel Composer update 5, but haven't installed. I do not know if this problem is present or not in update 5.

Jim Dempsey

Employee
148 Views

I've reproduced the problem on update 5 as well.

A workaround suggested by our front-end team is to use a reference lambda instead of copying i.e.:

[cpp]exec([&](){t.exec();});[/cpp]

We are lookinginto fixing this for the next major compiler version. If a fix in 11.1 or the current Intel Parallel Composer is needed, let me know.

Employee
148 Views
Hi all,

This issue is resolved in the 12.0 compiler that's part of Intel Parallel Composer 2011 and Composer XE 2011 products. Let us know if there's any problems.