This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
missing return value
- From: Paul Koning <Paul_Koning at dell dot com>
- To: gcc at gcc dot gnu dot org
- Date: Wed, 1 Apr 2009 13:18:32 -0400
- Subject: missing return value
The other day there was a request for a compile error if you do:
int foo(void) { }
and the answer was "the standard says that this is legal -- after all,
you can say 'foo();' so the return value isn't used and it doesn't
matter that it's missing".
That makes sense.
So how about:
int foo (void) { }
...
j = foo ();
This clearly *is* wrong. The compiler may not always be able to
tell. If it can -- for example, if this is inlined code where the
function definition is available at the time the call is compiled --
it sure would be helpful to have an error message here.
I just helped a colleague track one of these down after he had already
spent a day or three looking. Bugs like this can be hard to spot.
Especially if, as in this case, you were dealing with a class wrapped
around another class, and the wrappers all look the same, and those
wrappers are where the problem lies.
paul