c++ – 令人困惑的模板错误
问题:
我一直玩clang一段时间,我偶然发现了“test / SemaTemplate / dependent-template-recover.cpp”(在clang发行版中),它应该提供从模板错误中恢复的提示。
整个过程可以很容易地删除到一个最小的例子:
template<typename T, typename U, int N> struct X {
void f(T* t)
{
// expected-error{{use 'template' keyword to treat 'f0' as a dependent template name}}
t->f0<U>();
}
};
clang产生的错误消息:
tpl.cpp:6:13: error: use 'template' keyword to treat 'f0' as a dependent template name
t->f0<U>();
^
template
1 error generated.
…但是我很难理解究竟应该在哪里插入template
关键字以使代码在语法上正确?
I’ve been playing with clang a while, and I stumbled upon “test/SemaTemplate/dependent-template-recover.cpp” (in the clang distribution) which is supposed to provide hints to recover from a template error.The whole thing can be easily stripped down to a minimal example:The error message yielded by clang:… But I have a hard time understanding where exactly one is supposed to insert the template
keyword to have the code to be syntactically correct?