[PATCH] Remove "-Wbad-function-cast"
Paulo César Pereira de Andrade
pcpa at mandriva.com.br
Wed Feb 4 13:49:55 PST 2009
Tomas Carnecky wrote:
> It's the source of many useless warnings.
It was my suggestion to Peter to add -Wbad-function-cast
(and a few others). I am not sure if the proper solution
to the warnings is to "not generate them" :-)
As I understand this option, the proper solution is
of course not to create a temporary variable, but, first
to not use a cast, as the compiler should be smart enough
to do the right thing.
I don't know enough about this one, but I suspect there
may be performance in some inner loops, for example, a
routine converts a integer expression to a double one,
returns the double, and the code using the result converts
it back to an integer... But probably this is not the
reason this option exists.
> Signed-off-by: Tomas Carnecky <tom at dbservice.com>
> It causes warnings for code like:
> int i = (int) dixLookupPrivate(...);
> of which there is a lot in the xserver source. Fixing this
> is not easy, as it requires to create a temporary variable
> for the return value, and that is not easily possible
> when such constructs are used in macros.
> I also found this while googling around (originally posted
> to comp.lang.c):
> gcc's documentation says:
> `-Wbad-function-cast (C only)'
> Warn whenever a function call is cast to a non-matching type. For
> example, warn if `int malloc()' is cast to `anything *'.
> This seems to be intended to catch the error of calling malloc()
> without a prototype in scope, an error that gcc is quite capable of
> catching directly (the usual message is "warning: implicit declaration
> of function `malloc'"). I wouldn't use that option myself.
> We already warn about missing declaration (see in the patch below).
> (Cc: author of the XORG_CWARNFLAGS macro, commit 4cce4c81)
> xorg-macros.m4.in | 3 +--
> 1 files changed, 1 insertions(+), 2 deletions(-)
> diff --git a/xorg-macros.m4.in b/xorg-macros.m4.in
> index 9a2e26a..4a8dd2b 100644
> --- a/xorg-macros.m4.in
> +++ b/xorg-macros.m4.in
> @@ -443,8 +443,7 @@ AC_DEFUN([XORG_CWARNFLAGS], [
> if test "x$GCC" = xyes ; then
> CWARNFLAGS="-Wall -Wpointer-arith -Wstrict-prototypes
> -Wmissing-prototypes \
> --Wmissing-declarations -Wnested-externs -fno-strict-aliasing \
> +-Wmissing-declarations -Wnested-externs -fno-strict-aliasing"
> case `gcc -dumpversion` in
> CWARNFLAGS+=" -Wold-style-definition -Wdeclaration-after-statement"
More information about the xorg