【问题标题】:Clang: Template deduction failed 'double' vs '<double>'Clang:模板推演失败 'double' vs '<double>'
【发布时间】:2014-06-29 19:19:39
【问题描述】:

考虑以下代码,它使用带有可变参数的函数:

#include <iostream>

// Typedef function type
template<typename... Output>
using Func = void(Output*...);

// Function runner
template<typename... Output>
void run_func(Func<Output...>& func, Output*... output) {
  for (int i=0 ; i < 10 ; ++i) {
    func(output...);
  }
}

void f(double* d) {
  *d *= 2;
};

int main() {
  double value = 1.0;
  run_func(f, &value);
  printf("%f\n", value);
}

使用 g++ 4.7.3 编译它可以正常工作,并且运行会按预期生成 1024.0

使用 icpc 14.0.2 编译会崩溃...

templ.cc(21): internal error: assertion failed: lower_expr: bad kind (shared/cfe/edgcpfe/lower_il.c, line 18582)

    run_func(f, &value);
    ^

使用 clang 3.5.0-1 编译会出现以下错误消息:

templ.cc:21:3: error: no matching function for call to 'run_func'
  run_func(f, &value);
  ^~~~~~~~
templ.cc:9:6: note: candidate template ignored: deduced conflicting types for parameter 'Output' ('double' vs. <double>)
void run_func(Func<Output...>& func, Output*... output) {
     ^

这是一个错误,还是应该让 g++ 没有编译这个?

为什么 clang 会推断出 double&lt;double&gt; 的这些“冲突”类型,例如,&lt;double&gt; 是否意味着代表一个解压缩的 arglist?

更新 icpc 14.0.3不崩溃,程序编译运行正常。

请参阅 DPD200244439 Intel® Composer XE 2013 SP1 Compilers Fixes List

【问题讨论】:

  • 您的最后一个问题可以通过传递 run_func(f,&value,&value)... 来回答自己,这会导致 我认为不正确...您可能想要尝试使用来自 svn 的更新的 clang,它闻起来像一个错误
  • 由于用原生类型替换template using 可以解决问题,感觉很像一个bug。
  • @PlasmaHH 我试过 clang 版本 3.5.0 (trunk 208562),同样的问题!
  • 更新版本的icpc修复了这个问题
  • @WaelJ:在这种情况下,我建议您向 Clang 团队报告错误。 3.5 快到了,如果他们能在它消失之前解决这个问题,那就太酷了。

标签: c++ templates c++11 clang function-templates


【解决方案1】:

经过上面的讨论,看来这确实是clang中的一个bug。

正如gha.st 所指出的,跳过template using 并直接使用本机函数类型可以:

void run_func(void (&func)(Output*...), Output*... output) {

我对此here 提出了一个错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-18
    • 2015-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多