英文:
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
以下是翻译好的部分:
> 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.(因此接受此语法是错误的。)
英文:
> 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论