Home Dashboard Directory Help
Search

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


Status: 

Closed
 as Fixed Help for as Fixed


1
0
Sign in
to vote
Type: Bug
ID: 788701
Opened: 5/27/2013 1:00:59 PM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description


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);

or

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.

Details
Sign in to post a comment.
Posted by Microsoft on 6/4/2013 at 5:27 PM
Hi,

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
stl@microsoft.com
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 Microsoft 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(http://support.microsoft.com)
Sign in to post a workaround.
File Name Submitted By Submitted On File Size  
lambda_bug.zip (restricted) 5/28/2013 -