首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >这是已知的VC14错误吗?

这是已知的VC14错误吗?
EN

Stack Overflow用户
提问于 2015-08-27 16:35:11
回答 1查看 261关注 0票数 0

下面的代码给了我一个编译错误。

$ 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()。有人能复制吗?

代码语言:javascript
复制
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;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-28 08:45:55

这无疑是VC14的模板参数演绎代码中的一个错误。

一个可能的解决方法是允许Poly的所有类型的容器,在fails中。

代码语言:javascript
复制
template<class T1, class T2, class Cont>
void
fails(T1, 
      Poly<T2, Cont> *)
{}

我已经使用在线可视化C++编译器进行了验证。不幸的是,我们不能链接到测试用例就像我们在Ideone.com上所做的那样(单击查看g++-5.1编译)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32255000

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档