On 2/6/19 9:56 AM, Jakub Jelinek wrote:
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.

Sigh.  Was that jab really necessary?

The C++ standard says:

  ...flowing off the end of a function other than main (6.6.1)
  results in undefined behavior.

It doesn't mention anything about calling the function so it seems
to me the text I added is no less correct or clear than that.  I see
no point in going into unlikely corner cases that the standard itself
make provisions for.

Martin

Reply via email to