10

Consider the following code, which uses a function with variable arguments:

#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);
}

Compiling this with g++ 4.7.3 works fine, and running produces 1024.0 as expected.

Compiling using icpc 14.0.2 crashes it...

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

    run_func(f, &value);
    ^

Compiling with clang 3.5.0-1 gives the following error message:

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) {
     ^

Is this a bug, or should have g++ not compiled this?

Why is clang deducing these "conflicting" types of double and <double>, is <double> meant to represent an unpacked arglist for example?

Update icpc 14.0.3 does not crash, and the program compiles and runs correctly.

See DPD200244439 at Intel® Composer XE 2013 SP1 Compilers Fixes List

7
  • Your last question you could answer yourself by passing run_func(f,&value,&value)... which results in <double,double> which I don't think is correct... you might want to try with a more recent clang from svn, it smells like a bug
    – PlasmaHH
    Commented May 12, 2014 at 12:35
  • 6
    Since replacing the template using with the native type makes the problem go away, it feels very much like a bug. Commented May 12, 2014 at 12:49
  • @PlasmaHH I tried clang version 3.5.0 (trunk 208562), same problem!
    – WaelJ
    Commented May 12, 2014 at 16:08
  • a newer version of icpc fixes the issue
    – WaelJ
    Commented May 12, 2014 at 18:57
  • 1
    @WaelJ: In this case, I suggest that you report a bug to the Clang team. 3.5 is near, it would be cool if they managed to fix this before it goes out. Commented May 18, 2014 at 14:49

1 Answer 1

1

Following the above discussion, it seems that this is indeed a bug in clang.

As pointed out by gha.st, skipping template using and using the native function type directly works:

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

I have a filed a bug against this here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.