GCC vs clang:可变参数模板和指向成员方法的指针

时间:2016-09-23 16:15:10

标签: c++ c++11 gcc clang language-lawyer

请考虑以下代码:

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();
}

当然,这是一个很小的例子 目的是在内部转发一堆指向成员方法的指针作为函数的模板参数,通过解压缩列表来执行它们。
它适用于clang v3.9,不能使用GCC v6.2进行编译。

以下是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

哪个编译器是对的?这是不正确的代码吗?

0 个答案:

没有答案
相关问题