Merge branch 'dl/posix-unused-warning-clang' into seen

The UNUSED macro in 'compat/posix.h' has been updated to use a
newly introduced GIT_CLANG_PREREQ macro for compiler version
checks, and the existing GIT_GNUC_PREREQ macro has been modernized
to use explicit major/minor comparisons rather than bit-shifting.

* dl/posix-unused-warning-clang:
  compat/posix.h: simplify GIT_GNUC_PREREQ() comparison
  compat/posix.h: enable UNUSED warning messages for Clang
This commit is contained in:
Junio C Hamano
2026-06-12 15:58:17 -07:00

View File

@@ -4,22 +4,33 @@
#define _FILE_OFFSET_BITS 64
/*
* 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
* 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.
*/
*/
#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
# 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
/*
@@ -35,7 +46,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__)