I'm trying understanding what am I doing wrong here.
When I compile the code below and run it segfaults because free
recognizes that vector is freed twice.
It doesn't segfault in cpp shell, but it doesn't produce the correct answer.
Making a deliberate copy on line 42 seems to help: return vector<int>( src );
I don't really understand this, but wouldn't you be calling the destructor of src at the same time as you were trying to move(?) it out of the function?
The correct answer is the other thing that I forgot to notice for Ubuntu 16.04 version of GCC.
For some reason it also prints the wrong answer before it dies.
Segfault is happening in assembly that is cleaning variables that go out of scope of >> [](){} operator.
In Ubuntu 18.04 it doesn't work correctly, but on Ubuntu 16.04 it does. I also can't understand what the problem here. So one more time where is the mistake?
______________________ https://goo.gl/b7GTEb
I think it is probably a bug in the way an old version of the compiler deals with lambda functions (because switching to a normal function seems to work OK). Some of your code is C++14.
Newer compilers seem to be OK with it, and no warnings flash related to this problem (though you've got plenty of other unused stuff in).
I can't see anything wrong with your code (other than it's very contorted!).