Having a function that is meant to return a value but does not can cause some pretty nasty bugs, but since determining whether a function returns a value is an undecidable problem, the compiler doesn't attempt to catch that kind of error. It seems like it would be pretty easy to have the compiler insert a runtime guard at the end of all functions that are meant to return values. The runtime guard would just make the program blow up with some message telling you your function failed to return a value, and then you don't need to sit around doing tests and figure out why gdb is so confused about what happened. Is there any compiler setting like that available? I mainly work with g++.
I think that you mean if you create a function that i supposed to return a value and you forget the return statement to have an error.
Something like the following
1 2 3 4 5 6 7 8 9
#include <iostream>
usingnamespace std;
int no_ret(){
//whatever without a return statement
}
int main(){
//your program
return 0;
}
Then the compiler to show you a warning or an error message.
If I use -Wall, that gives a warning, but in any large group project there are tons of warnings and you never notice an important one like that.
If somewhere else I call foo:
cout << foo() << endl;
It happily returns -1079779132 or some other such garbage. It seems like it would be pretty easy to add a runtime check to prevent that behavior, basically something that would automatically modify foo to
1 2 3 4 5
int foo()
{
assert(false); //This should be unreached
}
but in any large group project there are tons of warnings
Errr.. no lol. I dunno who you are coding with. But you shouldn't have any warnings. They are warnings for a reason. Very few warnings should be acceptable. Current project of mine is 20k lines, so it's small-medium and has 0 warnings. Every warning is corrected.
I would address the cause, not the symptom. You have bad code that is causing you problems. Address that before trying to find a work around.