【发布时间】:2016-05-13 17:40:16
【问题描述】:
考虑以下代码:
template <class T, class U, class V>
struct Foo { };
template <class T, class U>
struct Foo<T, U, std::integral_constant<int, U::value>> {
static void print()
{
std::cerr << "instantiated";
}
};
template <class U>
struct Foo<double, U, std::integral_constant<int, U::value>> {
static void print()
{
std::cerr << "instantiated special";
}
};
struct Bar {
static const int value = 0;
};
int main(int argc, char ** argv)
{
using Baz = Foo<double, Bar, std::integral_constant<int, 0>>;
Baz::print();
return 0;
}
当我使用 icc 16.0.1 编译它时,我收到以下消息:
main.cpp(38): error: more than one partial specialization matches the template argument list of class "Foo<double, Bar, std::integral_constant<int, 0>>"
"Foo<T, U, std::integral_constant<int, U::value>>"
"Foo<double, U, std::integral_constant<int, U::value>>"
Baz::print();
使用 clang 3.7.1 和 gcc 5.3.0 编译(并打印“实例化特殊”)。这是 icc 中的错误,还是我的代码不正确?对我来说,第二个专业化似乎比第一个专业化更加专业化。除了锁定第一个模板参数之外,它与第一个相同。
编辑:我应该补充:如果这是 icc 中的错误,有没有好的解决方法?
【问题讨论】:
-
在我看来确实像 icc 中的一个错误。
-
您能否检查comments below 中的建议是否解决了ICC 上的问题?当然,这并不能完全解决您的问题,只是在调查中向前迈出了一步。
-
在实际代码中,整数来自U的嵌套成员,这反过来又给clang带来了问题,所以我的同事从非类型转换为类型模板参数。