【发布时间】:2012-11-06 19:07:42
【问题描述】:
如何指定一个默认函数作为类成员的参数?
从我的代码派生的当前示例是:
#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 编译器上试试吗(对于有编译器的人)?
【问题讨论】:
-
内部编译器错误始终是编译器中的错误。
-
Can you try it on other C++11 compilers (for people that have ones)?你做到了! -
+1,哇,一小段代码完美地重现了报告的问题!
标签: c++ compiler-construction c++11 lambda std-function