I've encountered a problem when passing returned rvalue references from a depth of more than 1.
struct Data {
std :: vector <int> data;
Data () {
data .push_back (1);
};
Data (Data && d)
: data (std :: move (d .data))
{}
};
Data && foo () {
Data d;
return std :: move (d);
}
Data && bar () {
return std :: move (foo ()); // Crashes in autogenerated code
}
Data && baz () {
return foo (); // Crashes in Data move constructor.
}
Data && bop () {
Data d = foo ();
return std :: move (d); // Crashes in autogenerated code.
}
int main () {
Data d_foo = foo (); // This is fine.
Data d_bar = bar (); // Crash.
Data d_bar = baz (); // Crash.
Data d_bop = bop (); // Crash.
}
I think the std::vector is being double-freed. I'm using g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5
Does the above code work for you? Am I doing something wrong or is there a bug in the library or compiler?
If (heaven forfend) it's the compiler (there are other known C++0x bugs in gcc), can someone please tell me if there's an apt-safe way to upgrade or patch gcc on ubuntu? I've tried before but got into a tangle of unsupported packages.
Thanks a lot.