When does overload resolution of non-dependent name take place, in definition context or point of instantiation?

怎甘沉沦 提交于 2019-12-05 12:23:41

In both context.

[temp.res] 14.6\8

If a hypothetical instantiation of a template immediately following its definition would be ill-formed due to a construct that does not depend on a template parameter, the program is ill-formed; no diagnostic is required. If the interpretation of such a construct in the hypothetical instantiation is different from the interpretation of the corresponding construct in any actual instantiation of the template, the program is ill-formed; no diagnostic is required.

[temp.nondep] 14.6.3\1

Non-dependent names used in a template definition are found using the usual name lookup and bound at the point they are used.

So both compilers are right.

If my understanding of the lookup rules are correct, then since g() is a non-dependent name, the overload set won't be added to in phase 2. Therefore the only choice for g(0) at the point of definition is g(long), and Clang is correct.

I would certainly naively expect only g(long) to be considered given the ordering of the definitions, but then again the C++ standard isn't always intuitive when templates are involved...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!