Re: [PATCH] security_sk_free void return fixup

From: Dick Streefland
Date: Wed Jun 16 2004 - 07:15:12 EST


Linus Torvalds <torvalds@xxxxxxxx> wrote:
| I'm going to remove this warning from sparse. Apparently it is valid C99,
| and somebody (I think Richard Henderson) made the excellent point that it
| allows for type-independent code where you do something like
|
| mytype myfunc1(xxx);
|
| mytype myfunc2(xxx)
| {
| ...
| return myfunc1(...);
| }
|
| and it just works regardless of what type it is.

It may work in gcc, but it is invalid according to ISO C99. First
sentence from section 6.8.6.4:

A return statement with an expression shall not appear in a
function whose return type is void.

Now, a function call is obviously an expression.

| sparse will obviously warn about expressions with non-void types being
| returned from a void function, but the case where the expression exists
| and has the right type should be ok.
|
| I'm not sure it's wonderful C in general, but I certainly can't claim it
| is actively offensive, and since gcc accepts it and we have these things
| in the kernel, why complain?

Gcc warns about this with the -pedantic option:

$ gcc-3.3 -pedantic -c return.c
return.c: In function `myfunc2':
return.c:5: warning: `return' with a value, in function returning void

--
Dick Streefland //// Altium BV
dick.streefland@xxxxxxxxx (@ @) http://www.altium.com
--------------------------------oOO--(_)--OOo---------------------------

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/