[PATCH v4 0/3] compat/posix.h: enable UNUSED warning messages for Clang
From: Dominik Loidolt <hidden>
Date: 2026-06-13 12:28:05
This series enables the intended UNUSED warning message with Clang by
adding a dedicated Clang version check. It also cleans up the nearby
GIT_GNUC_PREREQ() and UNUSED macros.
Changes since v3:
- split style-only cleanups into their own patch
- fix the UNUSED preprocessor indentation style
- simplify the GIT_GNUC_PREREQ() comparison commit message
- keep the Clang-specific note in the patch that adds GIT_CLANG_PREREQ()
Thanks,
Dominik
Dominik Loidolt (3):
compat/posix.h: enable UNUSED warning messages for Clang
compat/posix.h: clean up GIT_GNUC_PREREQ() and UNUSED
compat/posix.h: simplify GIT_GNUC_PREREQ() comparison
compat/posix.h | 35 +++++++++++++++++++++++------------
1 file changed, 23 insertions(+), 12 deletions(-)
Range-diff against v3:
1: 62f5bce297 ! 1: 9ec87cd815 compat/posix.h: enable UNUSED warning messages for Clang
@@ Commit message
Signed-off-by: Dominik Loidolt [off-list ref]
## compat/posix.h ##
+@@
+ * ... 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
2: a8fe5047a4 ! 2: 1a695af9ca compat/posix.h: simplify GIT_GNUC_PREREQ() comparison
@@ Metadata
Author: Dominik Loidolt [off-list ref]
## Commit message ##
- compat/posix.h: simplify GIT_GNUC_PREREQ() comparison
+ compat/posix.h: clean up GIT_GNUC_PREREQ() and UNUSED
- Replace the glibc-style bit-shift version comparison with an explicit
- major/minor comparison. This is easier to read and is consistent with
- the format already used by GIT_CLANG_PREREQ() and many BSD
- <sys/cdefs.h> headers.
+ Fix the preprocessor indentation of the GIT_GNUC_PREREQ() and UNUSED
+ macros according to the CodingGuidelines, without changing their
+ behavior.
- This has no runtime impact, as the macro is evaluated at compile time.
- It is also more future-proof, as it no longer assumes that GCC version
- components stay below 65536.
+ Adjust the spelling in the GIT_GNUC_PREREQ() comment block.
Signed-off-by: Dominik Loidolt [off-list ref]
## compat/posix.h ##
@@
- #define _FILE_OFFSET_BITS 64
/*
-- * Derived from Linux "Features Test Macro" header
+ * 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).
@@ compat/posix.h
+ * ... 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.
-+ *
+ * Note that Clang and other compilers define __GNUC__ for compatibility; use
+@@
+ *
* 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))
-+ ((__GNUC__ > (maj)) || \
-+ (__GNUC__ == (maj) && __GNUC_MINOR__ >= (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. */
+@@
+ * 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__
-: ---------- > 3: 289b7d9f8e compat/posix.h: simplify GIT_GNUC_PREREQ() comparison
base-commit: a89346e34a937f001e5d397ee62224e3e9852040
--
2.54.0