I have the following code:
struct Processor
{
template <typename... ARGS>
void OnMsg(ARGS... args, int) {}
// but makine ARGS after int is fine:
// void OnMsg(int, ARGS... args) {}
};
struct Dispatcher
{
void Register(void (Processor::*memfun)(int)) {}
};
void Register(Dispatcher& dispatcher)
{
dispatcher.Register(&Processor::OnMsg<>);
}
GCC >4.7.1 compiles this just fine. Clang (any) does not, because it cannot instantiate the "no-args" version of the OnMsg function.
17 : <source>:17:26: error: address of overloaded function 'OnMsg' does not match required type 'void (int)'
dispatcher.Register(&Processor::OnMsg<>);
^~~~~~~~~~~~~~~~~~
5 : <source>:5:10: note: candidate template ignored: failed template argument deduction
void OnMsg(ARGS... args, int) {}
^
12 : <source>:12:37: note: passing argument to parameter 'memfun' here
void Register(void (Processor::*memfun)(int)) {}
^
1 error generated.
Compiler exited with result code 1
Curiously enough, if you move the ARGS... in the OnMsg function to the end of the arguments (to the right of int), it works in clang.
Godbolt link: https://godbolt.org/g/cJwXC7
Which compiler is right?