From 689dc92e501e25ae1ed67410ff51b4359a4f5c3c Mon Sep 17 00:00:00 2001 From: Dominik Loidolt Date: Sat, 13 Jun 2026 14:27:09 +0200 Subject: [PATCH 1/3] 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 Signed-off-by: Junio C Hamano --- compat/posix.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/compat/posix.h b/compat/posix.h index faaae1b655..273cb87101 100644 --- a/compat/posix.h +++ b/compat/posix.h @@ -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. */ @@ -22,6 +25,15 @@ #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__) From ffd45926dcb18337b7897bd96d8b1b14acec2359 Mon Sep 17 00:00:00 2001 From: Dominik Loidolt Date: Sat, 13 Jun 2026 14:27:10 +0200 Subject: [PATCH 2/3] compat/posix.h: clean up GIT_GNUC_PREREQ() and UNUSED Fix the preprocessor indentation of the GIT_GNUC_PREREQ() and UNUSED macros according to the CodingGuidelines, without changing their behavior. Adjust the spelling in the GIT_GNUC_PREREQ() comment block. Signed-off-by: Dominik Loidolt Signed-off-by: Junio C Hamano --- compat/posix.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/compat/posix.h b/compat/posix.h index 273cb87101..d2de5cedf5 100644 --- a/compat/posix.h +++ b/compat/posix.h @@ -5,11 +5,10 @@ /* * Derived from Linux "Features Test Macro" header - * Convenience macros to test the versions of gcc (or - * a compatible compiler). + * Convenience macros to test the versions of GCC (or a compatible compiler). * Use them like this: * #if GIT_GNUC_PREREQ (2,8) - * ... code requiring gcc 2.8 or later ... + * ... code requiring GCC 2.8 or later ... * #endif * * Note that Clang and other compilers define __GNUC__ for compatibility; use @@ -17,12 +16,12 @@ * * 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. -*/ + */ #if defined(__GNUC__) && defined(__GNUC_MINOR__) # define GIT_GNUC_PREREQ(maj, min) \ ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) #else - #define GIT_GNUC_PREREQ(maj, min) 0 +# define GIT_GNUC_PREREQ(maj, min) 0 #endif /* Similar for Clang. */ @@ -48,13 +47,13 @@ * compilation, consider using MAYBE_UNUSED instead. */ #if GIT_GNUC_PREREQ(4, 5) || GIT_CLANG_PREREQ(2, 9) -#define UNUSED __attribute__((unused)) \ - __attribute__((deprecated ("parameter declared as UNUSED"))) +# define UNUSED __attribute__((unused)) \ + __attribute__((deprecated("parameter declared as UNUSED"))) #elif defined(__GNUC__) -#define UNUSED __attribute__((unused)) \ +# define UNUSED __attribute__((unused)) \ __attribute__((deprecated)) #else -#define UNUSED +# define UNUSED #endif #ifdef __MINGW64__ From cf48887610da108a3fbc97645e2d2ba2e7178ad0 Mon Sep 17 00:00:00 2001 From: Dominik Loidolt Date: Sat, 13 Jun 2026 14:27:11 +0200 Subject: [PATCH 3/3] compat/posix.h: simplify GIT_GNUC_PREREQ() comparison GIT_GNUC_PREREQ() uses a glibc-style bit-shift version comparison, which is harder to read than an explicit major/minor comparison. Use an explicit comparison, as in many BSD headers, and drop the Linux header attribution comment because it no longer applies. Signed-off-by: Dominik Loidolt Signed-off-by: Junio C Hamano --- compat/posix.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compat/posix.h b/compat/posix.h index d2de5cedf5..2f01564b0d 100644 --- a/compat/posix.h +++ b/compat/posix.h @@ -4,7 +4,6 @@ #define _FILE_OFFSET_BITS 64 /* - * Derived from Linux "Features Test Macro" header * Convenience macros to test the versions of GCC (or a compatible compiler). * Use them like this: * #if GIT_GNUC_PREREQ (2,8) @@ -19,7 +18,8 @@ */ #if defined(__GNUC__) && defined(__GNUC_MINOR__) # define GIT_GNUC_PREREQ(maj, min) \ - ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) + ((__GNUC__ > (maj)) || \ + (__GNUC__ == (maj) && __GNUC_MINOR__ >= (min))) #else # define GIT_GNUC_PREREQ(maj, min) 0 #endif