Bug with operator overloading and nested lambdas - by Bengt Gustafsson

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 634671 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 1/5/2011 1:24:48 AM
Access Restriction Public


The code below does not compile. The error is on the messy line of the second half of the function. The exact same messy line in the first half compiles. The only difference is that in the second half the enclosing compound statement is a lambda body while in the first half it is just a nested block.

Given the nature of the error message (and the newness of the lambda implementation) I would deduce that this is a compiler bug relating to the nesting of the lambdas. I can't see any reason that the line would compile differently inside an outer lambda, as no new names or operators are introduced.

class Class {
	template<typename F> void operator<<(const F& func) {}

template<typename R> R& operator-(const char* lhs, R& rhs) { return rhs; }

void click(Class& button)

void test()
		Class b;
		b << click;
		"Test" - b << click;

	  "Test"-[&]()->Class& { return *new Class; }() << click;

	[&]() {
		Class b;
		b << click;
		"Test" - b << click;

	  "Test"-[&]()->Class& { return *new Class; }() << click;

Note that this code seems rather unuseful, but I have of course boilt it down from a more fleshed out example that actually does make sense.
Sign in to post a comment.
Posted by Microsoft on 2/4/2011 at 1:20 PM
    The root cause of the issue is the same as http://connect.microsoft.com/VisualStudio/feedback/details/634688.
    We have fixed that one recently.

Xiang Fan
Visual C++ Compiler Team
Posted by Microsoft on 1/18/2011 at 3:37 PM

Thanks for reporting this issue. We do have lots of issues with nested lambdas in our compiler, and we are working on improving them for next release. The standard did make some late changes around nested lambdas which contributed greatly in having a low quality in this specific area of the compiler.

Ulzii Luvsanbat
Windows C++ Team
Posted by Bengt Gustafsson on 1/5/2011 at 5:47 AM
Note: This is probably caused by the bug I reported later as: 634688
Posted by Microsoft on 1/5/2011 at 1:26 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)