Regression in 2.67.0 makes G_DEFINE_TYPE trigger -Wincompatible-pointer-types-discards-qualifiers with CLang
Consider this simple demo program
$ cat demo.c
#include <glib-object.h>
typedef struct {
GObject parent;
int dummy;
} Foo;
typedef struct {
GObjectClass parent;
} FooClass;
static void foo_class_init(FooClass *klass)
{
}
static void foo_init(Foo *foo)
{
}
G_DEFINE_TYPE(Foo, foo, G_TYPE_OBJECT);
This compiles cleanly with GCC:
$ gcc -Wall -c -o demo.o demo.c `pkg-config --cflags --libs glib-2.0`
It generates warnings with CLang:
$ clang -c -o demo.o demo.c `pkg-config --cflags --libs glib-2.0`
clang-11: warning: -lglib-2.0: 'linker' input unused [-Wunused-command-line-argument]
demo.c:20:1: warning: passing 'typeof (*(&g_define_type_id__volatile)) *' (aka 'volatile unsigned long *') to parameter of type 'gsize *' (aka 'unsigned long *') discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
G_DEFINE_TYPE(Foo, foo, G_TYPE_OBJECT);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/gobject/gtype.h:1600:43: note: expanded from macro 'G_DEFINE_TYPE'
#define G_DEFINE_TYPE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, 0, {})
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/gobject/gtype.h:1759:60: note: expanded from macro 'G_DEFINE_TYPE_EXTENDED'
#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:2032:3: note: expanded from macro '_G_DEFINE_TYPE_EXTENDED_BEGIN'
_G_DEFINE_TYPE_EXTENDED_BEGIN_REGISTER(TypeName, type_name, TYPE_PARENT, flags) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/gobject/gtype.h:2000:7: note: expanded from macro '_G_DEFINE_TYPE_EXTENDED_BEGIN_REGISTER'
if (g_once_init_enter (&g_define_type_id__volatile)) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gthread.h:260:7: note: expanded from macro 'g_once_init_enter'
(!g_atomic_pointer_get (location) && \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:112:38: note: expanded from macro 'g_atomic_pointer_get'
__atomic_load (gapg_temp_atomic, &gapg_temp_newval, __ATOMIC_SEQ_CST); \
^~~~~~~~~~~~~~~~~
1 warning generated.
The regression appears to be caused by:
commit dce24dc4492dc7918ff240b9c3d4737d7eff6b82
Author: Philip Withnall <pwithnall@endlessos.org>
Date: Wed Oct 21 11:32:32 2020 +0100
gmacros: Use __typeof__ when compiling with Clang
at least removing the "|| defined(__clang__)
" part removes the warning.
This is seen on current Fedora 34 rawhide
glib2-2.67.0-2.fc34.x86_64
clang-11.0.0-2.fc34.x86_64