This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Question on visible scope in template declaration
- From: Andrew Pinski <pinskia at gmail dot com>
- To: Carl Lei <xecycle at gmail dot com>
- Cc: GCC Mailing List <gcc at gcc dot gnu dot org>
- Date: Mon, 14 Dec 2015 19:09:51 -0800
- Subject: Re: Question on visible scope in template declaration
- Authentication-results: sourceware.org; auth=none
- References: <566F8273 dot 6080904 at gmail dot com>
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.
Thanks,
Andrew Pinski
>
> --
> Carl Lei (XeCycle)
> Department of Physics and Astronomy, SJTU