I have just spend 3 hours, probably more, trying to find a bug, segfault or bad_allow, depending on the way I modified the code so as to understand what object was messing with the stack or memory: I put all my objects in doubt... I slaughtered classes... ( nonetheless this turned out to be good since those classes revealed themselves useless in the end :-) )...
But, indeed, the real mistake was simply:
I hadn't written a return statement in a function that should return a value (in my case I needed to return a std::vector<boost::any>
).
I thought that gcc (4.6.3) couldn't have compiled without it. And I feel even stranger remembering that something similar has happened to me with ms visual 2010.
So now I am wondering whether it is legal not to write a return statement ?? What happens in such cases ?
Is it related with the fact that the main that can have a return value or not ? Or should I consider going to gcc 4.7 ?
It's undefined behaviour:
[C++11: 6.6.3/2]:
[..] Flowing off the end of a function is equivalent to areturn
with no value; this results in undefined behavior in a value-returning function.
It compiles because:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With