]> git.ipfire.org Git - thirdparty/git.git/commitdiff
git-compat-util.h: use "deprecated" for UNUSED variables
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Thu, 25 Aug 2022 17:09:49 +0000 (19:09 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 1 Sep 2022 17:49:49 +0000 (10:49 -0700)
As noted in the preceding commit our "UNUSED" macro was no longer
protecting against actual use of the "unused" variables, which it was
previously doing by renaming the variable.

Let's instead use the "deprecated" attribute to accomplish that
goal. As [1] rightly notes this has the drawback that compiling with
"-Wno-deprecated-declarations" will silence any such uses. I think the
trade-off is worth it as:

 * We can consider that a feature, as e.g. backporting certain patches
   might use a now "unused" parameter, and the person doing that might
   want to silence it with DEVOPTS=no-error.

 * This way we play nicely with coccinelle, and any other dumb(er)
   parser of C (such as syntax highlighters).

 * Not every single compilation of git needs to catch "used but
   declared unused" parameters. It's sufficient that the default "make
   DEVELOPER=1" will do so, and that the "static-analysis" CI job will
   catch it.

1. https://lore.kernel.org/git/YwCtkwjWdJVHHZV0@coredump.intra.peff.net/

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-compat-util.h

index 5ea7be974930e4b0273ae90de7b949ad38c72d59..71a004be40966ea8e152f4cff6b774efd86583f7 100644 (file)
@@ -190,7 +190,8 @@ struct strbuf;
 #define _SGI_SOURCE 1
 
 #if defined(__GNUC__)
-#define UNUSED __attribute__((unused))
+#define UNUSED __attribute__((unused)) \
+       __attribute__((deprecated ("parameter declared as UNUSED")))
 #else
 #define UNUSED
 #endif