https://bugs.gentoo.org/970774
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/5145

From 9f5903a96f419058d457de7b7544c2bc9e73e510 Mon Sep 17 00:00:00 2001
From: Sam James <sam@gentoo.org>
Date: Fri, 10 Apr 2026 02:28:48 +0100
Subject: [PATCH] gvarianttype: use pure attribute, not inappropriate const

As found in https://gcc.gnu.org/PR124837, it is wrong to use the const
attribute [0] for g_variant_type_*is* because it may be called repeatedly
with different pointed-to data. The pure attribute [1] is what we want
here because it allows pointed-to data to change, so change to that.

const would be OK here if it pointed to a constant buffer, but it doesn't,
it points to newly malloc'd memory from all over the place.

[0] https://gcc.gnu.org/onlinedocs/gcc-15.2.0/gcc/Common-Function-Attributes.html#index-const-function-attribute
[1] https://gcc.gnu.org/onlinedocs/gcc-15.2.0/gcc/Common-Function-Attributes.html#index-pure-function-attribute

Fixes: 49bfa7b9cf8b16f7f6a5b1db565575d61a37100f
Signed-off-by: Sam James <sam@gentoo.org>
---
 glib/gvarianttype.h | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/glib/gvarianttype.h b/glib/gvarianttype.h
index 38980af829..3a57b9131a 100644
--- a/glib/gvarianttype.h
+++ b/glib/gvarianttype.h
@@ -302,7 +302,7 @@ typedef struct _GVariantType GVariantType;
 
 /* type string checking */
 GLIB_AVAILABLE_IN_ALL
-gboolean                        g_variant_type_string_is_valid          (const gchar         *type_string) G_GNUC_CONST;
+gboolean                        g_variant_type_string_is_valid          (const gchar         *type_string) G_GNUC_PURE;
 GLIB_AVAILABLE_IN_ALL
 gboolean                        g_variant_type_string_scan              (const gchar         *string,
                                                                          const gchar         *limit,
@@ -326,21 +326,21 @@ gchar *                         g_variant_type_dup_string               (const G
 
 /* classification */
 GLIB_AVAILABLE_IN_ALL
-gboolean                        g_variant_type_is_definite              (const GVariantType  *type) G_GNUC_CONST;
+gboolean                        g_variant_type_is_definite              (const GVariantType  *type) G_GNUC_PURE;
 GLIB_AVAILABLE_IN_ALL
-gboolean                        g_variant_type_is_container             (const GVariantType  *type) G_GNUC_CONST;
+gboolean                        g_variant_type_is_container             (const GVariantType  *type) G_GNUC_PURE;
 GLIB_AVAILABLE_IN_ALL
-gboolean                        g_variant_type_is_basic                 (const GVariantType  *type) G_GNUC_CONST;
+gboolean                        g_variant_type_is_basic                 (const GVariantType  *type) G_GNUC_PURE;
 GLIB_AVAILABLE_IN_ALL
-gboolean                        g_variant_type_is_maybe                 (const GVariantType  *type) G_GNUC_CONST;
+gboolean                        g_variant_type_is_maybe                 (const GVariantType  *type) G_GNUC_PURE;
 GLIB_AVAILABLE_IN_ALL
-gboolean                        g_variant_type_is_array                 (const GVariantType  *type) G_GNUC_CONST;
+gboolean                        g_variant_type_is_array                 (const GVariantType  *type) G_GNUC_PURE;
 GLIB_AVAILABLE_IN_ALL
-gboolean                        g_variant_type_is_tuple                 (const GVariantType  *type) G_GNUC_CONST;
+gboolean                        g_variant_type_is_tuple                 (const GVariantType  *type) G_GNUC_PURE;
 GLIB_AVAILABLE_IN_ALL
-gboolean                        g_variant_type_is_dict_entry            (const GVariantType  *type) G_GNUC_CONST;
+gboolean                        g_variant_type_is_dict_entry            (const GVariantType  *type) G_GNUC_PURE;
 GLIB_AVAILABLE_IN_ALL
-gboolean                        g_variant_type_is_variant               (const GVariantType  *type) G_GNUC_CONST;
+gboolean                        g_variant_type_is_variant               (const GVariantType  *type) G_GNUC_PURE;
 
 /* for hash tables */
 GLIB_AVAILABLE_IN_ALL
@@ -352,21 +352,21 @@ gboolean                        g_variant_type_equal                    (gconstp
 /* subtypes */
 GLIB_AVAILABLE_IN_ALL
 gboolean                        g_variant_type_is_subtype_of            (const GVariantType  *type,
-                                                                         const GVariantType  *supertype) G_GNUC_CONST;
+                                                                         const GVariantType  *supertype) G_GNUC_PURE;
 
 /* type iterator interface */
 GLIB_AVAILABLE_IN_ALL
-const GVariantType *            g_variant_type_element                  (const GVariantType  *type) G_GNUC_CONST;
+const GVariantType *            g_variant_type_element                  (const GVariantType  *type) G_GNUC_PURE;
 GLIB_AVAILABLE_IN_ALL
-const GVariantType *            g_variant_type_first                    (const GVariantType  *type) G_GNUC_CONST;
+const GVariantType *            g_variant_type_first                    (const GVariantType  *type) G_GNUC_PURE;
 GLIB_AVAILABLE_IN_ALL
-const GVariantType *            g_variant_type_next                     (const GVariantType  *type) G_GNUC_CONST;
+const GVariantType *            g_variant_type_next                     (const GVariantType  *type) G_GNUC_PURE;
 GLIB_AVAILABLE_IN_ALL
-gsize                           g_variant_type_n_items                  (const GVariantType  *type) G_GNUC_CONST;
+gsize                           g_variant_type_n_items                  (const GVariantType  *type) G_GNUC_PURE;
 GLIB_AVAILABLE_IN_ALL
-const GVariantType *            g_variant_type_key                      (const GVariantType  *type) G_GNUC_CONST;
+const GVariantType *            g_variant_type_key                      (const GVariantType  *type) G_GNUC_PURE;
 GLIB_AVAILABLE_IN_ALL
-const GVariantType *            g_variant_type_value                    (const GVariantType  *type) G_GNUC_CONST;
+const GVariantType *            g_variant_type_value                    (const GVariantType  *type) G_GNUC_PURE;
 
 /* constructors */
 GLIB_AVAILABLE_IN_ALL
-- 
GitLab
