Unexpected behaviour of this capture in a lambda expression - by Matthew Bradbury

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.


2
0
Sign in
to vote
ID 713679 Comments
Status Closed Workarounds
Type Bug Repros 1
Opened 12/13/2011 5:51:34 AM
Access Restriction Public
Moderator Decision Sent to Engineering Team for consideration

Description

Extra qualification of class members is needed in a lambda expression capturing this, when the member name is the same as a global function.
Sign in to post a comment.
Posted by Microsoft on 4/29/2014 at 12:24 PM
Thank you for reporting this issue. This issue has been fixed in Visual Studio 2013. You can install a trial version of Visual Studio 2013 with the fix from: http://go.microsoft.com/?linkid=9832436
Posted by Jim Barry on 2/8/2012 at 5:00 AM
I just ran into this bug myself, in VC10. It's particularly nasty when a member function has the same name and parameters as an existing nonmember function. The program compiles, but the nonmember function is called instead of the member function. I think this is quite bad.

Example:

#include <iostream>

void f()
{
std::cout << "Called ::f()" << std::endl;
}

struct S
{
void f()
{
    std::cout << "Called S::f()" << std::endl;
}

void oops()
{
    [this](){ f(); }(); // calls the wrong function
}
};

int main()
{
S().oops();
}
Posted by MS-Moderator09 [Feedback Moderator] on 12/13/2011 at 11:45 PM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for review. We will contact you if we require any additional information.
Posted by MS-Moderator01 on 12/13/2011 at 6: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)