gnome-control-center/panels/color
Philip Withnall ea014f24eb general: Fix various strict-aliasing warnings with g_clear_pointer()
This is just unfortunate. It’s an aliasing violation to cast a pointer
to a pointer (and there’s no way round that), although in practice it
will not cause a problem. People do quite often compile with
`-Werror=strict-aliasing`, though, so fixing the warnings is helpful.

Warnings are of the form:
```
../../source/gnome-control-center/panels/keyboard/cc-keyboard-shortcut-dialog.c: In function ‘cc_keyboard_shortcut_dialog_finalize’:
../../source/gnome-control-center/panels/keyboard/cc-keyboard-shortcut-dialog.c:518:20: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  518 |   g_clear_pointer ((GtkWindow**)&self->shortcut_editor, gtk_window_destroy);
/opt/gnome/install/include/glib-2.0/glib/gmacros.h:871:47: note: in definition of macro ‘G_STATIC_ASSERT’
  871 | #define G_STATIC_ASSERT(expr) _Static_assert (expr, "Expression evaluates to false")
      |                                               ^~~~
../../source/gnome-control-center/panels/keyboard/cc-keyboard-shortcut-dialog.c:518:3: note: in expansion of macro ‘g_clear_pointer’
  518 |   g_clear_pointer ((GtkWindow**)&self->shortcut_editor, gtk_window_destroy);
      |   ^~~~~~~~~~~~~~~
In file included from /opt/gnome/install/include/glib-2.0/glib/gatomic.h:30,
                 from /opt/gnome/install/include/glib-2.0/glib/gthread.h:34,
                 from /opt/gnome/install/include/glib-2.0/glib/gasyncqueue.h:34,
                 from /opt/gnome/install/include/glib-2.0/glib.h:34:
../../source/gnome-control-center/panels/keyboard/cc-keyboard-shortcut-dialog.c:518:20: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  518 |   g_clear_pointer ((GtkWindow**)&self->shortcut_editor, gtk_window_destroy);
/opt/gnome/install/include/glib-2.0/glib/glib-typeof.h:39:36: note: in definition of macro ‘glib_typeof’
   39 | #define glib_typeof(t) __typeof__ (t)
      |                                    ^
../../source/gnome-control-center/panels/keyboard/cc-keyboard-shortcut-dialog.c:518:3: note: in expansion of macro ‘g_clear_pointer’
  518 |   g_clear_pointer ((GtkWindow**)&self->shortcut_editor, gtk_window_destroy);
      |   ^~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
```

I believe it’s better to fix these by expanding out the
`g_clear_pointer()` call, than by changing the types of variables — the
latter approach means everything becomes a `GtkWidget` or a `GtkWindow`,
which loses type specificity. So this approach is in contrast to that
taken in commit 1bafd46ea3, for example.

Alternative approaches would be:
 1. Add internal `cc_clear_window()` and `cc_clear_widget()` helpers
    which do this in a single line without aliasing violations.
 2. Enforce compiling with `-Wno-strict-aliasing` if strict aliasing is
    not something that g-c-c maintainers want to care about (which would
    be fine, aliasing checks probably won’t catch any bugs in this kind
    of code).

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Fixes: #2563
2024-05-16 14:01:02 +00:00
..
icons Unify elements in the icon assets to shrink their file size 2024-04-29 11:01:18 -02:30
cc-color-calibrate.c color: Fix reference to deprecated icon 2024-04-29 11:01:18 -02:30
cc-color-calibrate.h color: Replace ifdefs with #pragma once 2018-05-30 15:09:55 +12:00
cc-color-calibrate.ui color: Fix GTK4 invisible start calibration button 2024-03-11 13:43:47 +00:00
cc-color-cell-renderer-text.c [WIP] color: Port to GTK4 2021-12-14 22:34:21 -03:00
cc-color-cell-renderer-text.h color: Replace ifdefs with #pragma once 2018-05-30 15:09:55 +12:00
cc-color-common.c color: Use g_auto for variables 2018-05-30 15:46:01 +12:00
cc-color-common.h color: Replace ifdefs with #pragma once 2018-05-30 15:09:55 +12:00
cc-color-device.c Remove unnecessary visibility change 2023-03-29 14:26:55 +13:00
cc-color-device.h color: Replace ifdefs with #pragma once 2018-05-30 15:09:55 +12:00
cc-color-panel.c general: Fix various strict-aliasing warnings with g_clear_pointer() 2024-05-16 14:01:02 +00:00
cc-color-panel.h color: Replace ifdefs with #pragma once 2018-05-30 15:09:55 +12:00
cc-color-panel.ui color: Rename "colors_page" to "color_page" 2024-04-03 19:10:59 -03:00
cc-color-profile.c color: Use CCListRowInfoButton to show color profile info 2024-04-02 16:34:49 +00:00
cc-color-profile.h color: Replace ifdefs with #pragma once 2018-05-30 15:09:55 +12:00
color.gresource.xml color: Make .ui filename match the .c filename 2019-09-09 21:58:00 +00:00
gnome-color-panel.desktop.in desktop: Remove obsolete Bugzilla entries 2022-10-20 13:20:09 +00:00
meson.build all: meson: do not specify resources from gresource files as dependencies 2023-05-24 08:34:14 +00:00