Template disambiguator accepted for non-template function.

huangapple go评论79阅读模式
英文:

Template disambiguator accepted for non-template function

问题

这段代码在GCC(甚至版本13.1和主干版本)中被接受,但在clang中被拒绝。接受它似乎是错误的(setNumber不是一个模板函数),所以我认为这是GCC中的一个错误。有人能引用明确说明这一点的相关章节和段落吗?

我尝试在GCC的Bugzilla中搜索“disambiguator”,但只找到无关的错误。

英文:

This code

template <typename U>
struct Bar{
    void setNumber(int) {}
};

template <int N>
struct Asd : public Bar<Asd<N>>{
    void doSomething();
};

template<int N>
inline void Asd<N>::doSomething() {
    this->template setNumber(N);
}

int main() {
    Asd<42> obj;
    obj.doSomething();
}

is accepted by GCC (even 13.1 and trunk) but rejected by clang (<https://godbolt.org/z/xbs8GqG7h>).
Accepting it seems wrong (setNumber is not a template function) so I believe this is a bug in GCC. Can somebody quote chapter and verse that makes this explicit?

I tried searching the GCC bugzilla for "disambiguator", but got only unrelated bugs.

答案1

得分: 5

以下是翻译好的部分:

[temp.names]/6:

> A name prefixed by the keyword template shall be followed by a template argument list or refer to a class template or an alias template.

Here the name setNumber

  • is not followed by a template argument list;(未跟随模板参数列表)
  • does not refer to a class template;(不指向类模板)
  • does not refer to an alias template.(不指向别名模板)

So it's wrong to accept this syntax.(因此接受此语法是错误的。)

英文:

[temp.names]/6:

> A name prefixed by the keyword template shall be followed by a template argument list or refer to a class template or an alias template.

Here the name setNumber

  • is not followed by a template argument list;
  • does not refer to a class template;
  • does not refer to an alias template.

So it's wrong to accept this syntax.

huangapple
  • 本文由 发表于 2023年6月18日 18:25:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76500060.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定