I know that dozens of bugs have been opened for this over the years, but please read this through.
If you have a C++ program missing a return statement from a function that is supposed to return a value, g++ will compile it happily with no errors (or even a warning, unless -Wreturn-type or -Wall is used). Trying to use the return value from the function will most likely cause a segmentation fault. Dozens of bugs have been opened for this over the years (e.g. bug 11474), all rejected as invalid based on the following statement from section 6.6.3 of the C++ standard: 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. However, the very same paragraph begins with: A return statement without an expression can be used only in functions that do not return a value, that is, a function with the return type void, a constructor (12.1), or a destructor (12.4). In my opinion, the standard contradicts itself. Either flowing off the end of a function is "equivalent to a return with no value" (i.e. invalid according to the beginning of the paragraph) or it is "undefined behaviour". It can't be both. Appendix C is informative rather than normative, but can help us understand the intent of the standard. Section C.1.4 says: Change: It is now invalid to return (explicitly or implicitly) from a function which is declared to return a value without actually returning a value. Rationale: The caller and callee may assume fairly elaborate return-value mechanisms for the return of class objects. If some flow paths execute a return without specifying any value, the implementation must embody many more complications. Besides, promising to return a value of a given type, and then not returning such a value, has always been recognized to be a questionable practice, tolerated only because very-old C had no distinction between void functions and int functions. The number of bugs opened for this issue over the years indicates how surprising the current behaviour is. Since it is not always practical to enable -Werror on large codebases, I think this should be an error by default. -- Summary: "warning: no return statement in function returning non- void" should be an error Product: gcc Version: unknown Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: david at rothlis dot net http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43943