7

I have no problem passing the address of a function template specialization to a regular template function:

template <typename T>
void f(T) {}

template <typename A, typename B>
void foo(A, B) {}

int main()
{
    foo(&f<int>, &f<float>);
}

However, when I try to pass the same specializations to a variadic template:

template <typename T>
void f(T) {}

template <typename... A>
void bar(A...) {}

int main()
{
    bar(&f<int>, &f<float>);
}

I get the following compiler errors with GCC (I tried 4.6.1 and 4.7.0):

test.cpp: In function 'int main()':
test.cpp:9:27: error: no matching function for call to 'bar(<unresolved overloaded function type>, <unresolved overloaded function type>)'
test.cpp:9:27: note: candidate is:
test.cpp:5:6: note: template<class ... A> void bar(A ...)
test.cpp:5:6: note:   template argument deduction/substitution failed:

Why am I getting these errors?

HighCommander4
  • 50,428
  • 24
  • 122
  • 194
  • `auto a = &f` doesn't work either: `error: 'a' has incomplete type` – Seth Carnegie Sep 12 '11 at 21:37
  • This works: `bar((void(*)(int))f, (void(*)(double))f);` but obviously that's not a solution. It just means (like the error said) it can't tell what type `&f` is for some reason. – Seth Carnegie Sep 12 '11 at 21:39

1 Answers1

5

Looks like it might be a bug in GCC that is possibly fixed in GCC 4.6.2 (I say possibly because it's not exactly the same, but does involve getting the address of a variadic template function).

Peter Alexander
  • 53,344
  • 14
  • 119
  • 168