gcc-8: -Wcast-function-type: new warnings for g_list_copy_deep()
Since gcc-8, with -Wcast-function-type
, I get a bunch of new warnings in my application:
warning: cast between incompatible function types from 'gchar * (*)(const gchar *)' {aka 'char * (*)(const char *)'} to 'void * (*)(const void *, void *)' [-Wcast-function-type]
priv->stream_uris = g_slist_copy_deep(list, (GCopyFunc) g_strdup, NULL);
warning: cast between incompatible function types from 'void * (*)(void *)' to 'void * (*)(const void *, void *)' [-Wcast-function-type]
iter->head = g_list_copy_deep(list, (GCopyFunc) g_object_ref, NULL);
The issue here is that GCopyFunc is supposed to take two parameters, and in my code I give it g_strdup()
and g_object_ref()
, which only take 1 parameter. This "hack" raised no warnings before ggc-8, and is even mentioned in GLib's documentation, at g_list_copy_deep, quoting: It's safe to pass NULL as user_data, if the copy function takes only one argument.
.
I found similar uses of g_list_copy_deep()
in GLib and GTK+. I can see these warnings if I build GLib master, by setting warning_level=2
in meson.build
, and then ninja | grep copy_deep -A 1
.
What's your suggestion to handle that? Do you think it would be nice/possible to address it in GLib itself?
Thanks
Related: #1453 (closed), although it seems to only address warnings with g_clear_pointer