This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Question on visible scope in template declaration


å 12/15/15 11:09, Andrew Pinski åé:
On Mon, Dec 14, 2015 at 7:01 PM, Carl Lei <xecycle@gmail.com> wrote:
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.

There is also argument dependent lookup.

Yes, I am aware of that, and I worked around this problem by adding an empty struct as a tag for ADL to my function signatures. But whether g should be found in the first phase before ADL is another question.

--
Carl Lei (XeCycle)
Department of Physics and Astronomy, SJTU


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]