Calculating a Variadic Template Using an Alias ​​of Type

I have a program like this:

template<typename ...Args>
using Function = void(*)(Args *...);

template<typename ...Args>
void DoThing(Function<Args...> func) { }

void IntFunction(int *i) { }

int main(int argc, char *argv[]) {
  DoThing(IntFunction);
}

When I run the program, I get this error

$ clang++ -std=c++14 template.cpp
template.cpp:12:3: error: no matching function for call to 'DoThing'
  DoThing(IntFunction);
  ^~~~~~~
template.cpp:7:6: note: candidate template ignored: substitution failure [with Args = int]
void DoThing(Function<Args...> func) { }
     ^
1 error generated.

But if I compile it with g ++, I get no errors.

It seems that clang is having problems displaying the parameters of the variational pattern when used in a type alias. If I replaced the variable parameters with the standard ones, then I no longer get the error.

Which compiler gives me the correct result? And why wasn’t I allowed to do this?

+4
source share
1 answer

Can be reduced to

template <typename... T>
using funptr = void(*)(T...);

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

template void f(void(*)());

; funptr<T...> , Clang .

# 25250.

0

Source: https://habr.com/ru/post/1612106/


All Articles