]> git.ipfire.org Git - thirdparty/git.git/commitdiff
compat/posix.h: enable UNUSED warning messages for Clang
authorDominik Loidolt <dominik.loidolt@univie.ac.at>
Sat, 13 Jun 2026 12:27:09 +0000 (14:27 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sat, 13 Jun 2026 15:45:26 +0000 (08:45 -0700)
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>
compat/posix.h

index faaae1b6555d1b03eb7c97a337701456cc81091e..273cb871013c6d4d623a4b8f7e2446a840d63d20 100644 (file)
@@ -12,6 +12,9 @@
  *   ... code requiring gcc 2.8 or later ...
  *  #endif
  *
+ * Note that Clang and other compilers define __GNUC__ for compatibility; use
+ * GIT_CLANG_PREREQ() to check for specific Clang versions.
+ *
  * This macro of course is not part of POSIX, but we need it for the UNUSED
  * macro which is used by some of our POSIX compatibility wrappers.
 */
  #define GIT_GNUC_PREREQ(maj, min) 0
 #endif
 
+/* Similar for Clang. */
+#if defined(__clang__) && defined(__clang_minor__) && defined(__clang_major__)
+# define GIT_CLANG_PREREQ(maj, min) \
+       ((__clang_major__ > (maj)) || \
+        (__clang_major__ == (maj) && __clang_minor__ >= (min)))
+#else
+# define GIT_CLANG_PREREQ(maj, min) 0
+#endif
+
 /*
  * UNUSED marks a function parameter that is always unused.  It also
  * can be used to annotate a function, a variable, or a type that is
@@ -35,7 +47,7 @@
  * When a parameter may be used or unused, depending on conditional
  * compilation, consider using MAYBE_UNUSED instead.
  */
-#if GIT_GNUC_PREREQ(4, 5)
+#if GIT_GNUC_PREREQ(4, 5) || GIT_CLANG_PREREQ(2, 9)
 #define UNUSED __attribute__((unused)) \
        __attribute__((deprecated ("parameter declared as UNUSED")))
 #elif defined(__GNUC__)