Skip to content

gclosure: avoid -Wincompatible-pointer-types compiler warning for G_CALLBACK() cast macro

Thomas Haller requested to merge thaller/glib:th/g-callback-cast-warning into master

The -Wincompatible-pointer-types compiler warning [1] is very useful to catch wrong casts for function pointers. It flags in uses where the function signature is incompatible with the desired type.

However see for example g_source_set_callback() function which expects a GCallback function argument. Then we have sources like g_unix_fd_add(), which expect a callback with a GUnixFDSourceFunc signature.

The cast macro was not usable for this purpose, if it doesn't silence the cast warning.

Compare also G_SOURCE_FUNC() macro which does a similar thing [2]. The difference is that G_SOURCE_FUNC() was added exactly for this purpose from the start. Here, the commit changes a pre-existing G_CALLBACK() macro and silences warnings. I still think this change is desirable.

[1] https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wcast-function-type

[2] 039fa689

Edited by Thomas Haller

Merge request reports