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 793175 - G++ 8 warns about G_DEFINE_TYPE GClassInitFunc cast
G++ 8 warns about G_DEFINE_TYPE GClassInitFunc cast
Status: RESOLVED DUPLICATE of bug 793272
Product: glib
Classification: Platform
Component: gobject
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2018-02-04 23:05 UTC by Philip Chimento
Modified: 2018-02-08 12:23 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gtype: Add parameter to class/instance init functions (2.17 KB, patch)
2018-02-04 23:09 UTC, Philip Chimento
none Details | Review

Description Philip Chimento 2018-02-04 23:05:19 UTC
It seems that G++ 8 is getting more strict about casting function pointers, and this shows up in a warning spew for every G_DEFINE_TYPE because of the unused class_data argument to GClassInitFunc and GInstanceInitFunc:

From, e.g. https://gitlab.gnome.org/GNOME/gjs/-/jobs/6475:

```
In file included from /usr/include/glib-2.0/gobject/gobject.h:24,
                 from /usr/include/glib-2.0/gobject/gbinding.h:29,
                 from /usr/include/glib-2.0/glib-object.h:23,
                 from /usr/include/glib-2.0/gio/gioenums.h:28,
                 from /usr/include/glib-2.0/gio/giotypes.h:28,
                 from /usr/include/glib-2.0/gio/gio.h:26,
                 from /root/jhbuild/checkout/gjs/gjs/context.cpp:32:
/root/jhbuild/checkout/gjs/gjs/context.cpp: In function 'GType gjs_context_get_type()':
/root/jhbuild/checkout/gjs/gjs/context.cpp:123:27: warning: cast between incompatible function types from 'void (*)(gpointer)' {aka 'void (*)(void*)'} to 'GClassInitFunc' {aka 'void (*)(void*, void*)'} [-Wcast-function-type]
 G_DEFINE_TYPE(GjsContext, gjs_context, G_TYPE_OBJECT);
                           ^~~~~~~~~~~
/usr/include/glib-2.0/gobject/gtype.h:1977:57: note: in definition of macro '_G_DEFINE_TYPE_EXTENDED_BEGIN_REGISTER'
                                        (GClassInitFunc) type_name##_class_intern_init, \
                                                         ^~~~~~~~~
/usr/include/glib-2.0/gobject/gtype.h:1737:60: note: in expansion of macro '_G_DEFINE_TYPE_EXTENDED_BEGIN'
 #define G_DEFINE_TYPE_EXTENDED(TN, t_n, T_P, _f_, _C_)     _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, _f_) {_C_;} _G_DEFINE_TYPE_EXTENDED_END()
                                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/gobject/gtype.h:1595:43: note: in expansion of macro 'G_DEFINE_TYPE_EXTENDED'
 #define G_DEFINE_TYPE(TN, t_n, T_P)       G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, 0, {})
                                           ^~~~~~~~~~~~~~~~~~~~~~
/root/jhbuild/checkout/gjs/gjs/context.cpp:123:1: note: in expansion of macro 'G_DEFINE_TYPE'
 G_DEFINE_TYPE(GjsContext, gjs_context, G_TYPE_OBJECT);
 ^~~~~~~~~~~~~
/root/jhbuild/checkout/gjs/gjs/context.cpp:123:27: warning: cast between incompatible function types from 'void (*)(GjsContext*)' {aka 'void (*)(_GjsContext*)'} to 'GInstanceInitFunc' {aka 'void (*)(_GTypeInstance*, void*)'} [-Wcast-function-type]
 G_DEFINE_TYPE(GjsContext, gjs_context, G_TYPE_OBJECT);
                           ^~~~~~~~~~~
/usr/include/glib-2.0/gobject/gtype.h:1979:60: note: in definition of macro '_G_DEFINE_TYPE_EXTENDED_BEGIN_REGISTER'
                                        (GInstanceInitFunc) type_name##_init, \
                                                            ^~~~~~~~~
/usr/include/glib-2.0/gobject/gtype.h:1737:60: note: in expansion of macro '_G_DEFINE_TYPE_EXTENDED_BEGIN'
 #define G_DEFINE_TYPE_EXTENDED(TN, t_n, T_P, _f_, _C_)     _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, _f_) {_C_;} _G_DEFINE_TYPE_EXTENDED_END()
                                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/gobject/gtype.h:1595:43: note: in expansion of macro 'G_DEFINE_TYPE_EXTENDED'
 #define G_DEFINE_TYPE(TN, t_n, T_P)       G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, 0, {})
                                           ^~~~~~~~~~~~~~~~~~~~~~
/root/jhbuild/checkout/gjs/gjs/context.cpp:123:1: note: in expansion of macro 'G_DEFINE_TYPE'
 G_DEFINE_TYPE(GjsContext, gjs_context, G_TYPE_OBJECT);
 ^~~~~~~~~~~~~
```

I realize all of GObject depends heavily on this technically undefined behaviour, and that's not going to change, so maybe we should disable this warning around gtype.h?

The attached patch is untested. It's an alternative to disabling the warning, but requires all client code to add a gpointer parameter to their instance_init functions, so probably not an option.
Comment 1 Philip Chimento 2018-02-04 23:09:12 UTC
Created attachment 367890 [details] [review]
gtype: Add parameter to class/instance init functions

This is in order to avoid a warning about an invalid function pointer
cast in G++ 8.
Comment 2 Philip Withnall 2018-02-08 12:23:55 UTC
I’m going to mark this as a duplicate of bug #793272 since there are more patches there. I still need to work out which approach would be a good way to fix this though. Let’s discuss there.

Thanks for taking the time to report this.
This particular bug has already been reported into our bug tracking system, but please feel free to report any further bugs you find.

*** This bug has been marked as a duplicate of bug 793272 ***