lambda value capture of std::cref reference_wrapper combined with placement new in called function results in C2558 - by valoh

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 788701 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 5/27/2013 1:00:59 PM
Access Restriction Public


I get

error C2558: class 'StartMain::<lambda_a86c18285b49591e30a6c84aaa2ff447>' : no copy constructor available or copy constructor is declared 'explicit'

with something like:

template <typename FUNC>
void Create(void* buffer, const FUNC& func)
   new (buffer) FUNC(func);

and calling it like:

int a_ = 23;
auto a = std::cref(a_);

auto closure = [=]() { std::cout << a.get(); };
char buffer[1024];
Construct((void*)buffer, closure);

the combination of the captured reference_wrapper and the placement new in the called function seem to trigger the error. following variants compile without errors:

auto closure = [=]() { std::cout << a_;  }; // no reference_wrapper
char buffer[1024];
Construct((void*)buffer, closure);


auto closure = [=]() { std::cout << a.get(); }; // reference_wrapper
char buffer[1024];
// but directly using placement new, not function with const reference to closure
new ((void*)buffer decltype(closure)(closure);

all variants compile without problems under clang.

Sign in to post a comment.
Posted by Deon [MSFT] on 4/29/2014 at 12:30 PM
Thank you for reporting this issue. This issue has been fixed in Visual Studio 2013. You can install a trial version of Visual Studio 2013 with the fix from:
Posted by Stephan [MSFT] on 6/4/2013 at 5:27 PM

Thanks for reporting this bug. We've already fixed it, and the fix will be available in VS 2013 Preview.

Stephan T. Lavavej
Senior Developer - Visual C++ Libraries
Posted by Microsoft on 5/30/2013 at 2:37 AM
Hi valoh, thanks for your response. Your issue has been routed to the appropriate VS development team for investigation.
Posted by valoh on 5/28/2013 at 2:13 PM
ok, I added a simple visual studio 2012 project showing the compile error. The same thing compile under clang without problems.
Posted by Microsoft on 5/27/2013 at 8:38 PM
Thank you for submitting feedback on Visual Studio and .NET Framework. In order to efficiently investigate and reproduce this issue, we are requesting a demo project. We look forward to hearing from you with this information.
Posted by Macy [MSFT] on 5/27/2013 at 1:50 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(