# [PATCH] compat/posix.h: enable UNUSED warning messages for Clang

20 messages from 2026-05-03 to 2026-06-15. Participants: Dominik Loidolt, Junio C Hamano, Patrick Steinhardt.
Thread: https://gitlist.dev/t/65582

## Dominik Loidolt, 2026-05-03 15:12

Subject: [PATCH] compat/posix.h: enable UNUSED warning messages for Clang
Message-ID: <20260503151210.36036-1-dominik.loidolt@univie.ac.at>

```
Treat Clang like GCC 4.5+ so using an UNUSED parameter emits the
intended warning message.

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, causing the
current check to use the deprecated attribute without a message, even
though Clang supports deprecated("...") since version 2.9 (2011).

Signed-off-by: Dominik Loidolt <dominik.loidolt@univie.ac.at>
---
I am not familiar with git's minimum compiler version but this patch
drops support for Clang < 2.9 from 2011.

Dominik
P.S. This is my first patch sent by email. Please let me know if I
missed something.

 compat/posix.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compat/posix.h b/compat/posix.h
index 245386fa4a..ed83a4d9d4 100644
--- a/compat/posix.h
+++ b/compat/posix.h
@@ -35,7 +35,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) || defined(__clang__)
 #define UNUSED __attribute__((unused)) \
 	__attribute__((deprecated ("parameter declared as UNUSED")))
 #elif defined(__GNUC__)

base-commit: 67ad42147a7acc2af6074753ebd03d904476118f
--
2.54.0


```

## Junio C Hamano, 2026-05-04 01:10

Subject: Re: [PATCH] compat/posix.h: enable UNUSED warning messages for Clang
Message-ID: <xmqq1pfsq8sd.fsf@gitster.g>
In-Reply-To: <20260503151210.36036-1-dominik.loidolt@univie.ac.at>

```
Dominik Loidolt <dominik.loidolt@univie.ac.at> writes:

> Treat Clang like GCC 4.5+ so using an UNUSED parameter emits the
> intended warning message.
>
> 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, causing the
> current check to use the deprecated attribute without a message, even
> though Clang supports deprecated("...") since version 2.9 (2011).
>
> Signed-off-by: Dominik Loidolt <dominik.loidolt@univie.ac.at>
> ---
> I am not familiar with git's minimum compiler version but this patch
> drops support for Clang < 2.9 from 2011.

Does this "drop support" because you force _all_ versions of Clang
to use the "deprecated" attribute, even though you _know_ some older
versions do not understand it?  Don't these versions identify
themselves so that you can do

	#if defined(__clang__) && CLANG_VERSION >= 2.9

I do not know if the userbase of GCC and Clang upgrade with a
similar cadence, or we seem to say that we care about GCC 4.5
(2010), so giving  a similar version detection for Clang and exclude
ones older than 2.9 sounds more appropriate.

> Dominik
> P.S. This is my first patch sent by email. Please let me know if I
> missed something.
>
>  compat/posix.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/compat/posix.h b/compat/posix.h
> index 245386fa4a..ed83a4d9d4 100644
> --- a/compat/posix.h
> +++ b/compat/posix.h
> @@ -35,7 +35,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) || defined(__clang__)
>  #define UNUSED __attribute__((unused)) \
>  	__attribute__((deprecated ("parameter declared as UNUSED")))
>  #elif defined(__GNUC__)
>
> base-commit: 67ad42147a7acc2af6074753ebd03d904476118f
> --
> 2.54.0

```

## Junio C Hamano, 2026-05-04 01:41

Subject: Re: [PATCH] compat/posix.h: enable UNUSED warning messages for Clang
Message-ID: <xmqqqznsossj.fsf@gitster.g>
In-Reply-To: <xmqq1pfsq8sd.fsf@gitster.g>

```
Junio C Hamano <gitster@pobox.com> writes:

>> I am not familiar with git's minimum compiler version but this patch
>> drops support for Clang < 2.9 from 2011.
>
> Does this "drop support" because you force _all_ versions of Clang
> to use the "deprecated" attribute, even though you _know_ some older
> versions do not understand it?  Don't these versions identify
> themselves so that you can do
>
> 	#if defined(__clang__) && CLANG_VERSION >= 2.9
>
> I do not know if the userbase of GCC and Clang upgrade with a
> similar cadence, or we seem to say that we care about GCC 4.5
> (2010), so giving  a similar version detection for Clang and exclude
> ones older than 2.9 sounds more appropriate.

IOW, something like this, perhaps?

 compat/posix.h | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git c/compat/posix.h w/compat/posix.h
index faaae1b655..0dd0637fc9 100644
--- c/compat/posix.h
+++ w/compat/posix.h
@@ -22,6 +22,17 @@
  #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 +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__)

```

## Dominik Loidolt, 2026-06-05 08:44

Subject: Re: [PATCH] compat/posix.h: enable UNUSED warning messages for Clang
Message-ID: <aiKMeHXOCulPAaXq@four.local>
In-Reply-To: <xmqqqznsossj.fsf@gitster.g>

```
On Mon, May 04, 2026 at 10:41:16AM +0900, Junio C Hamano wrote:
> > Does this "drop support" because you force _all_ versions of Clang
> > to use the "deprecated" attribute, even though you _know_ some older
> > versions do not understand it?  Don't these versions identify
> > themselves so that you can do
> >
> > 	#if defined(__clang__) && CLANG_VERSION >= 2.9
>
> IOW, something like this, perhaps?

Yes, you're right. My original patch breaks older Clang versions for no
good reason.

I'll send a v2 with an explicit Clang version check, as you suggested.

Thanks,
 Dominik

```

## Dominik Loidolt, 2026-06-05 09:46

Subject: [PATCH v2] compat/posix.h: enable UNUSED warning messages for Clang
Message-ID: <20260605094647.94805-1-dominik.loidolt@univie.ac.at>
In-Reply-To: <20260503151210.36036-1-dominik.loidolt@univie.ac.at>

```
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>
---
v2:
 - add GIT_CLANG_PREREQ()
 - require Clang 2.9+ for deprecated("...") in UNUSED

 compat/posix.h | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/compat/posix.h b/compat/posix.h
index faaae1b655..88ad29d74b 100644
--- a/compat/posix.h
+++ b/compat/posix.h
@@ -22,6 +22,17 @@
  #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 +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__)

base-commit: a89346e34a937f001e5d397ee62224e3e9852040
--
2.54.0


```

## Patrick Steinhardt, 2026-06-05 10:40

Subject: Re: [PATCH v2] compat/posix.h: enable UNUSED warning messages for Clang
Message-ID: <aiKnqlI7WdcskDAs@pks.im>
In-Reply-To: <20260605094647.94805-1-dominik.loidolt@univie.ac.at>

```
On Fri, Jun 05, 2026 at 11:46:47AM +0200, Dominik Loidolt wrote:
> 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.

Ah. I was briefly wondering about this because the UNUSED macro already
works. But the important part here is that it's really only about better
diagnostics via the attribute message.

> 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.

There's a second user of `GIT_GNUC_PREREQ` in "git-compat-util.h", but
that user checks for GCC 3.1. And as Clang identifies as a newer version
we don't have to adapt any other callsites.

> diff --git a/compat/posix.h b/compat/posix.h
> index faaae1b655..88ad29d74b 100644
> --- a/compat/posix.h
> +++ b/compat/posix.h
> @@ -22,6 +22,17 @@
>   #define GIT_GNUC_PREREQ(maj, min) 0
>  #endif
> 
> +/*
> + * Similar for Clang
> + */

Micronit, not worth rerolling over: this could have easily been a single
line: `/* 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 +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__)

Makes sense, thanks!

Patrick

```

## Dominik Loidolt, 2026-06-05 11:50

Subject: Re: [PATCH v2] compat/posix.h: enable UNUSED warning messages for Clang
Message-ID: <aiK4BR86cuq5bmCe@four.local>
In-Reply-To: <aiKnqlI7WdcskDAs@pks.im>

```
Thanks for the review!

I noticed that the version-check style now differs between GCC and the newly
introduced Clang checks, would it make sense to make them consistent? Like:

diff --git a/compat/posix.h b/compat/posix.h
index faaae1b655..e20f8ec61e 100644
--- a/compat/posix.h
+++ b/compat/posix.h
@@ -17,7 +17,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

I think the current GCC bit-shift check is harder to read.
If you agree, I could send a 2-patch v3 series, which would also clean up the
comment style nit.

 Dominik


```

## Patrick Steinhardt, 2026-06-05 13:22

Subject: Re: [PATCH v2] compat/posix.h: enable UNUSED warning messages for Clang
Message-ID: <aiLNqQgiQPlviB5X@pks.im>
In-Reply-To: <aiK4BR86cuq5bmCe@four.local>

```
On Fri, Jun 05, 2026 at 01:50:29PM +0200, Dominik Loidolt wrote:
> Thanks for the review!
> 
> I noticed that the version-check style now differs between GCC and the newly
> introduced Clang checks, would it make sense to make them consistent? Like:
> 
> diff --git a/compat/posix.h b/compat/posix.h
> index faaae1b655..e20f8ec61e 100644
> --- a/compat/posix.h
> +++ b/compat/posix.h
> @@ -17,7 +17,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
> 
> I think the current GCC bit-shift check is harder to read.
> If you agree, I could send a 2-patch v3 series, which would also clean up the
> comment style nit.

I was wondering about that, too. The question that I have is whether
there's any particular reason why the check was written that way. So in
the best case we'd do some digging into the history to figure out why
this looks the way it looks like.

Patrick

```

## Dominik Loidolt, 2026-06-05 15:53

Subject: Re: [PATCH v2] compat/posix.h: enable UNUSED warning messages for Clang
Message-ID: <aiLxCWp8Bv-KQoLf@four.local>
In-Reply-To: <aiLNqQgiQPlviB5X@pks.im>

```
On Fri, Jun 05, 2026 at 03:22:49PM +0200, Patrick Steinhardt wrote:
> I was wondering about that, too. The question that I have is whether
> there's any particular reason why the check was written that way. So in
> the best case we'd do some digging into the history to figure out why
> this looks the way it looks like.

I think the current bit-shift style introduced by 89c855ed3c (git-compat-util.h:
implement a different ARRAY_SIZE macro for for safely deriving the size of
array, 2015-04-30) was inherited from glibc [0].

I found that NetBSD [1] has long used the more explicit comparison form instead
of the bit-shift style, and other BSDs seem to do the same. So there is at
least established precedent for writing the version check that way. :-)

I see no obvious reason to prefer the bit-shift style today.

 Dominik

[0] https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=4360eafdd20769fa9d42c075853271debd06f7d1
[1] https://github.com/NetBSD/src/commit/2fffc76da21e012509677f5310464f62797bd1bf

```

## Patrick Steinhardt, 2026-06-08 06:20

Subject: Re: [PATCH v2] compat/posix.h: enable UNUSED warning messages for Clang
Message-ID: <aiZfIc8k-9Et25g6@pks.im>
In-Reply-To: <aiLxCWp8Bv-KQoLf@four.local>

```
On Fri, Jun 05, 2026 at 05:53:45PM +0200, Dominik Loidolt wrote:
> On Fri, Jun 05, 2026 at 03:22:49PM +0200, Patrick Steinhardt wrote:
> > I was wondering about that, too. The question that I have is whether
> > there's any particular reason why the check was written that way. So in
> > the best case we'd do some digging into the history to figure out why
> > this looks the way it looks like.
> 
> I think the current bit-shift style introduced by 89c855ed3c (git-compat-util.h:
> implement a different ARRAY_SIZE macro for for safely deriving the size of
> array, 2015-04-30) was inherited from glibc [0].
> 
> I found that NetBSD [1] has long used the more explicit comparison form instead
> of the bit-shift style, and other BSDs seem to do the same. So there is at
> least established precedent for writing the version check that way. :-)
> 
> I see no obvious reason to prefer the bit-shift style today.

Thanks for digging!

I don't really see a reason to keep the bitshift style, either. It could
make a difference if it was ever evaluated at runtime, as we would
evaluate the arguments multiple times with youur version. But all of the
instances we have are evaluated at compile time anwyay, so that doesn't
matter much to us.

I'll leave it up to you whether you want to send another iteration of
this patch series that also adapts the preexisting callsite to use the
new style.

Thanks!

Patrick

```

## Dominik Loidolt, 2026-06-08 12:44

Subject: [PATCH v3 1/2] compat/posix.h: enable UNUSED warning messages for Clang
Message-ID: <20260608124419.38905-1-dominik.loidolt@univie.ac.at>
In-Reply-To: <20260605094647.94805-1-dominik.loidolt@univie.ac.at>

```
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>
---
v3:
- fix comment style nit
- remove unnecessary parentheses around __clang_minor__ >= (min)

 compat/posix.h | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/compat/posix.h b/compat/posix.h
index faaae1b655..ffdfd91c7b 100644
--- a/compat/posix.h
+++ b/compat/posix.h
@@ -22,6 +22,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 +44,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__)

base-commit: a89346e34a937f001e5d397ee62224e3e9852040
--
2.54.0


```

## Dominik Loidolt, 2026-06-08 12:44

Subject: [PATCH v3 2/2] compat/posix.h: simplify GIT_GNUC_PREREQ() comparison
Message-ID: <20260608124419.38905-2-dominik.loidolt@univie.ac.at>
In-Reply-To: <20260608124419.38905-1-dominik.loidolt@univie.ac.at>

```
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.

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.

Signed-off-by: Dominik Loidolt <dominik.loidolt@univie.ac.at>
---
 compat/posix.h | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/compat/posix.h b/compat/posix.h
index ffdfd91c7b..deefc43f28 100644
--- a/compat/posix.h
+++ b/compat/posix.h
@@ -4,22 +4,24 @@
 #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. */
-- 
2.54.0


```

## Patrick Steinhardt, 2026-06-12 13:27

Subject: Re: [PATCH v3 2/2] compat/posix.h: simplify GIT_GNUC_PREREQ() comparison
Message-ID: <aiwJSBfRbUFZ70gP@pks.im>
In-Reply-To: <20260608124419.38905-2-dominik.loidolt@univie.ac.at>

```
On Mon, Jun 08, 2026 at 02:44:19PM +0200, Dominik Loidolt wrote:
> 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

It's a bit funny to use `GIT_CLANG_PREREQ()` as an argument here as
we've just added it in the preceding commit.

> <sys/cdefs.h> headers.
> 
> 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.

I feel like all the message needs to say is "let's do it for
consistency, and it's easier to read". That would've been sufficient,
whereas this argument here feels a bit thin.

Doesn't matter much though, and I think ultimately the message is fine
as-is, even though the reasoning is a bit funny.

> diff --git a/compat/posix.h b/compat/posix.h
> index ffdfd91c7b..deefc43f28 100644
> --- a/compat/posix.h
> +++ b/compat/posix.h
> @@ -4,22 +4,24 @@
>  #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.
> -*/
> + */

It would've been nice to either move these changes into a preparatory
commit or at least mention them 

>  #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

The change itself makes sense to me.

I'm not sure myself whether this could use another reroll. It's all just
nits, and the intent is clear enough.

Thanks!

Patrick

```

## Dominik Loidolt, 2026-06-12 19:04

Subject: Re: [PATCH v3 2/2] compat/posix.h: simplify GIT_GNUC_PREREQ() comparison
Message-ID: <aixYPxWiWO9iryKl@eduroam-077-080-003-247.wlan.univie.ac.at>
In-Reply-To: <aiwJSBfRbUFZ70gP@pks.im>

```
Thanks again for taking the time to review my contribution.

On Fri, Jun 12, 2026 at 03:27:36PM +0200, Patrick Steinhardt wrote:
> > It is also more future-proof, as it no longer assumes that GCC version
> > components stay below 65536.
>
> I feel like all the message needs to say is "let's do it for
> consistency, and it's easier to read". That would've been sufficient,
> whereas this argument here feels a bit thin.

Agreed. I'll simplify the commit message. The "future-proof" bit was a joke I
just couldn't resist, but it may cause more confusion than it is worth.
I'll drop it.

> It would've been nice to either move these changes into a preparatory
> commit or at least mention them

Agreed. I'll split the cleanup into a separate commit.

> I'm not sure myself whether this could use another reroll. It's all just
> nits, and the intent is clear enough.

I think it's worth rerolling.

Thanks,
 Dominik

```

## Dominik Loidolt, 2026-06-13 12:27

Subject: [PATCH v4 0/3] compat/posix.h: enable UNUSED warning messages for Clang
Message-ID: <20260613122711.38662-1-dominik.loidolt@univie.ac.at>
In-Reply-To: <20260608124419.38905-1-dominik.loidolt@univie.ac.at>

```
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 <dominik.loidolt@univie.ac.at>

      ## 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 <dominik.loidolt@univie.ac.at>

      ## 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 <dominik.loidolt@univie.ac.at>

      ## 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


```

## Dominik Loidolt, 2026-06-13 12:27

Subject: [PATCH v4 2/3] compat/posix.h: clean up GIT_GNUC_PREREQ() and UNUSED
Message-ID: <20260613122711.38662-3-dominik.loidolt@univie.ac.at>
In-Reply-To: <20260613122711.38662-1-dominik.loidolt@univie.ac.at>

```
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 <dominik.loidolt@univie.ac.at>
---
 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__
-- 
2.54.0


```

## Dominik Loidolt, 2026-06-13 12:27

Subject: [PATCH v4 1/3] compat/posix.h: enable UNUSED warning messages for Clang
Message-ID: <20260613122711.38662-2-dominik.loidolt@univie.ac.at>
In-Reply-To: <20260613122711.38662-1-dominik.loidolt@univie.ac.at>

```
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>
---
 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__)
-- 
2.54.0


```

## Dominik Loidolt, 2026-06-13 12:27

Subject: [PATCH v4 3/3] compat/posix.h: simplify GIT_GNUC_PREREQ() comparison
Message-ID: <20260613122711.38662-4-dominik.loidolt@univie.ac.at>
In-Reply-To: <20260613122711.38662-1-dominik.loidolt@univie.ac.at>

```
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 <sys/cdefs.h> headers, and
drop the Linux header attribution comment because it no longer applies.

Signed-off-by: Dominik Loidolt <dominik.loidolt@univie.ac.at>
---
 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
-- 
2.54.0


```

## Junio C Hamano, 2026-06-13 16:39

Subject: Re: [PATCH v4 0/3] compat/posix.h: enable UNUSED warning messages for Clang
Message-ID: <xmqqse6qe6oo.fsf@gitster.g>
In-Reply-To: <20260613122711.38662-1-dominik.loidolt@univie.ac.at>

```
Dominik Loidolt <dominik.loidolt@univie.ac.at> writes:

> 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

Looking good and all the points Patrick raised during the review of
the previous round seem to have been addressed nicely.

Will replace.  Shall we mark it for 'next' now?

Thanks.

```

## Patrick Steinhardt, 2026-06-15 08:48

Subject: Re: [PATCH v4 0/3] compat/posix.h: enable UNUSED warning messages for Clang
Message-ID: <ai-8Y1r9zbWfdY8p@pks.im>
In-Reply-To: <xmqqse6qe6oo.fsf@gitster.g>

```
On Sat, Jun 13, 2026 at 09:39:03AM -0700, Junio C Hamano wrote:
> Dominik Loidolt <dominik.loidolt@univie.ac.at> writes:
> 
> > 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
> 
> Looking good and all the points Patrick raised during the review of
> the previous round seem to have been addressed nicely.
> 
> Will replace.  Shall we mark it for 'next' now?

Yeah, I'm happy with this version. Thanks!

Patrick

```
