From db059847b246fbea1e6db0b38db9aaeec7ab4e36 Mon Sep 17 00:00:00 2001 From: Michael Catanzaro Date: Thu, 7 Jan 2021 09:45:43 -0600 Subject: [PATCH] Add warning when widget with no parent is unparented This is a little controversial -- Benjamin is not fond of adding new warnings in GTK 4 -- but it is not really an API break, and will help developers avoid adding unnecessary code to unparent widgets that are already unparented elsewhere. Also, it's still quite early in the life of GTK 4, before most apps have been ported. The earlier we add this warning, the better. --- gtk/gtkwidget.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 239f7735e8..8cfd5e56f4 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -2497,7 +2497,11 @@ gtk_widget_unparent (GtkWidget *widget) g_return_if_fail (GTK_IS_WIDGET (widget)); if (priv->parent == NULL) - return; + { + g_warning ("Attempted to unparent %s %p, but it already has no parent.", + G_OBJECT_TYPE_NAME (widget), widget); + return; + } gtk_widget_push_verify_invariants (widget);