如何将默认函数指定为类成员的参数?
从我的代码派生的当前示例是:
#include <iostream>
#include <functional>
template<typename T> struct C
{
static T test(std::function<T(int)> f = [](int i){return i;})
{return f(42);}
};
int main(int argc, char* argv[])
{
C<int>::test(); // ERROR = internal compiler error : in tsubst_copy, at cp/pt.c:11354
C<int>::test([](int i){return i;}); // OK
return 0;
}
这是 GCC 的错误吗?
是否可以使用另一种语法来避免这个问题?
你能在其他 C++11 编译器上试一试吗(对于有编译器的人)?
最佳答案
毫无疑问,这是一个编译器错误。无论您的程序是否合式,编译器都会检测到其自身数据结构中的不一致。
请遵循 GCC 错误报告说明:http://gcc.gnu.org/bugs/#report
关于c++ - GCC 错误与否:默认 std::function?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13257679/