默认参数的私有模板方法地址与GCC编译良好,但不与Clang编译

时间:2016-06-25 16:04:15

标签: c++ templates gcc clang access-modifiers

此代码:

#include <iostream>
#include <functional>


int func3() { return 3; }

struct Test {
    template <typename F = std::function<int (void)>> Test(F &&f = func<int>) : _f(std::forward<F>(f)) {}  // Compile only with GCC
    //template <typename F = std::function<int (void)>> Test(F &&f = func2) : _f(std::forward<F>(f)) {}  // Compile with both
    //Test (std::function<int (void)> f = func<int>) : _f(f) {} // Compile with both

    int get() const { return _f(); }

private:
    template <typename T> static T func() { return 1; }
    static int func2() { return 2; }

    std::function<int (void)> _f;
};

int main() {
    Test t1, t2(func3);


    std::cout << t1.get() << ", " << t2.get() << std::endl;
}

与GCC编译好,但不与Clang编译(&#39; func&#39;是&#39;测试&#39;错误的私人成员)。

这是Clang的错误吗?

0 个答案:

没有答案
相关问题