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

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 689504 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 9/19/2011 10:23:36 AM
Access Restriction Public


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.

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)