After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 619026 - avoid warning in gutils.h when using gcc with -Wconversion
avoid warning in gutils.h when using gcc with -Wconversion
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
2.32.x
Other All
: Normal trivial
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2010-05-18 21:05 UTC by Hannes Mueller
Modified: 2012-04-17 16:38 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch to avoid warning in gutils.h when using gcc with -Wconversion (413 bytes, patch)
2010-05-21 07:01 UTC, Hannes Mueller
none Details | Review
avoid warning in gutils.h when using also gcc >=4.3 with -Wconversion (1.01 KB, patch)
2012-02-04 09:36 UTC, Hannes Mueller
none Details | Review

Description Hannes Mueller 2010-05-18 21:05:47 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;
Comment 1 André Klapper 2010-05-20 19:29:55 UTC
Please attach patches as attachments so they are automatically recognized when searching Bugzilla. Thanks a lot!
Comment 2 Hannes Mueller 2010-05-21 07:01:07 UTC
Created attachment 161609 [details] [review]
patch to  avoid warning in gutils.h when using gcc with -Wconversion 

Patch added as attachment as advised.
Comment 3 Hannes Mueller 2010-06-10 20:01:37 UTC
I ask for confirmation and patch review.
Comment 4 Benjamin Otte (Company) 2010-08-05 21:20:52 UTC
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
Comment 5 Hannes Mueller 2012-02-04 09:36:35 UTC
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.
Comment 6 Hannes Mueller 2012-04-08 10:27:18 UTC
I set status to UNCONFIRMED, since I assume otherwise my new patch from 2012-02-04 is not considered.
Comment 7 Hannes Mueller 2012-04-17 16:38:32 UTC
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