Here is a c++ function:
int FuncWithoutReturn()
{
int var = 10;
++var;
// No return value here !!!
}
In MSVC, compiler generates error:
error C4716: 'FuncWithoutReturn' : must return a value.
But in XCode 5, the compiler just spits a warning:
Control reaches end of non-void function
In runtime if I am lucky, the app crashes. I know it is a stupid error but it would be good that the compiler yields an error in first place.
Just wondering anyone knows WHY XCode think it is a warning instead of an error.
You can use
-Werror=return-type
to make that warning and error, in my original comment I forgot that. You can see it live.This is both an option in clang and gcc, as far as I understand
XCode
can use either one.Falling off the end of value returning function is undefined behavior, we can see this by going to the draft C++ standard section
6.6.3
The return statement paragraph 2 which says:Undefined Behavior does not require a diagnostic(warning or error), although in many cases compilers will provide one.
You can enable it using
-Werror=return-type
Check your project's/target's/xcconfig's settings for "Mismatched Return Type" (aka
GCC_WARN_ABOUT_RETURN_TYPE
).