【问题标题】:GCC bug or not : default std::function?GCC 错误与否:默认 std::function?
【发布时间】: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


【解决方案1】:

毫无疑问,这是一个编译器错误。无论您的程序是否格式正确,编译器都会检测到其自身数据结构中的不一致。

请遵循 GCC 错误报告说明:http://gcc.gnu.org/bugs/#report

【讨论】:

  • 好的,该bug已报告。谢谢!
猜你喜欢
  • 1970-01-01
  • 2016-02-22
  • 1970-01-01
  • 1970-01-01
  • 2021-04-03
  • 1970-01-01
  • 1970-01-01
  • 2017-06-27
  • 1970-01-01
相关资源
最近更新 更多