CLang, GMutexLocker: error: unused variable 'locker' [-Werror,-Wunused-variable]
From: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4300#note_2235062
The following code causes error: unused variable 'locker' [-Werror,-Wunused-variable]
with clang:
{
g_autoptr(GMutexLocker) locker = g_mutex_locker_new(mutex);
...
}
I believe that's a clang bug, because the cleanup function IS a usage of the locker
variable, and GCC seems think that way as well. We could add G_GNUC_UNUSED
as part of g_autoptr()
, that would have the advantage of making gcc and clang consistent, but it feels like GMutexLocker is a special case here where it's common to not use the variable at all, while other types of autoptr usually make sense to warn when not used.
Any suggestion?