Skip to content

Allow g_atomic_pointer_get() to be used by projects which enable -Wbad-function-cast

When compiling third-party projects with -Wbad-function-cast, the inline g_atomic_pointer_get() implementation which uses C11 __atomic_load*() calls on GCC was causing compilation errors like:

error: cast from function call of type ‘long unsigned int’ to non-matching type ‘void *’

While we don’t want to compile all of GLib with -Wbad-function-cast, we should support its headers being included in projects which do enable that warning.

It doesn’t seem to be possible to cast away the warning (e.g. by casting the function’s result through (void)), so we have to assign to an intermediate integer of the right size first.

The same has to be done for the bool return value from __sync_bool_compare_and_swap(). In that case, casting from bool to gboolean raises a -Wbad-function-cast warning, since gboolean is secretly int.

The atomic tests have been modified to enable -Wbad-function-cast to catch regressions of this in future. The GLib build has conversely been modified to set -Wno-bad-function-cast, just in case people have it set in their environment CFLAGS.

Signed-off-by: Philip Withnall withnall@endlessm.com

#1041 (closed)

Closes #1041 (closed)

Merge request reports