GLib installed headers cause build failures with GCC8's -Wcast-function-type warnings
This was originally opened by @lkundrak at https://bugzilla.gnome.org/show_bug.cgi?id=793272
I also originally opened a bug against gsound before realizing the issue was in GLib.
Building something against the GLib headers gives warnings with GCC8's -Wcast-function-type. This is even worse when building something from GNOME Git using AX_COMPILER_FLAGS
which seems to pass -Werror by default.
For example, when building gsound from Git master you get quite a few of these:
gsound-context.c: In function ‘gsound_context_set_attributes’:
/usr/include/glib-2.0/glib/gmem.h:120:31: error: cast between incompatible function types from ‘int (*)(ca_proplist *)’ {aka ‘int (*)(struct ca_proplist *)’} to ‘void (*)(void *)’ [-Werror=cast-function-type]
GDestroyNotify _destroy = (GDestroyNotify) (destroy); \
^
gsound-context.c:359:3: note: in expansion of macro ‘g_clear_pointer’
g_clear_pointer (&pl, ca_proplist_destroy);
^~~~~~~~~~~~~~~
A simple way to reproduce the build failure if you don't have access to GCC8 is with the Freedesktop SDK:
$ git clone git@gitlab.com:freedesktop-sdk/freedesktop-sdk.git
$ cd freedesktop-sdk
$ git checkout bochecha/glib-cast-function-type # I made a branch just to test and reproduce this
$ bst build desktop/gsound-master.bst # When it fails, you can view the build logs and get a shell in the build sandbox
In the original bug in Bugzilla, @pwithnall asked:
What was the type of the destroy notify function you were using in this case?
I think in the case of gsound, it is ca_proplist_destroy