I'm trying to use C++0x, and in particular lambda expression and decltype to simplify some of my code, using the MSVC10 RC compiler.
I've run into the following very odd problem:
template <typename F>
auto foo(F f) -> decltype(f()){
return f();
}
template <typename F>
void bar(F f){
f();
}
int main() {
bar([](){
foo([]() { }); // error C2893: Failed to specialize function template ''unknown-type' foo(F)'
});
}
As indicated in the comment, the compiler generates an error on the line foo([]() { })
.
I hate to shout "compiler bug", but I really can't see any good explanation for this error.
Apparently, while inside the outer lambda expression, the compiler can not specialize the foo
function template for the inner lambda.
However, if the definition of foo
is changed to hardcode the return type, like this:
template <typename F>
void foo(F f){
return f();
}
then everything compiles just fine.
Is there some obscure quirk of decltype when used to deduce the return type of lambda expression parameters inside the scope of another lambda that I'm not aware of?