谁能给我一个提示,为什么这段代码会产生内部编译器错误?我已经在 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 函数,这是真的吗?