此代码:
#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的错误吗?