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

WaelJ
  • 2,942
  • 4
  • 22
  • 28
  • Your last question you could answer yourself by passing run_func(f,&value,&value)... which results in 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 May 12 '14 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. – danielschemmel May 12 '14 at 12:49
  • @PlasmaHH I tried clang version 3.5.0 (trunk 208562), same problem! – WaelJ May 12 '14 at 16:08
  • a newer version of icpc fixes the issue – WaelJ May 12 '14 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. – Matthieu M. May 18 '14 at 14:49
  • I filed a [bug](http://llvm.org/bugs/show_bug.cgi?id=19802) – WaelJ May 20 '14 at 10:57
  • @WaelJ please post your update as an answer and accept it to get the question off the unanswered list. – AliciaBytes May 24 '14 at 04:07

1 Answers1

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.

Community
  • 1
  • 1
WaelJ
  • 2,942
  • 4
  • 22
  • 28