Thread (5 messages) flat view 5 messages, 3 authors, 2022-08-26
STALE1448d

[PATCH 2/2] git-compat-util.h: use "deprecated" for UNUSED variables

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2022-08-25 17:10:16
Subsystem: the rest · Maintainer: Linus Torvalds

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/ (local)

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 git-compat-util.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/git-compat-util.h b/git-compat-util.h
index 5ea7be97493..71a004be409 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -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
-- 
2.37.2.1279.g8741a0e3ea3
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help