My program has this function:
vector<itemPtr> Level::getItemsAt(const Point& pt)
{
vector<itemPtr> vect(items.size());
// copy all items at pt's 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'm using g++, my gcc version is 4:4.4.1-1ubuntu2), but when I run the program it skips right over the return statement.
I stepped through with gdb, setting a breakpoint at the previous line, and got this:
Breakpoint 1, yarl::level::Level::getItemsAt (this=0x80d4d58, pt=...)
at src/Level.cpp:519
519 map.setHasItem(pt, false);
(gdb) next
521 }
(gdb)
I've tried recompiling from scratch several times, erasing the executable and all the object files beforehand, and it still does it.
Strangely, if I comment out the return statement and try to compile, it only gives warning: no return statement in function returning non-void
. I would have thought not providing a return statement in a function that returns something would be a compiler error, but I guess not.
I realize this is not much to go on, but does anyone have an idea why this is happening? What to check for? At this point I don't even know where to start looking.
EDIT: for clarification, I'm compiling with -O0
.
According to tjm, my version of gcc will still use RVO even with a -O0
compiler flag, so that was the problem after all. Thanks for your help, guys.