Passing function template specializations to a variadic template function
Asked Answered
G

1

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?

Gifted answered 12/9, 2011 at 21:25 Comment(2)
auto a = &f<int> doesn't work either: error: 'a' has incomplete typeBlynn
This works: bar((void(*)(int))f<int>, (void(*)(double))f<double>); but obviously that's not a solution. It just means (like the error said) it can't tell what type &f<int> is for some reason.Blynn
A
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).

Awl answered 12/9, 2011 at 21:55 Comment(2)
Nice find! That looks like it's almost certainly the same issue. (I'll verify once I build a more recent 4.7.0).Gifted
Confirmed, it was the same issue.Gifted

© 2022 - 2024 — McMap. All rights reserved.