From 4d1c4da04d6d626ae3c5281187e7a45f30608dbc Mon Sep 17 00:00:00 2001
From: Dominik Loidolt <dominik.loidolt@univie.ac.at>
Date: Mon, 4 Mar 2024 10:18:47 +0100
Subject: [PATCH] Fix UNUSED macro for older compiler (gcc 4.4 and older)

---
 lib/common/compiler.h | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/lib/common/compiler.h b/lib/common/compiler.h
index 510057c..7a8e121 100644
--- a/lib/common/compiler.h
+++ b/lib/common/compiler.h
@@ -21,6 +21,22 @@
 #define COMPILER_H
 
 
+/* Derived from Linux "Features Test Macro" header Convenience macros to test
+ * the versions of gcc (or a compatible compiler).
+ * Use them like this:
+ *  #if GNUC_PREREQ (2,8)
+ *   ... code requiring gcc 2.8 or later ...
+ *  #endif
+*/
+
+#if defined(__GNUC__) && defined(__GNUC_MINOR__)
+# define GNUC_PREREQ(maj, min) \
+	((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
+#else
+ #define GNUC_PREREQ(maj, min) 0
+#endif
+
+
 /**
  * Compile time check usable outside of function scope.
  * Stolen from Linux (hpi_internal.h)
@@ -108,12 +124,19 @@
  *
  * This macro is used to indicate that a variable is intentionally left unused
  * in the code. It helps suppress compiler warnings about unused variables.
- * It also protecting against actual use of the "unused" variable.
- *
+ * It also tries to prevent the actual use of the "unused" variables.
  */
 
+#if GNUC_PREREQ(4, 5)
 #define UNUSED __attribute__((unused)) \
 	__attribute__((deprecated ("parameter declared as UNUSED")))
+#elif defined(__GNUC__)
+#define UNUSED __attribute__((unused)) \
+	__attribute__((deprecated))
+#else
+#define UNUSED
+#endif
+
 
 
 /**
-- 
GitLab