繁体   English   中英

是否存在GCC错误:默认std :: function?

[英]GCC bug or not : default std::function?

如何指定默认函数作为类成员的参数?

从我的代码派生的当前示例是:

#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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM