When a function missing the return value, the compiler generates a warning but not an error?

☆樱花仙子☆ 提交于 2019-12-05 03:57:29

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:

[...]Flowing off the end of a function is equivalent to a return with no value; this results in undefined behavior in a value-returning function.

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

Just wondering anyone knows WHY XCode think it is a warning instead of an error.

Check your project's/target's/xcconfig's settings for "Mismatched Return Type" (aka GCC_WARN_ABOUT_RETURN_TYPE).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!