https://bugs.gentoo.org/859466

From 200c33021dbe93eae270aa1cc9a4428365a8d7a4 Mon Sep 17 00:00:00 2001
From: Matt Turner <mattst88@gmail.com>
Date: Tue, 26 Jul 2022 11:00:18 -0400
Subject: [PATCH 1/2] tab-view: Retype _AdwTabView::stack to fix aliasing
 violation

../src/adw-tab-view.c:1269:20: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
|   g_clear_pointer ((GtkWidget **) &self->stack, gtk_widget_unparent);

Closes: https://gitlab.gnome.org/GNOME/libadwaita/-/issues/522
(cherry picked from commit 5b6ea17d51a5b42a99128afa562f52aa32eff7b2)
---
 src/adw-tab-view.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/adw-tab-view.c b/src/adw-tab-view.c
index 26b64436..9c5fbe00 100644
--- a/src/adw-tab-view.c
+++ b/src/adw-tab-view.c
@@ -115,7 +115,7 @@ struct _AdwTabView
 {
   GtkWidget parent_instance;
 
-  GtkStack *stack;
+  GtkWidget *stack;
   GListStore *children;
 
   int n_pages;
@@ -763,7 +763,7 @@ page_belongs_to_this_view (AdwTabView *self,
   if (!page)
     return FALSE;
 
-  return gtk_widget_get_parent (page->child) == GTK_WIDGET (self->stack);
+  return gtk_widget_get_parent (page->child) == self->stack;
 }
 
 static inline gboolean
@@ -786,7 +786,7 @@ attach_page (AdwTabView *self,
 
   g_list_store_insert (self->children, position, page);
 
-  gtk_stack_add_child (self->stack, child);
+  gtk_stack_add_child (GTK_STACK (self->stack), child);
 
   g_object_freeze_notify (G_OBJECT (self));
 
@@ -829,7 +829,7 @@ set_selected_page (AdwTabView *self,
     if (notify_pages && self->pages)
       new_position = adw_tab_view_get_page_position (self, self->selected_page);
 
-    gtk_stack_set_visible_child (self->stack,
+    gtk_stack_set_visible_child (GTK_STACK (self->stack),
                                  adw_tab_page_get_child (selected_page));
     set_page_selected (self->selected_page, TRUE);
   }
@@ -922,7 +922,7 @@ detach_page (AdwTabView *self,
 
   g_object_thaw_notify (G_OBJECT (self));
 
-  gtk_stack_remove (self->stack, child);
+  gtk_stack_remove (GTK_STACK (self->stack), child);
 
   g_signal_emit (self, signals[SIGNAL_PAGE_DETACHED], 0, page, pos);
 
@@ -1305,7 +1305,7 @@ adw_tab_view_dispose (GObject *object)
 
   g_clear_object (&self->children);
 
-  g_clear_pointer ((GtkWidget **) &self->stack, gtk_widget_unparent);
+  g_clear_pointer (&self->stack, gtk_widget_unparent);
 
   G_OBJECT_CLASS (adw_tab_view_parent_class)->dispose (object);
 }
@@ -1737,9 +1737,9 @@ adw_tab_view_init (AdwTabView *self)
   self->children = g_list_store_new (ADW_TYPE_TAB_PAGE);
   self->default_icon = G_ICON (g_themed_icon_new ("adw-tab-icon-missing-symbolic"));
 
-  self->stack = GTK_STACK (gtk_stack_new ());
-  gtk_widget_show (GTK_WIDGET (self->stack));
-  gtk_widget_set_parent (GTK_WIDGET (self->stack), GTK_WIDGET (self));
+  self->stack = gtk_stack_new ();
+  gtk_widget_show (self->stack);
+  gtk_widget_set_parent (self->stack, GTK_WIDGET (self));
 
   g_object_bind_property (self, "is-transferring-page",
                           self->stack, "can-target",
@@ -2569,7 +2569,7 @@ adw_tab_view_get_page (AdwTabView *self,
 
   g_return_val_if_fail (ADW_IS_TAB_VIEW (self), NULL);
   g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
-  g_return_val_if_fail (gtk_widget_get_parent (child) == GTK_WIDGET (self->stack), NULL);
+  g_return_val_if_fail (gtk_widget_get_parent (child) == self->stack, NULL);
 
   for (i = 0; i < self->n_pages; i++) {
     AdwTabPage *page = adw_tab_view_get_nth_page (self, i);
-- 
2.35.1

From e6d911fae1cbebe3769ccfb0c665ce5162c86a24 Mon Sep 17 00:00:00 2001
From: Matt Turner <mattst88@gmail.com>
Date: Tue, 26 Jul 2022 11:02:14 -0400
Subject: [PATCH 2/2] tab-box: Retype _AdwTabBox::context_menu to fix aliasing
 violation

../src/adw-tab-box.c:3410:20: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
|   g_clear_pointer ((GtkWidget **) &self->context_menu, gtk_widget_unparent);

Closes: https://gitlab.gnome.org/GNOME/libadwaita/-/issues/522
(cherry picked from commit 33ab48efb62ae331f48521de1cf45960e609ff26)
---
 src/adw-tab-box.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/src/adw-tab-box.c b/src/adw-tab-box.c
index 54178555..2e0b62bf 100644
--- a/src/adw-tab-box.c
+++ b/src/adw-tab-box.c
@@ -100,7 +100,7 @@ struct _AdwTabBox
   GList *tabs;
   int n_tabs;
 
-  GtkPopover *context_menu;
+  GtkWidget *context_menu;
   GtkWidget *background;
 
   int allocated_width;
@@ -2618,7 +2618,7 @@ reset_setup_menu_cb (AdwTabBox *self)
 static void
 touch_menu_notify_visible_cb (AdwTabBox *self)
 {
-  if (!self->context_menu || gtk_widget_get_visible (GTK_WIDGET (self->context_menu)))
+  if (!self->context_menu || gtk_widget_get_visible (self->context_menu))
     return;
 
   self->hovering = FALSE;
@@ -2642,15 +2642,15 @@ do_popup (AdwTabBox *self,
   g_signal_emit_by_name (self->view, "setup-menu", info->page);
 
   if (!self->context_menu) {
-    self->context_menu = GTK_POPOVER (gtk_popover_menu_new_from_model (model));
-    gtk_widget_set_parent (GTK_WIDGET (self->context_menu), GTK_WIDGET (self));
-    gtk_popover_set_position (self->context_menu, GTK_POS_BOTTOM);
-    gtk_popover_set_has_arrow (self->context_menu, FALSE);
+    self->context_menu = gtk_popover_menu_new_from_model (model);
+    gtk_widget_set_parent (self->context_menu, GTK_WIDGET (self));
+    gtk_popover_set_position (GTK_POPOVER (self->context_menu), GTK_POS_BOTTOM);
+    gtk_popover_set_has_arrow (GTK_POPOVER (self->context_menu), FALSE);
 
     if (gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_RTL)
-      gtk_widget_set_halign (GTK_WIDGET (self->context_menu), GTK_ALIGN_END);
+      gtk_widget_set_halign (self->context_menu, GTK_ALIGN_END);
     else
-      gtk_widget_set_halign (GTK_WIDGET (self->context_menu), GTK_ALIGN_START);
+      gtk_widget_set_halign (self->context_menu, GTK_ALIGN_START);
 
     g_signal_connect_object (self->context_menu, "notify::visible",
                              G_CALLBACK (touch_menu_notify_visible_cb), self,
@@ -2672,9 +2672,9 @@ do_popup (AdwTabBox *self,
   rect.width = 0;
   rect.height = 0;
 
-  gtk_popover_set_pointing_to (self->context_menu, &rect);
+  gtk_popover_set_pointing_to (GTK_POPOVER (self->context_menu), &rect);
 
-  gtk_popover_popup (self->context_menu);
+  gtk_popover_popup (GTK_POPOVER (self->context_menu));
 }
 
 static void
@@ -2958,7 +2958,7 @@ adw_tab_box_size_allocate (GtkWidget *widget,
   value = gtk_adjustment_get_value (self->adjustment);
 
   if (self->context_menu)
-    gtk_popover_present (self->context_menu);
+    gtk_popover_present (GTK_POPOVER (self->context_menu));
 
   if (!self->n_tabs)
     return;
@@ -3169,7 +3169,7 @@ adw_tab_box_unrealize (GtkWidget *widget)
 {
   AdwTabBox *self = ADW_TAB_BOX (widget);
 
-  g_clear_pointer ((GtkWidget **) &self->context_menu, gtk_widget_unparent);
+  g_clear_pointer (&self->context_menu, gtk_widget_unparent);
 
   GTK_WIDGET_CLASS (adw_tab_box_parent_class)->unrealize (widget);
 }
@@ -3213,9 +3213,9 @@ adw_tab_box_direction_changed (GtkWidget        *widget,
 
   if (self->context_menu) {
     if (gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_RTL)
-      gtk_widget_set_halign (GTK_WIDGET (self->context_menu), GTK_ALIGN_END);
+      gtk_widget_set_halign (self->context_menu, GTK_ALIGN_END);
     else
-      gtk_widget_set_halign (GTK_WIDGET (self->context_menu), GTK_ALIGN_START);
+      gtk_widget_set_halign (self->context_menu, GTK_ALIGN_START);
   }
 }
 
-- 
2.35.1

