【发布时间】:2016-12-20 09:08:50
【问题描述】:
考虑这个最小的例子:
template<class X> struct foo;
template<>
struct foo<int>
{
template<class = void>
static constexpr int x = 0;
};
template<class T>
constexpr int foo<int>::x<T>;
最后两行是必需的,否则当变量 x 被 ODR 使用时,我们将得到一个未定义的引用。
虽然 gcc (6.2.1) 很乐意编译此代码,但 clang (3.9.0) 在最后一行失败并显示以下神秘消息:
错误:变量模板部分特化不特化 任何模板参数;要定义主模板,请删除 模板参数列表
哪一个是正确的行为?
【问题讨论】: