GNOME Bugzilla – Bug 796230
gst-libs sdp: Function cast warnings in GCC 8
Last modified: 2018-11-03 12:07:33 UTC
/home/fraxinas/gst/master/gst-plugins-base/gst-libs/gst/sdp/gstsdpmessage.h: In function 'glib_listautoptr_cleanup_GstSDPMessage': /usr/include/glib-2.0/glib/gmacros.h:462:99: warning: cast between incompatible function types from 'GstSDPResult (*)(GstSDPMessage *)' {aka 'enum <anonymous> (*)(struct <anonymous> *)'} to 'void (*)(void *)' [-Wcast-function-type] static inline void _GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName) (GList **_l) { g_list_free_full (*_l, (GDestroyNotify) func); } \ ^ /home/fraxinas/gst/master/gst-plugins-base/gst-libs/gst/sdp/gstsdpmessage.h:756:1: note: in expansion of macro 'G_DEFINE_AUTOPTR_CLEANUP_FUNC' G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstSDPMessage, gst_sdp_message_free) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/fraxinas/gst/master/gst-plugins-base/gst-libs/gst/sdp/gstsdpmessage.h: In function 'glib_slistautoptr_cleanup_GstSDPMessage': /usr/include/glib-2.0/glib/gmacros.h:463:102: warning: cast between incompatible function types from 'GstSDPResult (*)(GstSDPMessage *)' {aka 'enum <anonymous> (*)(struct <anonymous> *)'} to 'void (*)(void *)' [-Wcast-function-type] static inline void _GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName) (GSList **_l) { g_slist_free_full (*_l, (GDestroyNotify) func); } \ ^ /home/fraxinas/gst/master/gst-plugins-base/gst-libs/gst/sdp/gstsdpmessage.h:756:1: note: in expansion of macro 'G_DEFINE_AUTOPTR_CLEANUP_FUNC' G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstSDPMessage, gst_sdp_message_free) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This happens after upgrading from gcc 7.3.1+20180406-1 to 8.1.0-1 From https://gcc.gnu.org/gcc-8/changes.html -Wcast-function-type warns when a function pointer is cast to an incompatible function pointer. This warning is enabled by -Wextra. 1.4.0, 1.4.1 and master are all affected.
That's a false warning unfortunately, and the cast should've already prevented that. Returning something for a function that does not expect a return value is perfectly fine. You could try to first cast the function to a gpointer and then to a GDestroyNotify there. Does that work?
Created attachment 372178 [details] [review] sdpmessage: Avoid function cast warning in GCC 8
Maybe it would be worth patching this pattern into glib (like https://paste.xinu.at/zYR7Vn/ ) so that you can pass non-GDestroyNotify-compatible functions directly to G_DEFINE_AUTOPTR_CLEANUP_FUNC.
(In reply to Jan Alexander Steffens (heftig) from comment #3) > Maybe it would be worth patching this pattern into glib (like > https://paste.xinu.at/zYR7Vn/ ) so that you can pass > non-GDestroyNotify-compatible functions directly to > G_DEFINE_AUTOPTR_CLEANUP_FUNC. Yes, please file another bug there :)
Review of attachment 372178 [details] [review]: ::: gst-libs/gst/sdp/gstsdpmessage.h @@ +755,3 @@ #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC +static inline void _gst_autoptr_cleanup_sdp_message (GstSDPMessage *o) { gst_sdp_message_free (o); } +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstSDPMessage, _gst_autoptr_cleanup_sdp_message) Just casting the free function to a gpointer first and then to a GDestroyNotify is not enough?
(In reply to Sebastian Dröge (slomo) from comment #5) No, it causes a different warning: /home/fraxinas/gst/master/gst-plugins-base/gst-libs/gst/sdp/gstsdpmessage.h: In function 'glib_autoptr_cleanup_GstSDPMessage': /home/fraxinas/gst/master/gst-plugins-base/gst-libs/gst/sdp/gstsdpmessage.h:756:46: warning: function called through a non-compatible type G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstSDPMessage, (GDestroyNotify) (gpointer) gst_sdp_message_free) /usr/include/glib-2.0/glib/gmacros.h:461:88: note: in definition of macro 'G_DEFINE_AUTOPTR_CLEANUP_FUNC' static inline void _GLIB_AUTOPTR_FUNC_NAME(TypeName) (TypeName **_ptr) { if (*_ptr) (func) (*_ptr); } \
Can you update your patch once the GLib people decided which variant they want? We shouldn't depend on the GLib change as that would require updating the GLib dependency for such a trivial thing.
Not sure what kind of update you're thinking of. Casting the function given to G_DEFINE_AUTOPTR_CLEANUP_FUNC isn't viable due to the above warning. Downstream of GLib we can either use the static wrapper or the pragmas from attachment 372034 [details] [review].
-- GitLab Migration Automatic Message -- This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/issues/456.