使用lambda表达式的GCC内部错误

时间:2013-06-15 13:28:16

标签: gcc internal

有人能给我一个提示,为什么这段代码会产生内部编译器错误?我在gcc 4.8.1上测试了它。

#include <functional>
#include <algorithm>
#include <iostream>
#include <vector>

class Dummy {
private:
    int dummy;
public:
    Dummy() { dummy = 0; }
    ~Dummy() { }
    int getDummy() const { return dummy; }
    void setDummy(int d) { dummy = d; }
};

class DummyCollection {
private:
    std::vector<Dummy> table;

public:
    void eachDummy(std::function<bool (const Dummy& d)>& closure) {
        for(const Dummy& d: table) {
            if(! closure(d))
                break;
        }
    }
};

DummyCollection dc;

void iterateDummies(std::function<bool (const Dummy& d)>& closure) {
    dc.eachDummy([&] (const Dummy& d) {
        return closure(d);
    });
}

int main() {
    iterateDummies([&] (const Dummy& d) {
        std::cout << "dummy " << d.getDummy() << std::endl;
        return true;
    });

    return 0;
}

这是编译器输出:

(2:514)$ g++ test.cpp -o test -std=c++11
test.cpp: In lambda function:
test.cpp:34:2: internal compiler error: in pop_binding, at cp/name-lookup.c:382
  });
  ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://bugs.archlinux.org/> for instructions.

第34行是iterateDummies函数的结尾。似乎lambda函数不能从另一个lambda函数调用,这是真的吗?

2 个答案:

答案 0 :(得分:1)

正如输出所说,这不一定是代码中的缺陷 - 编译器开发人员有一些缺陷需要处理。您应该按照链接的错误报告说明进行操作。

答案 1 :(得分:1)

我已经向ArchLinux bugzilla报告了这个问题,并得到了这个答案,所以我打算将其粘贴到其他googlers的好处:

https://bugs.archlinux.org/task/35803

gcc-4.9-20130324 BAD
gcc-4.9-20130331 GOOD