【发布时间】:2015-08-27 16:35:11
【问题描述】:
下面的代码给了我一个编译错误。
$ cl.exe VC14-bug.cpp
Microsoft (R) C/C++ 优化编译器版本 19.00.23026 for x64
版权所有 (C) Microsoft Corporation。保留所有权利。
VC14-bug.cpp
VC14-bug.cpp(41): error C2893: 无法专门化函数模板'void failed(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;
}
【问题讨论】:
-
老实说,VC 错误报告的位置错误。
-
您确定这是一个错误,而不仅仅是 microsoft c++11 兼容性中缺少的功能吗?您是否尝试过明确指定失败的类型并查看它是否有效?
-
如果没有人可以重现它,它可能仍然是错误的代码。我也发在这里了:social.msdn.microsoft.com/Forums/vstudio/en-US/…
-
我找不到代码有什么问题,而且它在 Clang 和 GCC 上编译,所以我认为这是 MSVC 中的一个错误。报告Connect。