diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c
index a31ec09..feb197e 100644
--- a/gtk/gtkmenu.c
+++ b/gtk/gtkmenu.c
@@ -1314,7 +1314,8 @@ gtk_menu_detach (GtkMenu *menu)
   g_object_set_data (G_OBJECT (menu), I_(attach_data_key), NULL);
 
   /* Detach the toplevel window. */
-  gtk_window_set_attached_to (GTK_WINDOW (menu->priv->toplevel), NULL);
+  if (GTK_IS_WINDOW (menu->priv->toplevel))
+    gtk_window_set_attached_to (GTK_WINDOW (menu->priv->toplevel), NULL);
 
   g_signal_handlers_disconnect_by_func (data->attach_widget,
                                         (gpointer) attach_widget_screen_changed,
