Skip to main content
GameDev.net gamedev.net
🔒 Locked

C++0x: Nested lambdas and templates

Started by Cerasti Jan 1, 2010 at 5:57 PM 0 replies 2.1k views
Original Post
Cerasti
Cerasti
I'm trying out the new C++0x features available in Visual Studio 2010 Beta 2, in particular the lambda expressions. I have however come across a curious error: in nested lambda functions, template parameters cease to exist. They do work in non-nested lambdas though. This code illustrates the problem which, to me, appears to be a bug in the compiler. I hope that I'm wrong.

template <typename T>
void f()
{
	T x; // Works fine
	[](){
		T y; // As does this one
		[](){
			T z; // Not this one
		};
	};
}

int main()
{
	f<int>();
}

// error C2065: 'T' : undeclared identifier
// error C2146: syntax error : missing ';' before identifier 'z'
// error C3493: 'z' cannot be implicitly captured because no default capture mode has been specified

Odd?
Metsan
Metsan
It certainly seems to be a bug in MSVC. Your code compiles fine with the Intel C++ Compiler.

You might want to tell Microsoft about it (I've just made a quick search on Google and Microsoft Connect and apparently this has not been discussed before).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.