[PATCH doc] correct/expand -Wreturn-type
Jakub Jelinek
jakub@redhat.com
Wed Feb 6 16:56:00 GMT 2019
On Wed, Feb 06, 2019 at 09:51:59AM -0700, Martin Sebor wrote:
> -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.
That is not true, the undefined behavior is not when calling such a function,
but only when it flows off the end. So, it is perfectly fine if you have:
int
foo (int x)
{
if (x > 10)
return 20;
}
and you only ever call foo with x > 10, or if you have:
int
bar ()
{
baz ();
}
and baz always throws, or never returns etc. So, if we try to clarify, we
should clarify it correctly.
Jakub
More information about the Gcc-patches
mailing list