gpt4 book ai didi

c++ - Clang:模板推导失败 'double' 与 ''

转载 作者:可可西里 更新时间:2023-11-01 16:22:37 24 4
gpt4 key购买 nike

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

#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<double> , 是 <double>例如,意味着代表一个未打包的 arglist?

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

参见 DPD200244439 Intel® Composer XE 2013 SP1 Compilers Fixes List

最佳答案

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

正如 gha.st 指出的那样, 跳过 template using 并直接使用 native 函数类型:

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

我已针对此提交错误 here .

关于c++ - Clang:模板推导失败 'double' 与 '<double>',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23608857/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com