本文介绍了函数模板中的依赖名称查找:clang rejects,gcc accept的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! 请考虑以下片段:struct X { };namespace foo { template <class T> void bar() { T{} < T{}; } void operator<(const X&, const X&) {}}int main() { foo::bar<X>();} $ bclang rejects this code, gcc accepts it. Is this a gcc bug or is this a clang bug?推荐答案我相信这是一个gcc错误,以 70099 。从[temp.dep.res]:I believe this is a gcc bug, filed as 70099. From [temp.dep.res]: 在解析依赖名称时,会考虑以下来源的名称: $ b $ (1.2) - 与来自实例化上下文(14.6.4.1)的函数参数类型相关联的命名空间的声明 - 和定义上下文。 In resolving dependent names, names from the following sources are considered: (1.1) — Declarations that are visible at the point of definition of the template. (1.2) — Declarations from namespaces associated with the types of the function arguments both from the instantiation context (14.6.4.1) and from the definition context. foo :: operator<() isn在模板的定义点可见,并且不在函数参数的相关命名空间中( X 的关联命名空间只是全局命名空间 :: )。所以我认为gcc是错误的找到 foo :: operator< 和clang是正确的拒绝代码。foo::operator<() isn't visible at the point of definition of the template, and isn't in an associated namespace from the function arguments (X's associated namespace is just the global namespace ::). So I think gcc is wrong to find foo::operator< and clang is correct to reject the code. 这篇关于函数模板中的依赖名称查找:clang rejects,gcc accept的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-06 08:27