Edit:
This is indeed a bug in the compiler, I've opened a defect and got the following response.
Hello Motti,
Thank you for submitting this issue. As noted in the stackoverflow posting, this is a bug in our decltype implementation. Unfortunately, we cannot fix this bug in the next release of Visual Studio since the code is relatively uncommon, and we are particularly resource constrained.
Original question follows
I'm playing around with the C++0x features of VS10 and I ran into the following problem.
std::map<int, int> map()
{
return std::map<int, int>();
}
template <class F>
auto call(F f) -> decltype(f())
{
auto ret = f();
return ret;
}
void check()
{
auto m = call(map);
}
I get the following warning:
warning C4172: returning address of local variable or temporary
However when I change the prototype of call
to be the old style:
std::map<int, int> call(F f)
It's fine, it's also OK when call
is not a template function (even when using deduced return types).
If I look at the type of ret
it's std::map<int, int>
(no references or pointers).
Is this a bug in VS10 or am I missing something.