私は何を逃したのですか?次のコードは、g++ を使用して期待どおりにコンパイルされます。
#include <functional>
#include <iostream>
#include <string>
using namespace std;
typedef std::function<void()> Foo;
/* This function does NOT make g++ segfault */
Foo factory() {
return [] {cout << "Hi!" << endl;};
};
int main() {
/* This nested lambda makes g++ segfault */
// function<Foo()> factory = [] {
// return [] {cout << "Hello!" << endl;};
// };
factory()();
return 0;
}
使用されるコンパイル フラグ:
g++ -c -Wall -std=c++0x NestedLambdaProblem.cpp
main で // でコメントアウトされている 3 行のコメントを外すと、コンパイラは次のように segfaults します
$ g++ -c -Wall -std=c++0x NestedLambdaProblem.cpp
g++: internal compiler error: Segmentation fault (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.6/README.Bugs> for instructions.
使用する g++ バージョンについて:
$ g++ --version
g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3