Hello list,
The following code is rejected by GCC but accepted by Clang:
template <class T>
auto f(T v) -> decltype(g(v));
int g(int) { return 0; }
template <class T>
auto f(T v) -> decltype(g(v))
{
return g(v) + 1;
}
int main()
{
return f(0);
}
Error message at http://ideone.com/Vn79Hm.
Basically the problem comes down to which is the visible scope in that
trailing return type decltype(g(v)), where GCC uses the point of
declaration but Clang uses the point of definition. g is a dependent
name here, and the standard says "template definition context" should be
used; but I am not very sure about the wording. I suspect this to be a
GCC bug, but not sure, so asking here first.
--
Carl Lei (XeCycle)
Department of Physics and Astronomy, SJTU