From c59d553890b8eed712f5c3eab2edf934b95049f9 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 27 Oct 2022 12:23:50 +0100 Subject: [PATCH] gstdio: Silence "Not available before" warnings for inline functions Whenever a static inline calls a GLib function that was added since we started tracking versions, we need to silence the "Not available before" warnings, otherwise compiling code that includes this header with GLIB_VERSION_MAX_ALLOWED set to an old version will emit warnings, even if the static inline is never actually called. If the static inline is API, we also need to ensure it is annotated with GLIB_AVAILABLE_STATIC_INLINE_IN_2_76 or similar, so that callers get the appropriate "Not available before" warnings to alert them to their unintended use of newer API. g_clear_fd() calls a function that was introduced in 2.36. It already issues its own warning if called with GLIB_VERSION_MAX_ALLOWED less than 2.76. Similarly, g_autofd uses internal function _g_clear_fd_ignore_error which calls g_clear_fd(), but it issues its own warning if used with GLIB_VERSION_MAX_ALLOWED less than 2.76. Fixes: b3934133 "gstdio: Add g_clear_fd() and g_autofd" Resolves: #2796 Signed-off-by: Simon McVittie --- glib/gstdio.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/glib/gstdio.h b/glib/gstdio.h index cba25a2ae..d068119ad 100644 --- a/glib/gstdio.h +++ b/glib/gstdio.h @@ -190,7 +190,10 @@ g_clear_fd (int *fd_ptr, if (fd < 0) return TRUE; + /* Suppress "Not available before" warning */ + G_GNUC_BEGIN_IGNORE_DEPRECATIONS return g_close (fd, error); + G_GNUC_END_IGNORE_DEPRECATIONS } /* g_autofd should be defined on the same compilers where g_autofree is @@ -200,11 +203,14 @@ g_clear_fd (int *fd_ptr, static inline void _g_clear_fd_ignore_error (int *fd_ptr) { + /* Suppress "Not available before" warning */ + G_GNUC_BEGIN_IGNORE_DEPRECATIONS if (!g_clear_fd (fd_ptr, NULL)) { /* Do nothing: we ignore all errors, except for EBADF which * is a programming error, checked for by g_close(). */ } + G_GNUC_END_IGNORE_DEPRECATIONS } #define g_autofd _GLIB_CLEANUP(_g_clear_fd_ignore_error) GLIB_AVAILABLE_MACRO_IN_2_76