Git development
 help / color / mirror / Atom feed
* [PATCH] compat/posix.h: enable UNUSED warning messages for Clang
@ 2026-05-03 15:12 Dominik Loidolt
  2026-05-04  1:10 ` Junio C Hamano
  2026-06-05  9:46 ` [PATCH v2] " Dominik Loidolt
  0 siblings, 2 replies; 7+ messages in thread
From: Dominik Loidolt @ 2026-05-03 15:12 UTC (permalink / raw)
  To: git
  Cc: Dominik Loidolt, Alejandro R Sedeño,
	Alejandro R. Sedeño, Ævar Arnfjörð Bjarmason,
	Junio C Hamano

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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] compat/posix.h: enable UNUSED warning messages for Clang
  2026-05-03 15:12 [PATCH] compat/posix.h: enable UNUSED warning messages for Clang Dominik Loidolt
@ 2026-05-04  1:10 ` Junio C Hamano
  2026-05-04  1:41   ` Junio C Hamano
  2026-06-05  9:46 ` [PATCH v2] " Dominik Loidolt
  1 sibling, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2026-05-04  1:10 UTC (permalink / raw)
  To: Dominik Loidolt
  Cc: git, Alejandro R Sedeño, Alejandro R. Sedeño,
	Ævar Arnfjörð Bjarmason

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] compat/posix.h: enable UNUSED warning messages for Clang
  2026-05-04  1:10 ` Junio C Hamano
@ 2026-05-04  1:41   ` Junio C Hamano
  2026-06-05  8:44     ` Dominik Loidolt
  0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2026-05-04  1:41 UTC (permalink / raw)
  To: Dominik Loidolt
  Cc: git, Alejandro R Sedeño, Alejandro R. Sedeño,
	Ævar Arnfjörð Bjarmason

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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] compat/posix.h: enable UNUSED warning messages for Clang
  2026-05-04  1:41   ` Junio C Hamano
@ 2026-06-05  8:44     ` Dominik Loidolt
  0 siblings, 0 replies; 7+ messages in thread
From: Dominik Loidolt @ 2026-06-05  8:44 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git, Alejandro R Sedeño, Alejandro R. Sedeño,
	Ævar Arnfjörð Bjarmason

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2] compat/posix.h: enable UNUSED warning messages for Clang
  2026-05-03 15:12 [PATCH] compat/posix.h: enable UNUSED warning messages for Clang Dominik Loidolt
  2026-05-04  1:10 ` Junio C Hamano
@ 2026-06-05  9:46 ` Dominik Loidolt
  2026-06-05 10:40   ` Patrick Steinhardt
  1 sibling, 1 reply; 7+ messages in thread
From: Dominik Loidolt @ 2026-06-05  9:46 UTC (permalink / raw)
  To: gitster; +Cc: git, asedeno, asedeno, avarab, Dominik Loidolt

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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] compat/posix.h: enable UNUSED warning messages for Clang
  2026-06-05  9:46 ` [PATCH v2] " Dominik Loidolt
@ 2026-06-05 10:40   ` Patrick Steinhardt
  2026-06-05 11:50     ` Dominik Loidolt
  0 siblings, 1 reply; 7+ messages in thread
From: Patrick Steinhardt @ 2026-06-05 10:40 UTC (permalink / raw)
  To: Dominik Loidolt; +Cc: gitster, git, asedeno, asedeno, avarab

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] compat/posix.h: enable UNUSED warning messages for Clang
  2026-06-05 10:40   ` Patrick Steinhardt
@ 2026-06-05 11:50     ` Dominik Loidolt
  0 siblings, 0 replies; 7+ messages in thread
From: Dominik Loidolt @ 2026-06-05 11:50 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: gitster, git, asedeno, asedeno, avarab

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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-06-05 11:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-03 15:12 [PATCH] compat/posix.h: enable UNUSED warning messages for Clang Dominik Loidolt
2026-05-04  1:10 ` Junio C Hamano
2026-05-04  1:41   ` Junio C Hamano
2026-06-05  8:44     ` Dominik Loidolt
2026-06-05  9:46 ` [PATCH v2] " Dominik Loidolt
2026-06-05 10:40   ` Patrick Steinhardt
2026-06-05 11:50     ` Dominik Loidolt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox