在定义上下文或实例化点中,何时进行非依赖名称的重载解析? [英] When does overload resolution of non-dependent name take place, in definition context or point of instantiation?

查看:40
本文介绍了在定义上下文或实例化点中,何时进行非依赖名称的重载解析?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

3.4 [basic.lookup]/p1

3.4 [basic.lookup]/p1

名称查找成功后,将进行重载解析(13.3).

Overload resolution (13.3) takes place after name lookup has succeeded.

void g(long);

void g(int, int);

template<class T> void f() { g(0); }

void g(int, int = 0) {}

int main(){
    f<int>();
}

gcc编译成功,clang失败.

gcc compiles succeed, clang faild.

何时在定义上下文或实例化点进行非依赖名称的重载解析?还是两者都对?

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

推荐答案

在这两种情况下.

[温度] 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.

[温度不降温] 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.

这篇关于在定义上下文或实例化点中,何时进行非依赖名称的重载解析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆