加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 从xlC的模板功能问题的静态函数查找

发布时间:2020-12-16 03:12:26 所属栏目:百科 来源:网络整理
导读:当我在寻找有关我的源代码中的编译问题的线索时,我已经遇到了与功能查找相关的这个 bug report (against Mozilla’s JavaScript engine source).引用错误报告: TypedArrayTemplate is (obviously) a template,and it is referencing INT_TO_JSVAL,a static
当我在寻找有关我的源代码中的编译问题的线索时,我已经遇到了与功能查找相关的这个 bug report (against Mozilla’s JavaScript engine source).引用错误报告:

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.

来自编译器的信息消息:

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

在我的情况下,失败的代码与此类似:

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实现的行为是否正确? 2003年或2011年标准在哪里谈论?

解决方法

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

C 03 section 14.6.4.2候选函数[temp.dep.candidate]第1段:

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:

  • 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.

  • 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变化为:

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:

  • 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.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读