failure to warn about an obvious error

Martin v. Loewis martin@mira.isdn.cs.tu-berlin.de
Sun Nov 21 10:59:00 GMT 1999


> If -pedantic is turned on, the compiler says
> 
> 	 warning: control reaches end of non-void function `f()'
> 
> It would be real nice if g++ were more aggressive about this
> particular warning, especially in cases where the actual generated
> code will crash if invoked.

Thanks for your bug report. Please note that this warning is also
produced with -Wall; it is a general rule that you have to enable
warnings in g++ yourself unless diagnostics are required (and even
then you get some of them only with -pedantic).

As you probably know, it is very tricky to reliably tell whether a
function can "fall off the end". For example,

 #include <vector>

 std::vector<int> f(bool b) { 
   if (b)
     return std::vector<int>();
 }

is well-defined if this function is never invoked with "false".

In your example, it is pretty obvious. In other cases, you need flow
analysis. In some cases, you can never tell.

It is quite simple in the compiler to always emit the warning,
provided the necessary information was computed. My feeling would
still be to leave this as-is, and educate people to use -Wall instead
(most long-time users of GCC use it that way).

Regards,
Martin


More information about the Gcc-bugs mailing list