My program has this function:
vector<itemPtr> Level::getItemsAt(const Point& pt) { vector<itemPtr> vect(items.size()); // copy all items at pt position to vect remove_copy_if(items.begin(), items.end(), vect.begin(), boost::bind(matchesPosition<itemPtr>, _1, pt)); // update LevelMap and return map.setHasItem(pt, false); return vect; }
This compiles fine (I use g ++, my version of gcc is 4: 4.4.1-1ubuntu2), but when I run the program, it skips right above the return statement.
I went through gdb, setting a breakpoint on the previous line and getting the following:
Breakpoint 1, yarl::level::Level::getItemsAt (this=0x80d4d58, pt=...) at src/Level.cpp:519 519 map.setHasItem(pt, false); (gdb) next 521 } (gdb)
I tried to recompile from scratch several times, having previously deleted the executable and all the object files, and it still does.
It's strange if I comment on the return statement and try to compile it, it gives only warning: no return statement in function returning non-void . I would think that not providing a return statement in a function that returns something would be a compiler error, but I think not.
I understand that this is not so much, but does anyone have an idea why this is happening? What to check? At the moment, I donβt even know where to start.
EDIT: for clarification, I am compiling with -O0 .
According to tjm, my gcc version will still use RVO even with the -O0 compiler -O0 , so that was the problem after all. Thanks for the help guys.