Question on visible scope in template declaration

Carl Lei xecycle@gmail.com
Tue Dec 15 03:36:00 GMT 2015


在 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



More information about the Gcc mailing list