简体   繁体   English

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

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

How to specify a default function as a parameter of a class member ? 如何指定默认函数作为类成员的参数?

A current example derived from my code is : 从我的代码派生的当前示例是:

#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;
}

Is it a bug of GCC ? 这是GCC的错误吗?

Is it possible to avoid this problem with another syntax ? 是否可以通过其他语法避免此问题?

Can you try it on other C++11 compilers (for people that have ones) ? 您可以在其他C ++ 11编译器上(对于有编译器的人)尝试吗?

Without question, this is a compiler bug. 毫无疑问,这是一个编译器错误。 Regardless of whether your program is well-formed, the compiler has detected an inconsistency in its own data structures. 无论您的程序格式是否正确,编译器都已在其自己的数据结构中检测到不一致。

Please follow the GCC bug-reporting instructions: http://gcc.gnu.org/bugs/#report 请按照GCC错误报告说明进行操作: http : //gcc.gnu.org/bugs/#report

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

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