为什么下面的代码可以编译?我没有特化模板类的模板成员函数,所以只有一个 template<>
应该使用。然而,g++ 编译时没有任何警告,clang++ 只给出警告
warning: extraneous template parameter list in template specialization
template<typename T>
struct S{};
template<> template<> // why can we do this?
struct S<int>{};
int main()
{
}
最佳答案
因为语法允许,模板特化部分下好像也没有什么禁止的:
来自 [gram.temp]
explicit-specialization:
template < >
declaration
来自 [gram.dcl]
declaration:
[...]
explicit-specialization
语法过于松懈的事实已经在active issues list (#293) 自 2001 年以来。
关于c++ - 模板特化中的双模板<>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30927196/