A recent flurry of bug reports about wrong code in C++ due to flowing
(AKA falling) off the end of a function prompted me to look at what
the manual has to say about the undefined behavior that the warning
is meant to point out.  It turns out that the manual not only doesn't
mention it, but it also incorrectly states that in C++, -Wreturn-type
cannot be suppressed by -Wno-return-type.

The attached patch documents the undefined behavior and removes
the statement about -Wno-return-type having no effect in C++.

Martin

PS The C++ standard uses the term "flow of the end" so I used that
in the new text even though the C paragraph refers to it as "falling
off the end."
gcc/ChangeLog:

	* doc/invoke.texi (-Wreturn-type): Correct and expand.

Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi	(revision 268583)
+++ gcc/doc/invoke.texi	(working copy)
@@ -5261,13 +5261,15 @@ without a value).
 For C only, warn about a @code{return} statement with an expression in a
 function whose return type is @code{void}, unless the expression type is
 also @code{void}.  As a GNU extension, the latter case is accepted
-without a warning unless @option{-Wpedantic} is used.
+without a warning unless @option{-Wpedantic} is used.  Attempting
+to use the return value of a non-@code{void} function other than @code{main}
+that flows off the end by reaching the closing curly brace that terminates
+the function is undefined.
 
-For C++, a function without return type always produces a diagnostic
-message, even when @option{-Wno-return-type} is specified.  The only
-exceptions are @code{main} and functions defined in system headers.
+For C++, calling a non-@code{void} function other than @code{main} that flows
+off the end is undefined even if the value of the function is not used.
 
-This warning is enabled by default for C++ and is enabled by @option{-Wall}.
+This warning is enabled by default in C++ and by @option{-Wall} otherwise.
 
 @item -Wshift-count-negative
 @opindex Wshift-count-negative

Reply via email to