Home Dashboard Directory Help
Search

[c++] Nested lambda functions lose scope by Cory Nelson


Status: 

Closed
 as Fixed Help for as Fixed


5
0
Sign in
to vote
Type: Bug
ID: 537366
Opened: 2/28/2010 4:57:17 AM
Access Restriction: Public
1
Workaround(s)
view
1
User(s) can reproduce this bug

Description

When a lambda function is nested inside another lambda function, the inner one loses the scope of the enclosing block.
Details
Sign in to post a comment.
Posted by pauljurczak on 7/7/2011 at 1:34 AM
I'm using the most current version of VS2010 and this bug seems to be still there (workaround works). Can it get pushed a notch up on the list of priorities? Lambdas are being heavily evangelized by Microsoft and this is a pretty fundamental use case being affected.
Posted by AceHack on 11/11/2010 at 9:05 PM
I'm also having this problem but I just posted a work around. Hope it works for everyone else. Thanks.
Posted by Microsoft on 4/20/2010 at 9:56 AM
Hi: a fix for this issue has been checked into the compiler sources. The fix should show up in a future release of Visual C++.

Jonathan Caves
Visual C++ Compiler Team
Posted by Microsoft on 2/28/2010 at 11:41 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.

Thank you
Posted by Microsoft on 2/28/2010 at 7:07 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)
Posted by Cory Nelson on 2/28/2010 at 4:59 AM
yikes, repro steps lost formatting. attached a .cpp
Sign in to post a workaround.
Posted by AceHack on 11/11/2010 at 9:03 PM
I think this should help you out. It worked for me.

int testCapture = 0;
std::vector<std::vector<int>> dVector;
std::for_each(dVector.begin(), dVector.end(),
[&testCapture] (std::vector<int> vector)
{
    int& innerTestCaptureWorkaround = testCapture;
    std::for_each(vector.begin(), vector.end(),
    [&innerTestCaptureWorkaround] (int currentValue)
    {
        ...
    });
});

I know this is a real pain, it would be better if it was fixed but until then this is what I'm using.
File Name Submitted By Submitted On File Size  
funtest.cpp (restricted) 2/28/2010 -