compat/posix.h: enable UNUSED warning messages for Clang
Use a dedicated Clang version check for the UNUSED macro. Commit 7c07f36ad2 (git-compat-util.h: GCC deprecated message arg only in GCC 4.5+, 2022-10-05) restricted use of the deprecated attribute's message argument in the UNUSED macro to GCC 4.5 or newer. Clang identifies itself as GNUC 4.2.1 for compatibility, so GIT_GNUC_PREREQ(4, 5) does not detect whether Clang supports the deprecated("...") form. Add GIT_CLANG_PREREQ() macro and use it to enable the UNUSED warning message for Clang 2.9 and newer. Signed-off-by: Dominik Loidolt <dominik.loidolt@univie.ac.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Dominik Loidolt committed
Jun 13, 2026 at 14:27 UTC
689dc92e501e25ae1ed67410ff51b4359a4f5c3c
1 file changed
+13
-1
compat/posix.h
+13
-1
@@ -12,6 +12,9 @@
12
* ... code requiring gcc 2.8 or later ...
13
* #endif
14
*
15
+ * Note that Clang and other compilers define __GNUC__ for compatibility; use
16
+ * GIT_CLANG_PREREQ() to check for specific Clang versions.
17
+ *
18
* This macro of course is not part of POSIX, but we need it for the UNUSED
19
* macro which is used by some of our POSIX compatibility wrappers.
20
*/
@@ -22,6 +25,15 @@
25
#define GIT_GNUC_PREREQ(maj, min) 0
26
#endif
27
28
+/* Similar for Clang. */
29
+#if defined(__clang__) && defined(__clang_minor__) && defined(__clang_major__)
30
+# define GIT_CLANG_PREREQ(maj, min) \
31
+ ((__clang_major__ > (maj)) || \
32
+ (__clang_major__ == (maj) && __clang_minor__ >= (min)))
33
+#else
34
+# define GIT_CLANG_PREREQ(maj, min) 0
35
+#endif
36
+
37
/*
38
* UNUSED marks a function parameter that is always unused. It also
39
* can be used to annotate a function, a variable, or a type that is
@@ -35,7 +47,7 @@
47
* When a parameter may be used or unused, depending on conditional
48
* compilation, consider using MAYBE_UNUSED instead.
49
*/
38
-#if GIT_GNUC_PREREQ(4, 5)
50
+#if GIT_GNUC_PREREQ(4, 5) || GIT_CLANG_PREREQ(2, 9)
51
#define UNUSED __attribute__((unused)) \
52
__attribute__((deprecated ("parameter declared as UNUSED")))
53
#elif defined(__GNUC__)