Skip to content

Coerce type cast to void* because it causes compiler warnings

Emmanuel Fleury requested to merge emmanuel.fleury/glib:fix_atomic_cast into main

clang compiler with level 3 warning set is displaying a lot of warnings about the type of some arguments in some glib/gatomic.h macros. There are mainly two warnings:

glib/gtestutils.c:4261:11: warning: incompatible pointer types passing 'gpointer *' (aka 'void **') to parameter of type 'GSList **' (aka 'struct _GSList **') [-Wincompatible-pointer-types]
  while (!g_atomic_pointer_compare_and_exchange (test_filename_free_list, node->next, node));
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
glib/gatomic.h:215:44: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
    __atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
                                           ^~~~~~~~~~~~~~

And, the other one:

glib/tests/atomic.c:40:9: warning: passing 'gint *' (aka 'int *') to parameter of type 'guint *' (aka 'unsigned int *') converts between pointers to integer types with different sign [-Wpointer-sign]
  res = g_atomic_int_compare_and_exchange (&u, 6, 7);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
glib/gatomic.h:164:44: note: expanded from macro 'g_atomic_int_compare_and_exchange'
    __atomic_compare_exchange_n ((atomic), &gaicae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
                                           ^~~~~~~~~~~~~~

This patch just add a coerced cast in the macro to avoid these warnings.

Merge request reports