从xlC的模板函数问题查找静态函数 [英] static function lookup from a template function issue with xlC

查看:290
本文介绍了从xlC的模板函数问题查找静态函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我搜索关于我在源代码中遇到的编译问题的线索时,我遇到了这个错误报告(针对Mozilla的JavaScript引擎源)与函数查找相关。引用来自错误报告:

While I was searching for clues about a compilation problem I have had in my source, I have come across this bug report (against Mozilla's JavaScript engine source) related to functions lookup. Quoting from the bug report:


TypedArrayTemplate(显然)是一个模板,它引用INT_TO_JSVAL,一个静态内联函数,与::。这会中断xlC,因为它无法解析INT_TO_JSVAL。如果在模板参数的上下文中找不到非限定名称,那么该标准不要求考虑静态。

TypedArrayTemplate is (obviously) a template, and it is referencing INT_TO_JSVAL, a static inline function, without prefixing it with "::". This breaks xlC because it can not resolve INT_TO_JSVAL. The standard does not require that statics be considered if the unqualified name is not found in the context of the template arguments. g++ does this fallback, xlC does not.

来自编译器的信息性消息:

Informative message from the compiler:

(I) Static declarations are not considered for a function call if the function is not qualified.

在我的例子中,失败的代码类似于:

In my case the code that was failing was similar to this:

namespace N
{

static bool foo (std::string const &);

template <typename T>
void bar (T const &, std::string const & s)
{
    // expected unqualified call to N::foo()
    foo (s);
}

void baz (std::string const & s)
{
    bar (s);
}

} // namespace N

xlC实现真的正确吗?

Is the behaviour that xlC implements really correct? Where does the 2003 or 2011 standard talk about this?

推荐答案

在C ++ 11之前,这是正确的行为:unqualified name模板中使用的名称的解析被定义为仅查找具有外部链接的函数。

Prior to C++11 this was the correct behavior: unqualified name resolution of names used in templates was defined to only find functions with external linkage.

C ++ 03 section 14.6.4.2候选函数[temp.dep.candidate] :

C++03 section 14.6.4.2 Candidate Functions [temp.dep.candidate] paragraph 1:


对于依赖于模板参数的函数调用,如果函数名称是非限定ID,而不是
template-id,使用通常的查找规则(3.4.1,3.4.2)找到候选函数,除了:

For a function call that depends on a template parameter, if the function name is an unqualified-id but not a template-id, the candidate functions are found using the usual lookup rules (3.4.1, 3.4.2) except that:


  • 对于使用非限定名称查找(3.4.1)的查找部分,仅找到具有模板定义上下文的外部
    链接的函数声明。

  • For the part of the lookup using unqualified name lookup (3.4.1), only function declarations with external linkage from the template definition context are found.

对于使用关联命名空间(3.4.2)的查找部分,只找到在模板定义上下文或模板实例化上下文中找到的外部
链接的函数声明。

For the part of the lookup using associated namespaces (3.4.2), only function declarations with external linkage found in either the template definition context or the template instantiation context are found.

将C ++ 11更改为:

which changes in C++11 to:

对于依赖于模板参数的函数调用,使用通常的
查找规则(3.4.1,3.4.2,3.4.3)找到候选函数,除了:

For a function call that depends on a template parameter, the candidate functions are found using the usual lookup rules (3.4.1, 3.4.2, 3.4.3) except that:


  • 对于使用未限定名称查找(3.4.1)或限定名称查找(3.4.3)只有
    从模板定义上下文中找到函数声明。

  • For the part of the lookup using unqualified name lookup (3.4.1) or qualified name lookup (3.4.3), only function declarations from the template definition context are found.

对于使用关联命名空间

这篇关于从xlC的模板函数问题查找静态函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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