2

Consider the following code:

struct S { void f() { } };
struct T { void f() { } };

template<typename... M>
struct U: M... {
    template<void(M::*... F)(void)>
    void g() { }

    void f() {
        g<&M::f...>();
    }
};

int main() {
    U<S, T> u;
    u.f();
}

This is a minimal example, of course.
The intent is to forward internally a bunch of pointers to member methods as a template parameter of a function that executes them by unpacking the list.
It works with clang v3.9, it doesn't compile with GCC v6.2.

Here is the error returned by GCC:

/tmp/gcc-explorer-compiler116823-58-9skgit/example.cpp: In instantiation of 'void U<M>::f() [with M = {S, T}]':
16 : required from here
10 : error: no matching function for call to 'U<S, T>::g()'
g<&M::f...>();
~~~~~~~~~~~^~
7 : note: candidate: template<void (M::* ...F)()> void U<M>::g() [with void (M::* ...F)() = {F ...}; M = {S, T}]
void g() { }
^
7 : note: template argument deduction/substitution failed:
10 : error: wrong number of template arguments (2, should be 1)
g<&M::f...>();
~~~~~~~~~~~^~
Compilation failed

Which compiler is right? Is this ill-formed code or not?

skypjack
  • 49,335
  • 19
  • 95
  • 187

0 Answers0