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

GCC bug or not : default std::function?

本文关键字:默认 function std 错误 存在 GCC 是否      更新时间:2023-10-16

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

从我的代码中得出的当前示例是:

#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