GNOME Bugzilla – Bug 619026
avoid warning in gutils.h when using gcc with -Wconversion
Last modified: 2012-04-17 16:38:32 UTC
Using glib with gcc -Wconversion causes the following warning: /usr/include/glib-2.0/glib/gutils.h: In function ‘g_bit_storage’: /usr/include/glib-2.0/glib/gutils.h:358: warning: conversion to ‘guint’ from ‘int’ may change the sign of the result For several purposes it makes sense to use -Wconversion for programs using glib. With the following trivial patch the warning disappears. --- gutils.h.orig 2010-05-18 21:54:33.000000000 +0200 +++ gutils.h.new 2010-05-18 22:36:36.000000000 +0200 @@ -355,7 +355,7 @@ { #if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__) return G_LIKELY (number) ? - ((GLIB_SIZEOF_LONG * 8 - 1) ^ __builtin_clzl(number)) + 1 : 1; + ((GLIB_SIZEOF_LONG * 8U - 1) ^ __builtin_clzl(number)) + 1 : 1; #else register guint n_bits = 0;
Please attach patches as attachments so they are automatically recognized when searching Bugzilla. Thanks a lot!
Created attachment 161609 [details] [review] patch to avoid warning in gutils.h when using gcc with -Wconversion Patch added as attachment as advised.
I ask for confirmation and patch review.
commit a1b015f7b70b3851d5a6e45fd4114c7723b4f1ea Author: Hannes Müller <h.c.f.mueller@gmx.de> Date: Thu Aug 5 23:11:03 2010 +0200 avoid warning in gutils.h when using gcc with -Wconversion
Created attachment 206749 [details] [review] avoid warning in gutils.h when using also gcc >=4.3 with -Wconversion Old solution to avoid warning with gcc flag -Wconversion does not work with gcc >=4.3 since the behaviour for that flag has been changed, ref. http://gcc.gnu.org/wiki/NewWconversion. Now cast for __builtin_clzl is required, which itself is declared to return int.
I set status to UNCONFIRMED, since I assume otherwise my new patch from 2012-02-04 is not considered.
After IRC conversation Benjamin Otte (Company) pushed it to master and the 2-32 branch, ref. http://git.gnome.org/browse/glib/commit/?id=2ef1a8ef05410ee724f7ad577db57bd11e6c51c2