Search

Lambda declaration cannot access closure variables when defined as a member function of an inline class by Adaptation

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 581680
Opened: 7/30/2010 10:30:05 AM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
A Lambda function declared within a member function of an inline class complains that it cannot access the closure variables. Example given in steps to reproduce.

Notes:
* Moving the class outside of the function declaration compiles fine
* Having no arguments for the lambda compiles fine
Details (expand)

Visual Studio/Silverlight/Tooling version

Visual Studio 2010

What category (if any) best represents this feedback?

 

Steps to reproduce

#include <functional>
#include <iostream>

int main( ) {
    
    struct InlineStruct {
        static void AddF( const std::function< int( int ) >& func ) {
            std::cout << func( 1 ) << '\n';
        }
        static void AddI( int a ) {
            AddF( [a]( int c ) { return a + c; } );
        }
    };
    
    InlineStruct::AddI( 2 );
    
    return 0;
}

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

error C2326: 'void main::InlineStruct::AddI(int)' : function cannot access 'a'

Expected results

Program to compile and output the number 3.
File Attachments
File Name Submitted By Submitted On File Size  
main.cpp 7/30/2010 331 bytes
Sign in to post a comment.
Posted by Microsoft on 8/1/2010 at 10:14 PM
Thanks for your feedback. We are routing 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.
Posted by Microsoft on 7/30/2010 at 5:10 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.