public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks•im>
To: Dominik Loidolt <dominik.loidolt@univie•ac.at>
Cc: gitster@pobox•com, git@vger•kernel.org, asedeno@MIT•EDU,
	asedeno@google•com, avarab@gmail•com
Subject: Re: [PATCH v2] compat/posix.h: enable UNUSED warning messages for Clang
Date: Fri, 5 Jun 2026 12:40:42 +0200	[thread overview]
Message-ID: <aiKnqlI7WdcskDAs@pks.im> (raw)
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

  reply	other threads:[~2026-06-05 10:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-06-05 11:50     ` Dominik Loidolt
2026-06-05 13:22       ` Patrick Steinhardt
2026-06-05 15:53         ` Dominik Loidolt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aiKnqlI7WdcskDAs@pks.im \
    --to=ps@pks$(echo .)im \
    --cc=asedeno@MIT$(echo .)EDU \
    --cc=asedeno@google$(echo .)com \
    --cc=avarab@gmail$(echo .)com \
    --cc=dominik.loidolt@univie$(echo .)ac.at \
    --cc=git@vger$(echo .)kernel.org \
    --cc=gitster@pobox$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox