Skip to contentSkip to conversation

git-compat-util.h: fix build on gcc 4.4.x and earlier

PATCH In review Jeremy Lin 2 participants 2 messages Oct 5, 2022

lore
Share & tools
lore

Jeremy Lin

author
#0 lore raw

PATCH 1/1 git-compat-util.h: fix build on gcc 4.4.x and earlier

Commit 9ff7eb8c88 uses the deprecated attribute to display a warning message when something that is supposed to be unused is actually used. However, deprecated only supports messages starting in gcc 4.5.0, so earlier versions of gcc end up bailing out with a message like

error: wrong number of arguments specified for ‘deprecated’ attribute

This commit removes the use of the deprecated attribute for gcc 4.4.x and earlier. As this is just a diagnostic feature for developers, and presumably very few people are developing on such old systems anyway, this change shouldn't really impact anyone.

---
 git-compat-util.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
git-compat-util.h +6 -1
index b90b64718e..9e2969edd6 100644
@@ -190,8 +190,13 @@ struct strbuf;
 #define _SGI_SOURCE 1
 
 #if defined(__GNUC__)
-#define UNUSED __attribute__((unused)) \
+/* The `deprecated` attribute only accepts a message starting in gcc 4.5.0. */
+# if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40500
+#  define UNUSED __attribute__((unused)) \
 	__attribute__((deprecated ("parameter declared as UNUSED")))
+# else
+#  define UNUSED __attribute__((unused))
+# endif
 #else
 #define UNUSED
 #endif
Signature · 1 line
2.34.1
#1 lore raw
Quoted 26 lines · Jeremy Lin

Commit 9ff7eb8c88 uses the deprecated attribute to display a warning message when something that is supposed to be unused is actually used. However, deprecated only supports messages starting in gcc 4.5.0, so earlier versions of gcc end up bailing out with a message like

error: wrong number of arguments specified for ‘deprecated’ attribute

This commit removes the use of the deprecated attribute for gcc 4.4.x and earlier. As this is just a diagnostic feature for developers, and presumably very few people are developing on such old systems anyway, this change shouldn't really impact anyone.

---
 git-compat-util.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
git-compat-util.h +0 -1
index b90b64718e..9e2969edd6 100644
@@ -190,8 +190,13 @@ struct strbuf;
 #define _SGI_SOURCE 1
 
 #if defined(__GNUC__)
-#define UNUSED __attribute__((unused)) \

git-compat-util.h struct strbuf; · line 202

Quoted 10 lines
git-compat-util.h +6 -0
+/* The `deprecated` attribute only accepts a message starting in gcc 4.5.0. */
+# if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40500
+#  define UNUSED __attribute__((unused)) \
 	__attribute__((deprecated ("parameter declared as UNUSED")))
+# else
+#  define UNUSED __attribute__((unused))
+# endif
 #else
 #define UNUSED
 #endif

There's an earlier discussion & patch at
https://lore.kernel.org/git/[email protected]/