Home Dashboard Directory Help
Search

C2326 on Lambdas with [this]-Capture by Arne Mertz


Status: 

Closed
 as Fixed Help for as Fixed


1
0
Sign in
to vote
Type: Bug
ID: 689504
Opened: 9/19/2011 10:23:36 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

Consider following code:

namespace n1 {
class far_away {
    struct data {};
};
} //ns n1

namespace n2 {
struct Data {
    int i;
};

struct Foo {
    Data* data;

    void bar() {
     auto callback = [this]() {
        data->i = 5; //(!)
     };
    }
};
} //ns n2

At the line marked with (!), MSVC complains with a C2326: error C2326: 'void n2::`anonymous-namespace'::<lambda0>::operator ()(void) const': function can not access 'n2::Foo::data'

Changing the access to this->data->i = 5; or renaming any of the two data's resolves the problem.
Apparently the name lookup gets confues with n1::far_away::data here, although its not mentioned in the error message.

Details
Sign in to post a comment.
Posted by Microsoft on 9/20/2011 at 8:52 AM
Hi Arne:
    A fix for this issue has been checked into the compiler sources. The fix should show up in the next release of Visual C++.

Xiang Fan
Visual C++ Team
Posted by MS-Moderator08 [Feedback Moderator] on 9/20/2011 at 1:08 AM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by MS-Moderator01 on 9/19/2011 at 10:42 AM
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.