What have I missed? The following code compiles as expected, using 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;
}
The compile flags used:
g++ -c -Wall -std=c++0x NestedLambdaProblem.cpp
If I uncomment the three lines that is commented out with // in main, the compiler segfaults like this
$ 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.
About the g++ version used:
$ g++ --version
g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3