下面的代码给了我一个编译错误。
$ cl.exe VC14 14-bug.cpp 微软(R) C/C++优化编译器版本19.00.23026用于x64 版权(C)微软公司。版权所有。 VC14-bug.cpp VC14-bug.cpp(41):error C2893:未能专门化函数模板'void (T1,Poly> *)‘ VC14-bug.cpp(41):注意:带有以下模板参数: VC14-bug.cpp(41):注:'T1=int‘ VC14-bug.cpp(41):注:'T2=Kernel‘
造成问题的是函数f()。有人能复制吗?
template <typename T>
struct Container
{};
struct Kernel {
typedef int Nested;
};
template <class K,
class C = Container<typename K::Nested*> >
struct Poly
{};
// if f() gets commented it compiles
template<class T>
Poly<T>*
f()
{
return 0;
}
//template<class T2, class T1> // this compiles
template<class T1, class T2>
void
fails(T1,
Poly<T2> *)
{}
// if f() is moved here it also compiles
int main()
{
Poly<Kernel> * poly = 0;
fails(0, poly);
return 0;
}发布于 2015-08-28 08:45:55
这无疑是VC14的模板参数演绎代码中的一个错误。
一个可能的解决方法是允许Poly的所有类型的容器,在fails中。
template<class T1, class T2, class Cont>
void
fails(T1,
Poly<T2, Cont> *)
{}我已经使用在线可视化C++编译器进行了验证。不幸的是,我们不能链接到测试用例就像我们在Ideone.com上所做的那样(单击查看g++-5.1编译)。
https://stackoverflow.com/questions/32255000
复制相似问题