From dd62ad57d987d2cc16690ce03312d7c8085eccd1 Mon Sep 17 00:00:00 2001 From: Olivier Blin Date: Wed, 7 Aug 2024 15:46:19 +0200 Subject: [PATCH] gstring: fix unused-result warning with g_string_free() in C++ Some g++ versions issue an unused-result warning for the g_string_free() macro: error: ignoring return value of 'gchar* g_string_free_and_steal(GString*)', declared with attribute warn_unused_result [-Werror=unused-result] g_string_free(s, TRUE); This occurs with gcc 6.x / 7.1 / 7.2, and it is fixed in gcc 7.3. --- glib/gstring.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/glib/gstring.h b/glib/gstring.h index b4ccb34a9..3e66367a0 100644 --- a/glib/gstring.h +++ b/glib/gstring.h @@ -66,6 +66,8 @@ gchar* g_string_free_and_steal (GString *string) G_GNUC_WARN_UN #if G_GNUC_CHECK_VERSION (2, 0) && (GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_76) +#if !defined(__cplusplus) || !G_GNUC_CHECK_VERSION (6, 1) || G_GNUC_CHECK_VERSION (7, 3) + #define g_string_free(str, free_segment) \ (__builtin_constant_p (free_segment) ? \ ((free_segment) ? \ @@ -74,6 +76,8 @@ gchar* g_string_free_and_steal (GString *string) G_GNUC_WARN_UN : \ (g_string_free) ((str), (free_segment))) +#endif /* !defined(__cplusplus) || !G_GNUC_CHECK_VERSION (6, 1) || G_GNUC_CHECK_VERSION (7, 3) */ + #endif /* G_GNUC_CHECK_VERSION (2, 0) && (GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_76) */ GLIB_AVAILABLE_IN_2_34