【问题标题】:Is this a known VC14 bug这是一个已知的 VC14 错误吗
【发布时间】: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;
}

【问题讨论】:

标签: c++ visual-studio-2015


【解决方案1】:

那肯定是VC14的模板参数推导代码的bug。

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

template<class T1, class T2, class Cont>
void
fails(T1, 
      Poly<T2, Cont> *)
{}

我已使用online Visual C++ compiler 进行了验证。不幸的是,无法链接到测试用例like what we would do on Ideone.com (click to see the compilation with g++-5.1)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-30
    • 2012-09-18
    • 2012-03-25
    • 2010-12-22
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多